Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

enter image description here

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;
    }   
}

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.

enter image description here

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.0k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...