I have a wave file, I have a function that extracts 2 samples per pixel, and then draw lines with them. quickly and painlessly before I get down to scaling. I can display amplitude values without problems
which is an accurate representation of the waveform. for 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 this is great, but I need to display in db, so the quieter wave images arent ridiculously small, but when I do the following change to the above code
oneChannel[j]=10*log10(max); oneChannel[j+1]=-10*log10(-min);
The wave image is as follows.
which is not accurate, it looks like it is crushed. Is there something wrong with what I'm doing? I need to find a way to convert from amplitude to decibels while maintaining momentum. im thinking that I should not take the average value when converting to DB.
source share