Naudio c#如何使声音更响亮? [英] How can i make the sound louder with Naudio c#?
问题描述
我正在尝试增加代码中声波的幅度.我有缓冲区,该缓冲区由构成wave所需的所有字节组成.
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();
}
推荐答案
您可以转换为ISampleProvider
,然后尝试通过将信号通过增益大于1.0的VolumeSampleProvider
来放大信号.但是,如果有任何样本超过0,最终可能会导致硬剪切.
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();
一种更好的解决方案是使用动态范围压缩器效果,但NAudio并非开箱即用.
A better solution would be to use a dynamic range compressor effect, but NAudio does not come with one out of the box.
这篇关于Naudio c#如何使声音更响亮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!