
Rockbox mail archiveSubject: [patch] peakmeter[patch] peakmeter
From: Andreas Zwirtes <zwirtes_at_gmx.de>
Date: Mon, 07 Oct 2002 03:00:17 +0200 Hi ! I finished the code for the dB Peakmeter. It compiles well for recorder. Although I cannt test it, it worked 100% on my windows machine. Seems I left the USB cable in the office, so i cannot copy the binary to my box. Since i'm new to rockbox and know nothing about CVS, i changed as little as possible in /apps/peakmeter.c. I've added the function calc_dB and edited peak_meter_draw (). I think I stuck to the contribution rules. Comments highly appreciated. Bye, Andreas Zwirtes aka radhard The following lines were changed in peak_meter_draw: snip /* scale the samples */ left /= (MAX_PEAK / meterwidth); right /= (MAX_PEAK / meterwidth); snip has been replaced by: snip /* scale the samples (old linear version) left /= (MAX_PEAK / meterwidth); right /= (MAX_PEAK / meterwidth); */ /* scale the samples (newer dB version)*/ left = calc_dB(left) * meterwidth / 9000; right = calc_dB(right) * meterwidth / 9000; snip The new code should be inserted before peak_meter_draw and looks like this: snip /** * Calculates dB Value for the peak meter, uses peak value as input * _at_param int sample  The input value * Make sure that 0 <= value < SAMPLE_RANGE * * _at_return int  The 2 digit fixed comma result of the euation * 20 * log (sample / SAMPLE_RANGE) + 90 * Output range is 08961 (that is 0,0  89,6 dB). * Normally 0dB is full scale, here it is shifted +90dB. * The calculation is based on the results of a linear * approximation tool written specifically for this problem * by Andreas Zwirtes (radhard_at_gmx.de). The result hat an * accurracy of better than 2%. It is highly runtime optimized, * the cascading ifclauses do an successive approximation on * the input value. This avoids big lookuptables and * forloops. */ int calc_dB (int iSample) { //return n+m*(iSampleiStart)/100 int n; long m; int iStart; if (iSample < 119) //Range 14 { if (iSample < 5) //Range 12 { if (iSample < 1) //Range 1 { iStart = 0; n = 0; m = 5900; } else //Range 2 { iStart = 1; n = 59; m = 34950; } } else //Range 34 { if (iSample < 24) //Range 3 { iStart = 5; n = 1457; m = 7168; } else //Range 4 { iStart = 24; n = 2819; m = 1464; } } } else //Range 58 { if (iSample < 2918) //Range 56 { if (iSample < 592) //Range 5 { iStart = 119; n = 4210; m = 295; } else //Range 6 { iStart = 592; n = 5605; m = 60; } } else //Range 78 { if (iSample < 15352) //Range 7 { iStart = 2918; n = 7001; m = 12; } else //Range 8 { iStart = 15352; n = 8439; m = 3; } } } return n + (m * (long)(iSample  iStart)) / 100L; } snip Received on 20021007 Page template was last modified "Tue Sep 7 00:00:02 2021" The Rockbox Crew  Privacy Policy 