Beispiel #1
0
        public async Task Resample(string srcFile, string destFile)
        {
            var wavFile = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(destFile), $"{System.IO.Path.GetFileNameWithoutExtension(destFile)}.wav");

            if (System.IO.File.Exists(wavFile))
            {
                System.IO.File.Delete(wavFile);
            }
            using (var reader = new AudioFileReader(srcFile))
            {
                var resampler = new WdlResamplingSampleProvider(reader, 44100);
                WaveFileWriter.CreateWaveFile16(wavFile, resampler);
            }
            using (var reader = new WaveFileReader(wavFile))
            {
                if (System.IO.File.Exists(destFile))
                {
                    System.IO.File.Delete(destFile);
                }
                using (var writer = new LameMP3FileWriter(destFile, reader.WaveFormat, LAMEPreset.EXTREME))
                {
                    //reader.CopyTo(writer);
                    await reader.CopyToAsync(writer);

                    await writer.FlushAsync();
                }
            }
            System.IO.File.Delete(wavFile);
        }
Beispiel #2
0
        private async Task UpdateOutputFileBasedOnMediaFormat()
        {
            switch (_userSettings.MediaFormat)
            {
            case MediaFormat.Wav:
                _fileManager.Rename(_currentOutputFile.ToPendingFileString(), _currentOutputFile.ToString());
                return;

            case MediaFormat.Mp3:
                using (var reader = new WaveFileReader(_currentOutputFile.ToPendingFileString()))
                {
                    using (var mp3writer = new LameMP3FileWriter(_currentOutputFile.ToTranscodingToMP3String(), _waveIn.WaveFormat, _userSettings.Bitrate))
                    {
                        await reader.CopyToAsync(mp3writer);

                        if (mp3writer != null)
                        {
                            await mp3writer.FlushAsync();
                        }
                    }
                }

                _fileManager.DeleteFile(_currentOutputFile.ToPendingFileString());
                _fileManager.Rename(_currentOutputFile.ToTranscodingToMP3String(), _currentOutputFile.ToString());

                var mp3TagsInfo = new MediaTags.MP3Tags()
                {
                    Track = _track,
                    OrderNumberInMediaTagEnabled = _userSettings.OrderNumberInMediaTagEnabled,
                    Count       = _userSettings.OrderNumber,
                    CurrentFile = _currentOutputFile.ToString()
                };
                await mp3TagsInfo.SaveMediaTags();

                return;

            default:
                return;
            }
        }