Naudio c#如何使声音更响亮? [英] How can i make the sound louder with Naudio c#?

查看:642
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