Esempio n. 1
0
 public void FillWith(IAudioSampleProvider audioSampleProvider)
 {
     Array.Clear(_samples, 0, _samples.Length);
     audioSampleProvider.Read(_samples, _samples.Length);
     _dataStream.Position = 0;
     _dataStream.Write(_samples, 0, _samples.Length);
 }
Esempio n. 2
0
        public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
        {
            _audioSampleProvider = audioSampleProvider;

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"));
            _writer.Write(0); // placeholder
            _writer.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"));

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("fmt "));

            var extraSize = 0;
            var encoding = 1;
            var channels = audioSampleProvider.AudioFormat.Channels;
            var sampleRate = audioSampleProvider.AudioFormat.SampleRate;
            var bitsPerSample = audioSampleProvider.AudioFormat.BitsPerSample;
            var blockAlign = audioSampleProvider.AudioFormat.BlockAlign;
            var averageBytesPerSecond = audioSampleProvider.AudioFormat.AverageBytesPerSecond;
            _writer.Write((18 + extraSize)); // wave format length
            _writer.Write((short)encoding);
            _writer.Write((short)channels);
            _writer.Write(sampleRate);
            _writer.Write(averageBytesPerSecond);
            _writer.Write((short)blockAlign);
            _writer.Write((short)bitsPerSample);
            _writer.Write((short)extraSize);

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("data"));
            _dataSizePos = _writer.BaseStream.Position;
            _writer.Write(0); // placeholder
        }
Esempio n. 3
0
        public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
        {
            _audioSampleProvider = audioSampleProvider;

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("RIFF"));
            _writer.Write(0); // placeholder
            _writer.Write(System.Text.Encoding.UTF8.GetBytes("WAVE"));

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("fmt "));

            var extraSize             = 0;
            var encoding              = 1;
            var channels              = audioSampleProvider.AudioFormat.Channels;
            var sampleRate            = audioSampleProvider.AudioFormat.SampleRate;
            var bitsPerSample         = audioSampleProvider.AudioFormat.BitsPerSample;
            var blockAlign            = audioSampleProvider.AudioFormat.BlockAlign;
            var averageBytesPerSecond = audioSampleProvider.AudioFormat.AverageBytesPerSecond;

            _writer.Write((18 + extraSize)); // wave format length
            _writer.Write((short)encoding);
            _writer.Write((short)channels);
            _writer.Write(sampleRate);
            _writer.Write(averageBytesPerSecond);
            _writer.Write((short)blockAlign);
            _writer.Write((short)bitsPerSample);
            _writer.Write((short)extraSize);

            _writer.Write(System.Text.Encoding.UTF8.GetBytes("data"));
            _dataSizePos = _writer.BaseStream.Position;
            _writer.Write(0); // placeholder
        }
Esempio n. 4
0
 public void FillWith(IAudioSampleProvider audioSampleProvider)
 {
     Array.Clear(_samples, 0, _samples.Length);
     audioSampleProvider.Read(_samples, _samples.Length);
     _dataStream.Position = 0;
     _dataStream.Write(_samples, 0, _samples.Length);
 }
Esempio n. 5
0
 public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
 {
     _audioSampleProvider = audioSampleProvider;
     if (_audioSampleProvider.AudioFormat.SampleRate != _audioFormat.SampleRate)
     {
         _audioSampleProvider = new ResampleAudioSampleProvider(audioSampleProvider, _audioFormat.SampleRate);
     }
     if (_audioSampleProvider.AudioFormat.Channels == 1 && _audioFormat.Channels == 2)
     {
         _audioSampleProvider = new MonoToStereoAudioSampleProvider16(_audioSampleProvider);
     }
 }
