public void ConversionTest( string inputPath, SampleRate sampleRate, BitRate bitRate, ChannelFormat channelFormat) { var inputFileName = Path.GetFileNameWithoutExtension(inputPath); var actualSampleRate = SampleRateHelper.GetSampleRate(sampleRate); var actualBitRate = BitRateHelper.GetBitRate(bitRate); var actualChannelsCount = ChannelFormatHelper.GetChannelsCount(channelFormat); var fileName = $"{inputFileName}-SR{actualSampleRate}-BR{actualBitRate}-CF{actualChannelsCount}"; var outputPath = string.Format(OutputPathFormat, fileName); WavConverter.Convert(inputPath, outputPath, sampleRate, channelFormat, bitRate); using (var inputReader = new AudioFileReader(inputPath)) using (var outputReader = new WaveFileReader(outputPath)) { Assert.Equal(actualSampleRate, outputReader.WaveFormat.SampleRate); Assert.Equal(actualBitRate, outputReader.WaveFormat.BitsPerSample); Assert.Equal(actualChannelsCount, outputReader.WaveFormat.Channels); Assert.InRange( inputReader.TotalTime, outputReader.TotalTime - _totalTimeDelta, outputReader.TotalTime + _totalTimeDelta); } #if !DEBUG DeleteIfExists(outputPath); #endif }
public void Conversionless() { WavConverter.Convert(AudioFiles.WavFilename, DefaultOutputPath); var existsOutputPath = File.Exists(DefaultOutputPath); Assert.False(existsOutputPath); }
static void Main(string[] args) { var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var inputFiles = Directory.EnumerateFiles(currentDirectory, "*.wav", SearchOption.TopDirectoryOnly); foreach (var file in inputFiles) { var fileName = Path.GetFileNameWithoutExtension(file); var outputFileName = $"{fileName}-out.wav"; var outputPath = Path.Combine(currentDirectory, "Output", outputFileName); var thread = new Thread(() => { Debug.WriteLine($"Converting {fileName}..."); try { WavConverter.Convert(file, outputPath, SampleRate.Low, ChannelFormat.Mono, BitRate.Low); } catch (InvalidDataException) { Debug.WriteLine($":-S Ops, unsupported format: {fileName}"); } catch (Exception exception) { Debug.WriteLine($":,-( Ops, {exception.Message}: {fileName}"); } finally { Debug.WriteLine($"Done!: {fileName}"); } }); thread.Start(); } }
public void DifferentOutputDirectoryTest() { var outputPath = Path.Combine(DefaultOutputDirectory, DefaultOutputPath); WavConverter.Convert(AudioFiles.WavFilename, outputPath, SampleRate.Low, ChannelFormat.Mono, BitRate.Low); #if !DEBUG DeleteIfExists(outputPath); Directory.Delete(DefaultOutputDirectory); #endif }
public void UnexistingInputTest() { Assert.Throws <FileNotFoundException>( () => WavConverter.Convert("Foo.wav", DefaultOutputPath, SampleRate.Low)); }
public void ULauConversionTest() { Assert.Throws <InvalidDataException>( () => WavConverter.Convert(AudioFiles.WavSR44100BR32CF2ULauFilename, DefaultOutputPath)); }
/**<summary>Replaces a sound content file.</summary>*/ private static void ReplaceSound(string name, string outputFile) { WavConverter.Convert(GetSound(name), Path.Combine(SoundDir, outputFile)); }