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); }
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 }
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); } }
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(); }
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); }
public AudioSampleProviderToAudioStream(IAudioSampleProvider audioSampleProvider) { _audioSampleProvider = audioSampleProvider; _format = _audioSampleProvider.AudioFormat; }