How can i make the sound louder with Naudio c#?

末鹿安然 提交于 2019-12-11 09:21:28

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!