C++ 绘制波形-转换为DB会将其压扁

C++ 绘制波形-转换为DB会将其压扁,c++,audio,waveform,C++,Audio,Waveform,我有一个wave文件,我有一个函数,每像素检索2个样本,然后我用它们画线。在处理缩放之前,快速且无痛。我可以显示振幅值,没问题 这是波形的精确图像。为此,我使用了以下代码 //tempAllChannels[numOfSamples] holds amplitude data for the entire wav //oneChannel[numOfPixels*2] will hold 2 values per pixel in display area, an average of min

我有一个wave文件,我有一个函数,每像素检索2个样本,然后我用它们画线。在处理缩放之前,快速且无痛。我可以显示振幅值,没问题

这是波形的精确图像。为此,我使用了以下代码

//tempAllChannels[numOfSamples] holds amplitude data for the entire wav
//oneChannel[numOfPixels*2] will hold 2 values per pixel in display area, an average of min amp, and average of max
for(int i = 0; i < numOfSamples; i++)//loop through all samples in wave file
{
    if (tempAllChannels[i] < 0) min += tempAllChannels[i];//if neg amp value, add amp value to min
    if (tempAllChannels[i] >= 0) max += tempAllChannels[i]; 

    if(i%factor==0 && i!=0)     //factor is (numofsamples in wav)/(numofpixels) in display area
    {
        min = min/factor;       //get average amp value
        max = max/factor;
        oneChannel[j]=max;
        oneChannel[j+1]=min;
        j+=2;                   //iterate for next time
        min = 0;                //reset for next time
        max = 0;
    }   
}
波浪图像如下所示


这不准确,看起来像是被压扁了。我在做什么有问题吗?我需要找到一种方法,在保持动力的同时,将振幅转换为分贝。我想我不应该在转换成DB时取平均值。

不要转换成DB来查看概述。没有人这样做


与其求块上的平均值,不如求绝对值的最大值。通过平均,您将在高频峰值中释放大量振幅。

当您扩展小值时,会挤压大值。这是保持相同间隔的唯一方法。这是数学的自然结果。我想可能是这样的。然而,当我在audacity中查看波形时,它们的波形更加相等。我以为它们是以分贝显示的,但事实并非如此。我想一定是我如何填充平均振幅数组的问题。要么是这样,要么是他们找到了一种稍微正常化的方法,让人们更容易阅读。今天早上,我画了代表最大值和最小值的水平线,并找到了它们的距离。事实证明,正是由于使用了平均值,我的安静波形变得太小了。
oneChannel[j]=10*log10(max);
oneChannel[j+1]=-10*log10(-min);