Esempio n. 1
0
        public ConvertingSampleProvider(IWaveProvider waveProvider, WaveFormat targetFormat)
        {
            if (waveProvider.WaveFormat.SampleRate != targetFormat.SampleRate)
            {
                if (waveProvider.WaveFormat.Encoding == WaveFormatEncoding.IeeeFloat)
                {
                    provider = ((resampler = new MediaFoundationResampler(waveProvider, targetFormat)) as MediaFoundationResampler).ToSampleProvider();
                }
                else
                {
                    provider = ((resampler = new MediaFoundationResampler(new Wave16ToFloatProvider(waveProvider), targetFormat)) as MediaFoundationResampler).ToSampleProvider();
                }
            }
            else
            {
                provider = waveProvider.ToSampleProvider();
            }

            if (provider.WaveFormat.Channels != targetFormat.Channels)
            {
                if (targetFormat.Channels == 1 & provider.WaveFormat.Channels > 1)
                {
                    provider = provider.ToMono();
                }
                else if (targetFormat.Channels == 2)
                {
                    provider = provider.ToStereo();
                }
                else
                {
                    throw new InvalidWaveFormatException($"Couldn´t find a suitable conversion from {provider.WaveFormat.Channels} to {targetFormat.Channels} Channels");
                }
            }
        }
Esempio n. 2
0
 public SampleProvider(ISampleProvider input)
 {
     if (input.WaveFormat.Channels == 2)
     {
         this.output = input;
     }
     else
     {
         this.output = input.ToStereo();
     }
 }
 public ISampleProvider SupplySample(bool stereo, bool loop, ISampleProvider input)
 {
     if (stereo)
     {
         input.ToStereo();
     }
     else
     {
         input.ToMono();
     }
     return(input);
 }
 public SampleProvider(VoiceStreamStruct voiceStreamStruct, ISampleProvider input)
 {
     this.buffer            = new float[buffSize];
     this.voiceStreamStruct = voiceStreamStruct;
     if (input.WaveFormat.Channels != 2)
     {
         this.input = input.ToStereo();
     }
     else
     {
         this.input = input;
     }
 }
Esempio n. 5
0
        public AudioSample(string filePath)
        {
            this.audioFileReader = new AudioFileReader(filePath);
            ISampleProvider sampleProvider = this.audioFileReader.ToSampleProvider();

            // Mono to Stereo
            if (sampleProvider.WaveFormat.Channels == 1)
            {
                sampleProvider = sampleProvider.ToStereo();
            }
            // Resample
            if (sampleProvider.WaveFormat.SampleRate != 16000)
            {
                sampleProvider = new WdlResamplingSampleProvider(sampleProvider, 16000);
            }
            this.oriSample = sampleProvider;
            this.Sample    = this.oriSample;
        }
Esempio n. 6
0
            public SampleProvider(string folderPath, ISampleProvider input, SourceLocation location)
            {
                this.hrtf = new HRTF(folderPath);
                this.hrtf.Init();
                this.binSyn   = new BinauralSynthesis(currInput, dataOutput);
                this.location = location;

                // convert stereo input to mono
                if (input.WaveFormat.Channels != 1)
                {
                    this.input = input.ToMono();
                }
                else
                {
                    this.input = input;
                }

                WaveFormat = input.ToStereo().WaveFormat;
            }
Esempio n. 7
0
 private ISampleProvider StereoToMono(ISampleProvider input)
 {
     return(input.ToStereo());
 }