绘制波形 - 转换为DB南瓜它 [英] drawing waveform - converting to DB squashes it
问题描述
我有一个波形文件,我有检索每像素2个样本,然后我画与他们行的功能。快速,无痛之前我处理缩放。我可以显示振幅值没有问题
I have a wave file, i have a function that retrieves 2 samples per pixel then i draw lines with them. quick and painless before i deal with zooming. i can display the amplitude values no problem
这是波形的精确图像。要做到这一点我用下面的code
that is an accurate image of the waveform. to do this i used the following code
//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;
}
}
和这是伟大的,但我需要这么安静波图像的arent小得可笑的分贝显示,但是当我做如下改变上述code
and that's great but I need to display in db so quieter wave images arent ridiculously small, but when i make the following change to the above code
oneChannel[j]=10*log10(max);
oneChannel[j+1]=-10*log10(-min);
波图像看起来是这样的。
the wave image looks like this.
这心不是准确的,它看起来像其正挤压。是不是有什么毛病我在做什么?我需要找到一个方法来从振幅转换为分贝,同时保持动态。即时通讯思想当转换为DB我不应该服用的平均水平。
which isnt accurate, it looks like its being squashed. Is there something wrong with what I'm doing? I need to find a way to convert from amplitude to decibels whilst maintaining dynamics. im thinking i shouldnt be taking an average when converted to DB.
推荐答案
不要转换为分贝概述。没有人做到这一点。
Don't convert to dB for overviews. No one does that.
而不是找到平均值块的,你应该找绝对值最大。通过平均,你将失去大量的幅度在高频峰值。
Instead of finding the average over a block, you should find the max of the absolute value. By averaging, you will loose a lot of amplitude in your high frequency peaks.
这篇关于绘制波形 - 转换为DB南瓜它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!