Esempio n. 6
0
 public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
 {
     _audioSampleProvider = audioSampleProvider;
     if (_audioSampleProvider.AudioFormat.SampleRate != _audioFormat.SampleRate)
     {
         _audioSampleProvider = new ResampleAudioSampleProvider(audioSampleProvider, _audioFormat.SampleRate);
     }
     if (_audioSampleProvider.AudioFormat.Channels == 1 && _audioFormat.Channels == 2)
     {
         _audioSampleProvider = new MonoToStereoAudioSampleProvider16(_audioSampleProvider);
     }
 }
Esempio n. 7
0
        public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
        {
            var format = ToWaveFormat(audioSampleProvider.AudioFormat);

            _voice = new SourceVoice(_xAudio, format, true);
            _audioSampleProvider = audioSampleProvider;
            for (var i = 0; i < NumBuffers; i++)
            {
                FillBuffer(i);
            }
            _audioThread = Task.Factory.StartNew(OnAudioThread, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
            _voice.Start();
        }
Esempio n. 8
0
        public MonoToStereoAudioSampleProvider16(IAudioSampleProvider audioSampleProvider)
        {
            if (audioSampleProvider.AudioFormat.Channels != 1)
            {
                throw new ArgumentException("audioSampleProvider expected to be Mono");
            }
            if (audioSampleProvider.AudioFormat.BitsPerSample != 16)
            {
                throw new ArgumentException("audioSampleProvider expected to be 16 bit");
            }

            _audioSampleProvider = audioSampleProvider;
            _audioFormat         = new AudioFormat(_audioSampleProvider.AudioFormat.SampleRate, 2, _audioSampleProvider.AudioFormat.BitsPerSample);
        }
        public MonoToStereoAudioSampleProvider16(IAudioSampleProvider audioSampleProvider)
        {
            if (audioSampleProvider.AudioFormat.Channels != 1)
            {
                throw new ArgumentException("audioSampleProvider expected to be Mono");
            }
            if (audioSampleProvider.AudioFormat.BitsPerSample != 16)
            {
                throw new ArgumentException("audioSampleProvider expected to be 16 bit");
            }

            _audioSampleProvider = audioSampleProvider;
            _audioFormat = new AudioFormat(_audioSampleProvider.AudioFormat.SampleRate, 2, _audioSampleProvider.AudioFormat.BitsPerSample);
        }
 public ResampleAudioSampleProvider(IAudioSampleProvider source, int newSampleRate)
 {
     _outFormat = new AudioFormat(newSampleRate, 2, 16);
     _converter = RateHelper.MakeRateConverter(source.AudioFormat.SampleRate, newSampleRate, source.AudioFormat.Channels == 2, false);
     _stream = new AudioSampleProviderToAudioStream(source);
 }
Esempio n. 11
0
 public ResampleAudioSampleProvider(IAudioSampleProvider source, int newSampleRate)
 {
     _outFormat = new AudioFormat(newSampleRate, 2, 16);
     _converter = RateHelper.MakeRateConverter(source.AudioFormat.SampleRate, newSampleRate, source.AudioFormat.Channels == 2, false);
     _stream    = new AudioSampleProviderToAudioStream(source);
 }
Esempio n. 12
0
 public AudioSampleProviderToAudioStream(IAudioSampleProvider audioSampleProvider)
 {
     _audioSampleProvider = audioSampleProvider;
     _format = _audioSampleProvider.AudioFormat;
 }
 public AudioSampleProviderToAudioStream(IAudioSampleProvider audioSampleProvider)
 {
     _audioSampleProvider = audioSampleProvider;
     _format = _audioSampleProvider.AudioFormat;
 }
Esempio n. 14
0
 public void SetSampleProvider(IAudioSampleProvider audioSampleProvider)
 {
     var format = ToWaveFormat(audioSampleProvider.AudioFormat);
     _voice = new SourceVoice(_xAudio, format, true);
     _audioSampleProvider = audioSampleProvider;
     for (var i = 0; i < NumBuffers; i++)
     {
         FillBuffer(i);
     }
     _audioThread = Task.Factory.StartNew(OnAudioThread, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
     _voice.Start();
 }