Шустрый

Профиль
Группа: Участник
Сообщений: 113
Регистрация: 4.12.2008
Репутация: нет Всего: нет
|
Всем привет, может кто то уже имел опыт в подобных задачах, поделитесь плз опытом... Имеется, массив байт, полученый из файла, на подобии архива: | Код | FileStream input = new FileStream(textBox1.Text, FileMode.Open); BinaryReader reader = new BinaryReader(input); byte[] bytes = reader.ReadBytes((int)input.Length);
|
В нем могут содержаться WAVE, OggS данные. с WAVE разобрался, имеются довольно хорошие описания в интернете, а вот с ogg ничего не выходит. Вот как у меня поиск файла в массиве байтов | Код | private Dictionary<int, SoundFile> allFiles = new Dictionary<int, SoundFile>();
|
Кнопка открыть файл... | Код | private void OpenBtn_Click(object sender, EventArgs e) { try { FileListBox.Items.Clear(); allFiles.Clear(); FileStream input = new FileStream(textBox1.Text, FileMode.Open); BinaryReader reader = new BinaryReader(input); byte[] bytes = reader.ReadBytes((int)input.Length);
int id = 0; for (int currentbyte = 0; currentbyte < bytes.Length; currentbyte++) { if (id > 0xFF) { MessageBox.Show("Insufficient buffer length!"); return; } if ((Encoding.ASCII.GetString(bytes, currentbyte, 1) == "R") && (Encoding.ASCII.GetString(bytes, currentbyte, 4) == "RIFF")) { var wFile = new WaveFile(); var header = new WavHeader(); var headerSize = Marshal.SizeOf(header);
reader.Read(bytes, currentbyte, headerSize); FileListBox.Items.Add(Path.GetFileNameWithoutExtension(textBox1.Text) + "_" + Convert.ToString(id + 1) + ".wav");
// Чтобы не считывать каждое значение заголовка по отдельности, // воспользуемся выделением unmanaged блока памяти var headerPtr = Marshal.AllocHGlobal(headerSize); // Копируем считанные байты из файла в выделенный блок памяти Marshal.Copy(bytes, currentbyte, headerPtr, headerSize); // Преобразовываем указатель на блок памяти к нашей структуре Marshal.PtrToStructure(headerPtr, header);
wFile.header = header; wFile.data = new byte[header.Subchunk2Size]; Array.Copy(bytes, currentbyte + 44, wFile.data, 0, header.Subchunk2Size);
wFile.all = new byte[header.ChunkSize + 8]; Array.Copy(bytes, currentbyte, wFile.all, 0, header.ChunkSize + 8);
allFiles.Add(id, wFile); id++; currentbyte += 4; } // Info: http://shounen.ru/docs/ogm/ogm.shtml else if ((Encoding.ASCII.GetString(bytes, currentbyte, 1) == "O") && (Encoding.ASCII.GetString(bytes, currentbyte, 4) == "OggS")) { //var oFile = new OggFile(); //var header = new OggHeader(); //var headerSize = Marshal.SizeOf(header);
string u1 = Encoding.ASCII.GetString(bytes, currentbyte + 0x0, 4); byte u2 = bytes[currentbyte + 0x4]; byte u3 = bytes[currentbyte + 0x5]; ulong u4 = BitConverter.ToUInt64(bytes, currentbyte + 0x6); uint u5 = BitConverter.ToUInt32(bytes, currentbyte + 0xE); uint u6 = BitConverter.ToUInt32(bytes, currentbyte + 0x12); uint u7 = BitConverter.ToUInt32(bytes, currentbyte + 0x16); byte u8 = bytes[currentbyte + 0x1A];
byte[] u9 = new byte[u8]; Array.Copy(bytes, currentbyte + 0x1B, u9, 0, u9.Length); MessageBox.Show("u3: " + u3);
//oFile.all = new byte[27 * u8]; //Array.Copy(bytes, currentbyte, oFile.all, 0, oFile.all.Length); FileListBox.Items.Add(Path.GetFileNameWithoutExtension(textBox1.Text) + "_" + Convert.ToString(id + 1) + ".ogg"); id++; currentbyte += 4; } } reader.Close(); input.Close(); } catch (Exception exception1) { MessageBox.Show("Error while processing file!" + exception1); } }
|
Тако вот Сохраняю.. | Код | private void SaveBtn_Click(object sender, EventArgs e) { if (FileListBox.SelectedIndex > -1) { string FileName = FileListBox.SelectedItem.ToString(); FileStream stream2 = new FileStream(FileName, FileMode.Create, FileAccess.ReadWrite); BinaryWriter writer2 = new BinaryWriter(stream2);
writer2.Write(allFiles[FileListBox.SelectedIndex].all); writer2.Close(); stream2.Close(); MessageBox.Show("Saved to \"" + FileName + "\"" + "Saved"); } }
|
Вот так вот проигрываю.. | Код | private void playBtn_Click(object sender, EventArgs e) { var data = allFiles[FileListBox.SelectedIndex].all;
PlaySound(data,0,5); }
[DllImport("winmm.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern int PlaySound(byte[] bytes, int i, int j);
|
Может у кого - то есть нормальный Header для ogg? Поделитесь плз. Это сообщение отредактировал(а) Felixx - 24.12.2011, 14:57
|