帮助与动态范围COM

帮助与动态范围COM

本文介绍了帮助与动态范围COM pression功能(音频)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这样做动态范围COM pression一个C#函数(基本上南瓜瞬间峰值和放大一切以产生一个整体的响亮声音的音频效果)。我写这是否一个功能(我认为):

I am writing a C# function for doing dynamic range compression (an audio effect that basically squashes transient peaks and amplifies everything else to produce an overall louder sound). I have written a function that does this (I think):

public static void Compress(ref short[] input, double thresholdDb, double ratio)
{
    double maxDb = thresholdDb - (thresholdDb / ratio);
    double maxGain = Math.Pow(10, -maxDb / 20.0);

    for (int i = 0; i < input.Length; i += 2)
    {
        // convert sample values to ABS gain and store original signs
        int signL = input[i] < 0 ? -1 : 1;
        double valL = (double)input[i] / 32768.0;
        if (valL < 0.0)
        {
            valL = -valL;
        }
        int signR = input[i + 1] < 0 ? -1 : 1;
        double valR = (double)input[i + 1] / 32768.0;
        if (valR < 0.0)
        {
            valR = -valR;
        }

        // calculate mono value and compress
        double val = (valL + valR) * 0.5;
        double posDb = -Math.Log10(val) * 20.0;
        if (posDb < thresholdDb)
        {
            posDb = thresholdDb - ((thresholdDb - posDb) / ratio);
        }

        // measure L and R sample values relative to mono value
        double multL = valL / val;
        double multR = valR / val;

        // convert compressed db value to gain and amplify
        val = Math.Pow(10, -posDb / 20.0);
        val = val / maxGain;

        // re-calculate L and R gain values relative to compressed/amplified
        // mono value
        valL = val * multL;
        valR = val * multR;

        double lim = 1.5; // determined by experimentation, with the goal
            // being that the lines below should never (or rarely) be hit
        if (valL > lim)
        {
            valL = lim;
        }
        if (valR > lim)
        {
            valR = lim;
        }

        double maxval = 32000.0 / lim;

        // convert gain values back to sample values
        input[i] = (short)(valL * maxval);
        input[i] *= (short)signL;
        input[i + 1] = (short)(valR * maxval);
        input[i + 1] *= (short)signR;
    }
}

和我与10.0 1.5和4.0之间的分贝至30.0分贝和比例之间的阈值值调用它。这个功能绝对产生响亮整体声音,但与失真的不可接受的水平,即使在低的阈值和低的比率。

and I am calling it with threshold values between 10.0 db and 30.0 db and ratios between 1.5 and 4.0. This function definitely produces a louder overall sound, but with an unacceptable level of distortion, even at low threshold values and low ratios.

任何人都可以看到什么毛病这个功能呢?我在正确处理立体声方面(函数假定立体声输入)?正如我(依稀)明白的事情,我不想COM preSS分别在两个通道,所以我的code试图COM preSS一个虚拟单声道采样值,然后采用相同的玉米pression单独的​​L和R的采样值的程度。不知道我这样做是正确的,但是。

Can anybody see anything wrong with this function? Am I handling the stereo aspect correctly (the function assumes stereo input)? As I (dimly) understand things, I don't want to compress the two channels separately, so my code is attempting to compress a "virtual" mono sample value and then apply the same degree of compression to the L and R sample value separately. Not sure I'm doing it right, however.

我认为问题的一部分,可能我的功能,踢在com pression突然当超过阈值时的硬拐点。我想我可能需要使用软拐点是这样的:

I think part of the problem may the "hard knee" of my function, which kicks in the compression abruptly when the threshold is crossed. I think I may need to use a "soft knee" like this:

任何人都可以建议修改我的函数来产生膝软曲线?

Can anybody suggest a modification to my function to produce the soft knee curve?

推荐答案

我想你怎么办COM pression基本的认识是错误的(对不起;))。这不是COM pressing个别样本值;这将从根本上改变波形和产生严重的谐波失真。您需要评估的输入信号的音量超过许多样品(我将不得不谷歌正确的公式),并使用此一备受更逐渐变化的乘数适用于输入样本生成输出。

I think your basic understanding of how to do compression is wrong (sorry ;)). It's not about "compressing" individual sample values; that will radically change the waveform and produce severe harmonic distortions. You need to assess the input signal volume over many samples (I would have to Google for the correct formula), and use this to apply a much-more-gradually-changing multiplier to the input samples to generate output.

在kvraudio.com/forum的DSP论坛可能,如果你有一个很难找到的常用技术你指出正确的方向。

The DSP forum at kvraudio.com/forum might point you in the right direction if you have a hard time finding the usual techniques.

这篇关于帮助与动态范围COM pression功能(音频)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:45