private void ConvertSongs(AsyncPartialResultCollector <ConvertedSong> partialResults) { const int bufferSize = 256; byte[] reusedBuffer = new byte[bufferSize]; foreach (var song in Songs) { partialResults.AddPartialResult( ConvertSong(song, reusedBuffer) ); } _logger.Log( $"Completed song conversion batch: {Songs.Count()} songs " + $"were converted to format '{SongEncoder.Extension}'. " + $"First song: '{Songs.FirstOrDefault().SongInfo.CombinedName}'." ); }
private void SplitGroup(AsyncPartialResultCollector <RecordedSong> partialResults) { using (var groupReader = new WaveFileReader(Group.Path)) { const int bufferSize = 256; //I'm guessing this power of 2 should work well byte[] buffer = new byte[bufferSize]; int songNum = 1; _logger.Log("songs: " + string.Join(", ", Group.Songs.Select(x => x.CombinedName))); foreach (var song in Group.Songs.Skip(1).Where(s => s.IsSong && s.HasStopped)) { //Loop through songs, ignoring ads, durations where the music is paused, and incomplete songs //Skip the first song as this will be incomplete (do this before filtering out ads etc //as there's no point skipping a song after an ad) string songPath = Path.Combine( Path.GetDirectoryName(Group.Path), $"Temp Group '{Group.GroupID}' - Song#{songNum} {song.CombinedName}" ); // ^ Adding in the group id and song number avoids having to deal with // duplicates (they'll be dealt with later) using (var songWriter = new WaveFileWriter(songPath + ".wav-extracting", groupReader.WaveFormat)) { ExtractSongToFile(buffer, groupReader, songWriter, song); } File.Move(songPath + ".wav-extracting", songPath + ".wav"); partialResults.AddPartialResult(new RecordedSong(song, songPath + ".wav")); songNum++; } } _logger.Log($"Finished splitting song group '{Group.GroupID}' into songs"); File.Delete(Group.Path); //Deleting later no longer works (due to setting mutation) // Don't delete yet - clear up all the files later, where it's easier to make it customiseable etc. // This also ensures that if there's an error above the file should still get deleted. }