问题
I am trying to increase the amplitude of the sound wave in my code. I have the buffer consisting of all the bytes needed to make the wave.
Here is my code for the audio Playback:
public void AddSamples(byte[] buffer)
{
//somehow adjust the buffer to make the sound louder
bufferedWaveProvider.AddSamples(buffer, 0, buffer.Length);
WaveOut waveout = new WaveOut();
waveout.Init(bufferedWaveProvider);
waveout.Play();
//to make the program more memory efficient
bufferedWaveProvider.ClearBuffer();
}
回答1:
You could convert to an ISampleProvider
and then try to amplify the signal by passing it through a VolumeSampleProvider
with a gain > 1.0. However, you could end up with hard clipping if any samples go above 0.
WaveOut waveout = new WaveOut();
var volumeSampleProvider = new VolumeSampleProvider(bufferedWaveProvider.ToSampleProvider());
volumeSampleProvider.Volume = 2.0f; // double the amplitude of every sample - may go above 0dB
waveout.Init(volumeSampleProvider);
waveout.Play();
A better solution would be to use a dynamic range compressor effect, but NAudio does not come with one out of the box.
回答2:
I had a similar problem, too. But Could done with it with this link:
http://mark-dot-net.blogspot.hu/2009/10/playback-of-sine-wave-in-naudio.html
If you know all details about your sound It would be helpful I think
来源:https://stackoverflow.com/questions/49067902/how-can-i-make-the-sound-louder-with-naudio-c