private byte[] extractSongData(Song song, BinaryReader br, out List<Int32> dpdsTable) { var buf = new byte[ChunkBufferSize]; var data = new List<byte>(); dpdsTable = new List<Int32>(); var curDecLen = 0; br.BaseStream.Position = song.Offset; for (var i = song.FirstChunkID; i <= song.LastChunkID; i++) { br.BaseStream.Position += 56; var packetDecLen = 0; for (var j = 0; j < _curChunkPacketCounts[i]; j++) { packetDecLen = curDecLen + br.ReadInt32(); dpdsTable.Add(packetDecLen); } curDecLen = packetDecLen; var chunkLen = getChunkLength(i); br.Read(buf, 0, (int) chunkLen); data.AddRange(buf.Take((int) chunkLen)); } return data.ToArray(); }
private void exportSongToXwma(Song song, BinaryReader br, string xmaFn) { var dpdsTable = new List<Int32>(); var data = extractSongData(song, br, out dpdsTable); File.Copy(_curChannels == 2 ? "audio.xma" : "audiom.xma", xmaFn, true); long packetCount, dpdsPos, dataPos; using (var tempBr = new MemoryStream(File.ReadAllBytes(xmaFn))) { dpdsPos = findArrayInStream(tempBr, XwmaDpdsHeader, 0) + 8; dataPos = findArrayInStream(tempBr, XwmaDataHeader, dpdsPos); packetCount = (dataPos - dpdsPos) / 4; } using (var bw = new BinaryWriter(File.OpenWrite(xmaFn))) { bw.BaseStream.Position = dpdsPos; for (var i = 0; i < packetCount; i++) { if (i < dpdsTable.Count) { bw.Write(dpdsTable[i]); } else { bw.Write(dpdsTable.Last()); } } bw.BaseStream.Position = dataPos + 8; bw.Write(data); bw.Flush(); } }
private void parseSongs() { var songs = new List<Song>(); for (var i = 0; i < _curSongOffsets.Count; i++) { var song = new Song(); song.FirstChunkID = _curChunkOffsets.IndexOf(_curSongOffsets[i]); song.Offset = _curSongOffsets[i]; if (i < _curSongOffsets.Count - 1) { song.LastChunkID = _curChunkOffsets.IndexOf(_curSongOffsets[i + 1]) - 1; song.ChunkCount = song.LastChunkID - song.FirstChunkID + 1; } else { song.LastChunkID = _curChunkOffsets.Count - 1; song.ChunkCount = song.LastChunkID - song.FirstChunkID + 1; } song.Length = 0; song.PacketCount = 0; for (var j = song.FirstChunkID; j <= song.LastChunkID; j++) { song.Length += getChunkLength(j); song.PacketCount += _curChunkPacketCounts[j]; } song.ID = i; song.Duration = (double) song.Length / 4000; songs.Add(song); } _allSongs = new List<Song>(songs); _matchingSongs = new ObservableCollection<Song>(_allSongs); }
private string exportSongToWav(Song song, BinaryReader br, string wavFn) { var xmaFn = Path.GetDirectoryName(wavFn) + "\\" + Path.GetFileNameWithoutExtension(wavFn) + ".xma"; exportSongToXwma(song, br, xmaFn); var command = Directory.GetCurrentDirectory() + "\\xWMAEncode.exe"; var args = "\"" + xmaFn + "\" \"" + wavFn + "\""; var px = Process.Start(new ProcessStartInfo(command, args) { WindowStyle = ProcessWindowStyle.Hidden }); px.WaitForExit(); File.Delete(xmaFn); return wavFn; }