本文介绍了我如何削弱由给定的分贝值WAV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想25%,以减少WAV文件的幅度,我会写这样的事:

If I wanted to reduce a WAV file's amplitude by 25%, I would write something like this:

for (int i = 0; i < data.Length; i++)
{
    data[i] *= 0.75;
}

很多我的音频技术所读文章的,然而,在分贝方面讨论幅度。我明白分贝单位原则上对数的性质,但在实际code而言没有这么多。

A lot of the articles I read on audio techniques, however, discuss amplitude in terms of decibels. I understand the logarithmic nature of decibel units in principle, but not so much in terms of actual code.

我的问题是:如果我想减弱,比方说,20分贝WAV文件的音量,我会怎么做这在code像我上面的例子

My question is: if I wanted to attenuate the volume of a WAV file by, say, 20 decibels, how would I do this in code like my above example?

更新:公式(基于尼尔斯Pipenbrinck的答案)由给定数分贝衰减(输入为正数,例如10,20等):

Update: formula (based on Nils Pipenbrinck's answer) for attenuating by a given number of decibels (entered as a positive number e.g. 10, 20 etc.):

public void AttenuateAudio(float[] data, int decibels)
{
    float gain = (float)Math.Pow(10, (double)-decibels / 20.0);
    for (int i = 0; i < data.Length; i++)
    {
        data[i] *= gain;
    }
}

所以,如果我想通过衰减 20 分贝,增益系数 .1

推荐答案

我想你想从分贝获得转换。

I think you want to convert from decibel to gain.

有关音频的公式是:

分贝增益:

  gain = 10 ^ (attenuation in db / 20)

或C:

  gain = powf(10, attenuation / 20.0f);

该方程转换增益分贝是:

The equations to convert from gain to db are:

  attenuation_in_db = 20 * log10 (gain)

这篇关于我如何削弱由给定的分贝值WAV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-12 18:20