diff options
Diffstat (limited to 'apps/recorder/peakmeter.c')
-rw-r--r-- | apps/recorder/peakmeter.c | 120 |
1 files changed, 55 insertions, 65 deletions
diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c index 49e74de105..2b85513cf3 100644 --- a/apps/recorder/peakmeter.c +++ b/apps/recorder/peakmeter.c | |||
@@ -139,17 +139,17 @@ static const long clip_time_out[] = { | |||
139 | /* precalculated peak values that represent magical | 139 | /* precalculated peak values that represent magical |
140 | dBfs values. Used to draw the scale */ | 140 | dBfs values. Used to draw the scale */ |
141 | static const int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = { | 141 | static const int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = { |
142 | 32752, /* 0 db */ | 142 | 32736, /* 0 db */ |
143 | 22784, /* - 3 db */ | 143 | 22752, /* - 3 db */ |
144 | 14256, /* - 6 db */ | 144 | 16640, /* - 6 db */ |
145 | 11752, /* - 9 db */ | 145 | 11648, /* - 9 db */ |
146 | 9256, /* -12 db */ | 146 | 8320, /* -12 db */ |
147 | 4256, /* -18 db */ | 147 | 4364, /* -18 db */ |
148 | 2186, /* -24 db */ | 148 | 2064, /* -24 db */ |
149 | 1186, /* -30 db */ | 149 | 1194, /* -30 db */ |
150 | 373, /* -40 db */ | 150 | 363, /* -40 db */ |
151 | 102, /* -50 db */ | 151 | 101, /* -50 db */ |
152 | 33, /* -60 db */ | 152 | 34, /* -60 db */ |
153 | 0, /* -inf */ | 153 | 0, /* -inf */ |
154 | }; | 154 | }; |
155 | 155 | ||
@@ -160,17 +160,19 @@ static int db_scale_count = DB_SCALE_SRC_VALUES_SIZE; | |||
160 | * @param int sample - The input value | 160 | * @param int sample - The input value |
161 | * Make sure that 0 <= value < SAMPLE_RANGE | 161 | * Make sure that 0 <= value < SAMPLE_RANGE |
162 | * | 162 | * |
163 | * @return int - The 2 digit fixed comma result of the euation | 163 | * @return int - The 2 digit fixed point result of the euation |
164 | * 20 * log (sample / SAMPLE_RANGE) + 90 | 164 | * 20 * log (sample / SAMPLE_RANGE) + 90 |
165 | * Output range is 0-8961 (that is 0,0 - 89,6 dB). | 165 | * Output range is 0-9000 (that is 0.0 - 90.0 dB). |
166 | * Normally 0dB is full scale, here it is shifted +90dB. | 166 | * Normally 0dB is full scale, here it is shifted +90dB. |
167 | * The calculation is based on the results of a linear | 167 | * The calculation is based on the results of a linear |
168 | * approximation tool written specifically for this problem | 168 | * approximation tool written specifically for this problem |
169 | * by Andreas Zwirtes (radhard@gmx.de). The result hat an | 169 | * by Andreas Zwirtes (radhard@gmx.de). The result has an |
170 | * accurracy of better than 2%. It is highly runtime optimized, | 170 | * accurracy of better than 2%. It is highly runtime optimized, |
171 | * the cascading if-clauses do an successive approximation on | 171 | * the cascading if-clauses do an successive approximation on |
172 | * the input value. This avoids big lookup-tables and | 172 | * the input value. This avoids big lookup-tables and |
173 | * for-loops. | 173 | * for-loops. |
174 | * Improved by Jvo Studer for errors < 0.2dB for critical | ||
175 | * range of -12dB to 0dB (78.0 to 90.0dB). | ||
174 | */ | 176 | */ |
175 | 177 | ||
176 | int calc_db (int isample) | 178 | int calc_db (int isample) |
@@ -180,81 +182,69 @@ int calc_db (int isample) | |||
180 | long m; | 182 | long m; |
181 | int istart; | 183 | int istart; |
182 | 184 | ||
183 | /* Range 1-4 */ | 185 | if (isample < 2308) { /* Range 1-5 */ |
184 | if (isample < 119) { | ||
185 | 186 | ||
186 | /* Range 1-2 */ | 187 | if (isample < 115) { /* Range 1-3 */ |
187 | if (isample < 5) { | ||
188 | 188 | ||
189 | /* Range 1 */ | 189 | if (isample < 24) { |
190 | if (isample < 1) { | ||
191 | istart = 0; | ||
192 | n = 0; | ||
193 | m = 5900; | ||
194 | } | ||
195 | 190 | ||
196 | /* Range 2 */ | 191 | if (isample < 5) { |
197 | else { | 192 | istart = 1; /* Range 1 */ |
198 | istart = 1; | 193 | n = 98; |
199 | n = 59; | ||
200 | m = 34950; | 194 | m = 34950; |
201 | } | 195 | } |
202 | } | ||
203 | |||
204 | /* Range 3-4 */ | ||
205 | else { | 196 | else { |
206 | 197 | istart = 5; /* Range 2 */ | |
207 | /* Range 3 */ | 198 | n = 1496; |
208 | if (isample < 24) { | ||
209 | istart = 5; | ||
210 | n = 1457; | ||
211 | m = 7168; | 199 | m = 7168; |
212 | } | 200 | } |
201 | } | ||
202 | else { | ||
203 | istart = 24; /* Range 3 */ | ||
204 | n = 2858; | ||
205 | m = 1498; | ||
206 | } | ||
207 | } | ||
208 | else { /* Range 4-5 */ | ||
213 | 209 | ||
214 | /* Range 4 */ | 210 | if (isample < 534) { |
211 | istart = 114; /* Range 4 */ | ||
212 | n = 4207; | ||
213 | m = 319; | ||
214 | } | ||
215 | else { | 215 | else { |
216 | istart = 24; | 216 | istart = 588; /* Range 5 */ |
217 | n = 2819; | 217 | n = 5583; |
218 | m = 1464; | 218 | m = 69; |
219 | } | 219 | } |
220 | } | 220 | } |
221 | } | 221 | } |
222 | 222 | ||
223 | /* Range 5-8 */ | 223 | else { /* Range 6-9 */ |
224 | else { | ||
225 | 224 | ||
226 | /* Range 5-6 */ | 225 | if (isample < 12932) { |
227 | if (isample < 2918) { | ||
228 | 226 | ||
229 | /* Range 5 */ | 227 | if (isample < 6394) { |
230 | if (isample < 592) { | 228 | istart = 2608; /* Range 6 */ |
231 | istart = 119; | 229 | n = 6832; |
232 | n = 4210; | 230 | m = 21; |
233 | m = 295; | ||
234 | } | 231 | } |
235 | |||
236 | /* Range 6 */ | ||
237 | else { | 232 | else { |
238 | istart = 592; | 233 | istart = 7000; /* Range 7 */ |
239 | n = 5605; | 234 | n = 7682; |
240 | m = 60; | 235 | m = 9; |
241 | } | 236 | } |
242 | } | 237 | } |
243 | |||
244 | /* Range 7-8 */ | ||
245 | else { | 238 | else { |
246 | 239 | ||
247 | /* Range 7 */ | 240 | if (isample < 22450) { |
248 | if (isample < 15352) { | 241 | istart = 13000; /* Range 8 */ |
249 | istart = 2918; | 242 | n = 8219; |
250 | n = 7001; | 243 | m = 5; |
251 | m = 12; | ||
252 | } | 244 | } |
253 | |||
254 | /* Range 8 */ | ||
255 | else { | 245 | else { |
256 | istart = 15352; | 246 | istart = 22636; /* Range 9 */ |
257 | n = 8439; | 247 | n = 8697; |
258 | m = 3; | 248 | m = 3; |
259 | } | 249 | } |
260 | } | 250 | } |