drawing waveform - converting to DB squashes it
Asked Answered
E

1

1

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.

Exoteric answered 18/6, 2012 at 22:20 Comment(2)
When you expand the small values, you squash the large ones. That's the only way to keep the same interval. It's a natural outcome of the math.Machellemachete
i thought that may be the case. when i look at waveforms in audacity however, their waveforms are more equal. i had assumed they were displaying in decibels but they arent. I think there must be an issue with how im populating the array of average amplitudes. either that or they have figured out a way of slightly normalising to make things more readable by humans.Exoteric
P
3

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.

Pink answered 19/6, 2012 at 15:34 Comment(1)
i did that this morning after drawing horizontal lines representing the max and min values and finding them way off. it turns out it was using the average that was making my quiet wavs too small.Exoteric

© 2022 - 2024 — McMap. All rights reserved.