Example #1
0
        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
        }
Example #2
0
        public void Conversionless()
        {
            WavConverter.Convert(AudioFiles.WavFilename, DefaultOutputPath);
            var existsOutputPath = File.Exists(DefaultOutputPath);

            Assert.False(existsOutputPath);
        }
Example #3
0
        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();
            }
        }
Example #4
0
        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
        }
Example #5
0
 public void UnexistingInputTest()
 {
     Assert.Throws <FileNotFoundException>(
         () => WavConverter.Convert("Foo.wav", DefaultOutputPath, SampleRate.Low));
 }
Example #6
0
 public void ULauConversionTest()
 {
     Assert.Throws <InvalidDataException>(
         () => WavConverter.Convert(AudioFiles.WavSR44100BR32CF2ULauFilename, DefaultOutputPath));
 }
Example #7
0
 /**<summary>Replaces a sound content file.</summary>*/
 private static void ReplaceSound(string name, string outputFile)
 {
     WavConverter.Convert(GetSound(name), Path.Combine(SoundDir, outputFile));
 }