Onle one table row per WPS tag
[maemo-rb.git] / apps / plugins / vu_meter.c
blobfc04bc784218b5de28d7c5282c094526f1267e69
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
9 * Copyright (C) 2003 Lee Pilgrim
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 **************************************************************************/
20 #include "plugin.h"
21 #include "lib/fixedpoint.h"
22 #include "lib/playback_control.h"
24 PLUGIN_HEADER
26 /* variable button definitions */
27 #if CONFIG_KEYPAD == RECORDER_PAD
28 #define VUMETER_QUIT BUTTON_OFF
29 #define VUMETER_HELP BUTTON_ON
30 #define VUMETER_MENU BUTTON_F1
31 #define VUMETER_UP BUTTON_UP
32 #define VUMETER_DOWN BUTTON_DOWN
33 #define LABEL_HELP "ON"
34 #define LABEL_QUIT "OFF"
35 #define LABEL_MENU "F1"
36 #define LABEL_VOLUME "UP/DOWN"
38 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
39 #define VUMETER_QUIT BUTTON_OFF
40 #define VUMETER_HELP BUTTON_ON
41 #define VUMETER_MENU BUTTON_F1
42 #define VUMETER_UP BUTTON_UP
43 #define VUMETER_DOWN BUTTON_DOWN
44 #define LABEL_HELP "ON"
45 #define LABEL_QUIT "OFF"
46 #define LABEL_MENU "F1"
47 #define LABEL_VOLUME "UP/DOWN"
49 #elif CONFIG_KEYPAD == ONDIO_PAD
50 #define VUMETER_QUIT BUTTON_OFF
51 #define VUMETER_HELP_PRE BUTTON_MENU
52 #define VUMETER_HELP (BUTTON_MENU | BUTTON_REL)
53 #define VUMETER_MENU_PRE BUTTON_MENU
54 #define VUMETER_MENU (BUTTON_MENU | BUTTON_REPEAT)
55 #define VUMETER_UP BUTTON_UP
56 #define VUMETER_DOWN BUTTON_DOWN
57 #define LABEL_HELP "MODE"
58 #define LABEL_QUIT "OFF"
59 #define LABEL_MENU "MODE.."
60 #define LABEL_VOLUME "UP/DOWN"
62 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
63 (CONFIG_KEYPAD == IRIVER_H300_PAD)
64 #define VUMETER_QUIT BUTTON_OFF
65 #define VUMETER_HELP BUTTON_ON
66 #define VUMETER_MENU BUTTON_SELECT
67 #define VUMETER_MENU2 BUTTON_MODE
68 #define VUMETER_UP BUTTON_UP
69 #define VUMETER_DOWN BUTTON_DOWN
70 #define LABEL_HELP "PLAY"
71 #define LABEL_QUIT "STOP"
72 #define LABEL_MENU "SELECT,MODE"
73 #define LABEL_VOLUME "UP/DOWN"
75 #define VUMETER_RC_QUIT BUTTON_RC_STOP
77 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
78 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
79 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
80 #define VUMETER_QUIT BUTTON_MENU
81 #define VUMETER_HELP BUTTON_PLAY
82 #define VUMETER_MENU BUTTON_SELECT
83 #define VUMETER_UP BUTTON_SCROLL_FWD
84 #define VUMETER_DOWN BUTTON_SCROLL_BACK
85 #define LABEL_HELP "PLAY"
86 #define LABEL_QUIT "MENU"
87 #define LABEL_MENU "SELECT"
88 #define LABEL_VOLUME "Wheel"
90 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
91 #define VUMETER_QUIT BUTTON_POWER
92 #define VUMETER_HELP BUTTON_A
93 #define VUMETER_MENU BUTTON_MENU
94 #define VUMETER_UP BUTTON_UP
95 #define VUMETER_DOWN BUTTON_DOWN
96 #define LABEL_HELP "A"
97 #define LABEL_QUIT "POWER"
98 #define LABEL_MENU "MENU"
99 #define LABEL_VOLUME "UP/DOWN"
101 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
102 #define VUMETER_QUIT BUTTON_POWER
103 #define VUMETER_HELP BUTTON_REC
104 #define VUMETER_MENU BUTTON_SELECT
105 #define VUMETER_UP BUTTON_SCROLL_FWD
106 #define VUMETER_DOWN BUTTON_SCROLL_BACK
107 #define LABEL_HELP "REC"
108 #define LABEL_QUIT "POWER"
109 #define LABEL_MENU "SELECT"
110 #define LABEL_VOLUME "Wheel"
112 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
113 #define VUMETER_QUIT (BUTTON_HOME|BUTTON_REPEAT)
114 #define VUMETER_HELP BUTTON_SELECT|BUTTON_REPEAT
115 #define VUMETER_MENU BUTTON_SELECT|BUTTON_REL
116 #define VUMETER_UP BUTTON_SCROLL_FWD
117 #define VUMETER_DOWN BUTTON_SCROLL_BACK
118 #define LABEL_HELP "Hold Select"
119 #define LABEL_QUIT "HOME"
120 #define LABEL_MENU "Select"
121 #define LABEL_VOLUME "Scrollwheel"
123 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
124 #define VUMETER_QUIT BUTTON_POWER
125 #define VUMETER_HELP BUTTON_REC
126 #define VUMETER_MENU BUTTON_SELECT
127 #define VUMETER_UP BUTTON_VOL_UP
128 #define VUMETER_DOWN BUTTON_VOL_DOWN
129 #define LABEL_HELP "REC"
130 #define LABEL_QUIT "POWER"
131 #define LABEL_MENU "SELECT"
132 #define LABEL_VOLUME "VOL UP/DN"
134 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
135 #define VUMETER_QUIT BUTTON_POWER
136 #define VUMETER_HELP BUTTON_HOME
137 #define VUMETER_MENU BUTTON_SELECT
138 #define VUMETER_UP BUTTON_VOL_UP
139 #define VUMETER_DOWN BUTTON_VOL_DOWN
140 #define LABEL_HELP "HOME"
141 #define LABEL_QUIT "POWER"
142 #define LABEL_MENU "SELECT"
143 #define LABEL_VOLUME "VOL UP/DN"
145 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
146 #define VUMETER_QUIT BUTTON_POWER
147 #define VUMETER_HELP (BUTTON_SELECT | BUTTON_UP)
148 #define VUMETER_MENU (BUTTON_SELECT | BUTTON_REL)
149 #define VUMETER_UP BUTTON_VOL_UP
150 #define VUMETER_DOWN BUTTON_VOL_DOWN
151 #define LABEL_HELP "SELECT + UP"
152 #define LABEL_QUIT "POWER"
153 #define LABEL_MENU "SELECT"
154 #define LABEL_VOLUME "VOL UP/DN"
156 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
157 #define VUMETER_QUIT BUTTON_POWER
158 #define VUMETER_HELP BUTTON_PLAY
159 #define VUMETER_MENU BUTTON_SELECT
160 #define VUMETER_UP BUTTON_UP
161 #define VUMETER_DOWN BUTTON_DOWN
162 #define LABEL_HELP "PLAY"
163 #define LABEL_QUIT "POWER"
164 #define LABEL_MENU "SELECT"
165 #define LABEL_VOLUME "UP/DOWN"
167 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
168 #define VUMETER_QUIT BUTTON_POWER
169 #define VUMETER_HELP BUTTON_PLAY
170 #define VUMETER_MENU BUTTON_REW
171 #define VUMETER_UP BUTTON_SCROLL_UP
172 #define VUMETER_DOWN BUTTON_SCROLL_DOWN
173 #define LABEL_HELP "PLAY"
174 #define LABEL_QUIT "POWER"
175 #define LABEL_MENU "REW"
176 #define LABEL_VOLUME "Scroller"
178 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
179 #define VUMETER_QUIT BUTTON_BACK
180 #define VUMETER_HELP BUTTON_NEXT
181 #define VUMETER_MENU BUTTON_MENU
182 #define VUMETER_UP BUTTON_UP
183 #define VUMETER_DOWN BUTTON_DOWN
184 #define LABEL_HELP "NEXT"
185 #define LABEL_QUIT "BACK"
186 #define LABEL_MENU "MENU"
187 #define LABEL_VOLUME "UP/DOWN"
189 #elif (CONFIG_KEYPAD == MROBE100_PAD)
190 #define VUMETER_QUIT BUTTON_POWER
191 #define VUMETER_HELP BUTTON_DISPLAY
192 #define VUMETER_MENU BUTTON_MENU
193 #define VUMETER_UP BUTTON_UP
194 #define VUMETER_DOWN BUTTON_DOWN
195 #define LABEL_HELP "DISPLAY"
196 #define LABEL_QUIT "POWER"
197 #define LABEL_MENU "MENU"
198 #define LABEL_VOLUME "UP/DOWN"
200 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
201 #define VUMETER_QUIT BUTTON_RC_REC
202 #define VUMETER_HELP BUTTON_RC_MODE
203 #define VUMETER_MENU BUTTON_RC_MENU
204 #define VUMETER_UP BUTTON_RC_VOL_UP
205 #define VUMETER_DOWN BUTTON_RC_VOL_DOWN
206 #define LABEL_HELP "MODE"
207 #define LABEL_QUIT "REC"
208 #define LABEL_MENU "MENU"
209 #define LABEL_VOLUME "VOL UP/DN"
211 #elif CONFIG_KEYPAD == COWON_D2_PAD
212 #define VUMETER_QUIT BUTTON_POWER
213 #define VUMETER_MENU BUTTON_MENU
214 #define LABEL_QUIT "POWER"
215 #define LABEL_MENU "MENU"
217 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
218 #define VUMETER_QUIT BUTTON_BACK
219 #define VUMETER_HELP BUTTON_SELECT
220 #define VUMETER_MENU BUTTON_MENU
221 #define VUMETER_UP BUTTON_UP
222 #define VUMETER_DOWN BUTTON_DOWN
223 #define LABEL_HELP "MIDDLE"
224 #define LABEL_QUIT "BACK"
225 #define LABEL_MENU "MENU"
226 #define LABEL_VOLUME "UP/DOWN"
228 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
229 #define VUMETER_QUIT BUTTON_POWER
230 #define VUMETER_HELP BUTTON_VIEW
231 #define VUMETER_MENU BUTTON_MENU
232 #define VUMETER_UP BUTTON_UP
233 #define VUMETER_DOWN BUTTON_DOWN
234 #define LABEL_HELP "VIEW"
235 #define LABEL_QUIT "POWER"
236 #define LABEL_MENU "MENU"
237 #define LABEL_VOLUME "UP/DOWN"
239 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
240 #define VUMETER_QUIT BUTTON_POWER
241 #define VUMETER_HELP BUTTON_RIGHT
242 #define VUMETER_MENU BUTTON_MENU
243 #define VUMETER_UP BUTTON_UP
244 #define VUMETER_DOWN BUTTON_DOWN
245 #define LABEL_HELP "RIGHT"
246 #define LABEL_QUIT "POWER"
247 #define LABEL_MENU "MENU"
248 #define LABEL_VOLUME "UP/DOWN"
250 #elif CONFIG_KEYPAD == ONDAVX747_PAD
251 #define VUMETER_QUIT BUTTON_POWER
252 #define VUMETER_MENU BUTTON_MENU
253 #define LABEL_QUIT "POWER"
254 #define LABEL_MENU "MENU"
256 #elif CONFIG_KEYPAD == ONDAVX777_PAD
257 #define VUMETER_QUIT BUTTON_POWER
258 #define LABEL_QUIT "POWER"
260 #elif CONFIG_KEYPAD == MROBE500_PAD
261 #define VUMETER_QUIT BUTTON_POWER
262 #define LABEL_QUIT "POWER"
264 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
265 #define VUMETER_QUIT BUTTON_REC
266 #define VUMETER_HELP BUTTON_PLAY
267 #define VUMETER_MENU BUTTON_LEFT
268 #define VUMETER_UP BUTTON_UP
269 #define VUMETER_DOWN BUTTON_DOWN
270 #define LABEL_HELP "PLAY"
271 #define LABEL_QUIT "REC"
272 #define LABEL_MENU "LEFT"
273 #define LABEL_VOLUME "UP/DOWN"
275 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
276 #define VUMETER_QUIT BUTTON_REC
277 #define VUMETER_HELP BUTTON_PLAY
278 #define VUMETER_MENU BUTTON_MENU
279 #define VUMETER_UP BUTTON_UP
280 #define VUMETER_DOWN BUTTON_DOWN
281 #define LABEL_HELP "PLAY"
282 #define LABEL_QUIT "REC"
283 #define LABEL_MENU "MENU"
284 #define LABEL_VOLUME "UP/DOWN"
286 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
287 #define VUMETER_QUIT (BUTTON_REC|BUTTON_PLAY)
288 #define VUMETER_HELP BUTTON_PLAY
289 #define VUMETER_MENU BUTTON_SELECT
290 #define VUMETER_UP BUTTON_VOL_UP
291 #define VUMETER_DOWN BUTTON_VOL_DOWN
292 #define LABEL_HELP "PLAY"
293 #define LABEL_QUIT "MENU"
294 #define LABEL_MENU "SELECT"
295 #define LABEL_VOLUME "UP/DOWN"
297 #else
298 #error No keymap defined!
299 #endif
301 #ifdef HAVE_TOUCHSCREEN
302 #ifndef VUMETER_QUIT
303 #define VUMETER_QUIT BUTTON_TOPLEFT
304 #define LABEL_QUIT "TOPLEFT"
305 #endif
306 #ifndef VUMETER_HELP
307 #define VUMETER_HELP BUTTON_CENTER
308 #define LABEL_HELP "CENTRE"
309 #endif
310 #ifndef VUMETER_MENU
311 #define VUMETER_MENU BUTTON_TOPRIGHT
312 #define LABEL_MENU "TOPRIGHT"
313 #endif
314 #ifndef VUMETER_UP
315 #define VUMETER_UP BUTTON_TOPMIDDLE
316 #endif
317 #ifndef VUMETER_DOWN
318 #define VUMETER_DOWN BUTTON_BOTTOMMIDDLE
319 #endif
320 #ifndef LABEL_VOLUME
321 #define LABEL_VOLUME "UP/DOWN"
322 #endif
323 #endif
325 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
326 #define mas_codec_readreg(x) rand()%MAX_PEAK
327 #endif
329 /* Defines x positions on a logarithmic (dBfs) scale. */
330 unsigned char analog_db_scale[LCD_WIDTH/2];
332 /* Define's y positions, to make the needle arch, like a real needle would. */
333 unsigned char y_values[LCD_WIDTH/2];
335 const unsigned char digital_db_scale[] =
336 {0,2,3,5,5,6,6,6,7,7,7,7,8,8,8,8,8,9,9,9,9,9,9,9,9,10,10,
337 10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11};
339 const unsigned char needle_cover[] =
340 {0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18};
342 const unsigned char sound_speaker[] = {0x18,0x24,0x42,0xFF};
343 const unsigned char sound_low_level[] = {0x24,0x18};
344 const unsigned char sound_med_level[] = {0x42,0x3C};
345 const unsigned char sound_high_level[] = {0x81,0x7E};
346 const unsigned char sound_max_level[] = {0x0E,0xDF,0x0E};
348 const int half_width = LCD_WIDTH / 2;
349 const int quarter_width = LCD_WIDTH / 4;
350 const int half_height = LCD_HEIGHT / 2;
352 /* approx ratio of the previous hard coded values */
353 const int analog_mini_1 = (LCD_WIDTH / 2)*0.1;
354 const int analog_mini_2 = (LCD_WIDTH / 2)*0.25;
355 const int analog_mini_3 = (LCD_WIDTH / 2)*0.4;
356 const int analog_mini_4 = (LCD_WIDTH / 2)*0.75;
358 const int digital_block_width = LCD_WIDTH / 11;
359 const int digital_block_gap = (int)(LCD_WIDTH / 11) / 10;
360 /* ammount to lead in on left so 11x blocks are centered - is often 0 */
361 const int digital_lead = (LCD_WIDTH - (((int)(LCD_WIDTH / 11))*11) ) / 2;
363 const int digital_block_height = (LCD_HEIGHT - 54) / 2 ;
365 #define ANALOG 0 /* The two meter types */
366 #define DIGITAL 1
368 int left_needle_top_y;
369 int left_needle_top_x;
370 int last_left_needle_top_x;
371 int right_needle_top_y;
372 int right_needle_top_x;
373 int last_right_needle_top_x = LCD_WIDTH / 2;
375 int num_left_leds;
376 int num_right_leds;
377 int last_num_left_leds;
378 int last_num_right_leds;
380 int i;
381 #ifdef HAVE_LCD_COLOR
382 int screen_foreground;
383 #endif
385 #define MAX_PEAK 0x8000
387 /* gap at the top for left/right etc */
388 #define NEEDLE_TOP 25
390 /* pow(M_E, 5) * 65536 */
391 #define E_POW_5 9726404
393 struct saved_settings {
394 int meter_type;
395 bool analog_use_db_scale;
396 bool digital_use_db_scale;
397 bool analog_minimeters;
398 bool digital_minimeters;
399 int analog_decay;
400 int digital_decay;
401 } vumeter_settings;
403 void reset_settings(void) {
404 vumeter_settings.meter_type=ANALOG;
405 vumeter_settings.analog_use_db_scale=true;
406 vumeter_settings.digital_use_db_scale=true;
407 vumeter_settings.analog_minimeters=true;
408 vumeter_settings.digital_minimeters=false;
409 vumeter_settings.analog_decay=3;
410 vumeter_settings.digital_decay=0;
413 void calc_scales(void)
415 unsigned int fx_log_factor = E_POW_5/half_width;
416 unsigned int y,z;
418 long j;
419 long k;
420 int nh = LCD_HEIGHT - NEEDLE_TOP;
421 long nh2 = nh*nh;
423 for (i=1; i <= half_width; i++)
425 /* analog scale */
426 y = (half_width/5)*fp16_log(i*fx_log_factor);
428 /* better way of checking for negative values? */
429 z = y>>16;
430 if (z > LCD_WIDTH)
431 z = 0;
433 analog_db_scale[i-1] = z;
434 /* play nice */
435 rb->yield();
437 /* y values (analog needle co-ords) */
438 j = i - (int)(half_width/2);
439 k = nh2 - ( j * j );
441 /* fsqrt+1 seems to give a closer approximation */
442 y_values[i-1] = LCD_HEIGHT - (fp_sqrt(k, 16)>>8) - 1;
443 rb->yield();
447 void load_settings(void) {
448 int fp = rb->open(PLUGIN_DEMOS_DIR "/.vu_meter", O_RDONLY);
449 if(fp>=0) {
450 rb->read(fp, &vumeter_settings, sizeof(struct saved_settings));
451 rb->close(fp);
453 else {
454 reset_settings();
455 rb->splash(HZ, "Press " LABEL_HELP " for help");
459 void save_settings(void) {
460 int fp = rb->creat(PLUGIN_DEMOS_DIR "/.vu_meter", 0666);
461 if(fp >= 0) {
462 rb->write (fp, &vumeter_settings, sizeof(struct saved_settings));
463 rb->close(fp);
467 void change_volume(int delta) {
468 char curr_vol[5];
469 int minvol = rb->sound_min(SOUND_VOLUME);
470 int maxvol = rb->sound_max(SOUND_VOLUME);
471 int vol = rb->global_settings->volume + delta;
473 if (vol > maxvol) vol = maxvol;
474 else if (vol < minvol) vol = minvol;
475 if (vol != rb->global_settings->volume) {
476 rb->sound_set(SOUND_VOLUME, vol);
477 rb->global_settings->volume = vol;
478 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol);
479 rb->lcd_putsxy(0,0, curr_vol);
480 rb->lcd_update();
481 rb->sleep(HZ/12);
485 static bool vu_meter_menu(void)
487 int selection;
488 bool menu_quit = false;
489 bool exit = false;
491 MENUITEM_STRINGLIST(menu,"VU Meter Menu",NULL,"Meter Type","Scale",
492 "Minimeters","Decay Speed","Playback Control",
493 "Quit");
495 static const struct opt_items meter_type_option[2] = {
496 { "Analog", -1 },
497 { "Digital", -1 },
500 static const struct opt_items decay_speed_option[7] = {
501 { "No Decay", -1 },
502 { "Very Fast", -1 },
503 { "Fast", -1 },
504 { "Medium", -1 },
505 { "Medium-Slow", -1 },
506 { "Slow", -1 },
507 { "Very Slow", -1 },
510 while (!menu_quit) {
511 switch(rb->do_menu(&menu, &selection, NULL, false))
513 case 0:
514 rb->set_option("Meter Type", &vumeter_settings.meter_type, INT,
515 meter_type_option, 2, NULL);
516 break;
518 case 1:
519 if(vumeter_settings.meter_type==ANALOG)
521 rb->set_bool_options("Scale", &vumeter_settings.analog_use_db_scale,
522 "dBfs", -1, "Linear", -1, NULL);
524 else
526 rb->set_bool_options("Scale", &vumeter_settings.digital_use_db_scale,
527 "dBfs", -1, "Linear", -1, NULL);
529 break;
531 case 2:
532 if(vumeter_settings.meter_type==ANALOG)
534 rb->set_bool("Enable Minimeters",
535 &vumeter_settings.analog_minimeters);
537 else
539 rb->set_bool("Enable Minimeters",
540 &vumeter_settings.digital_minimeters);
542 break;
544 case 3:
545 if(vumeter_settings.meter_type==ANALOG)
547 rb->set_option("Decay Speed", &vumeter_settings.analog_decay, INT,
548 decay_speed_option, 7, NULL);
550 else
552 rb->set_option("Decay Speed", &vumeter_settings.digital_decay, INT,
553 decay_speed_option, 7, NULL);
555 break;
557 case 4:
558 playback_control(NULL);
559 break;
561 case 5:
562 exit = true;
563 /* fall through to exit the menu */
564 default:
565 menu_quit = true;
566 break;
569 /* the menu uses the userfont, set it back to sysfont */
570 rb->lcd_setfont(FONT_SYSFIXED);
571 return exit;
574 void draw_analog_minimeters(void) {
575 rb->lcd_mono_bitmap(sound_speaker, quarter_width-28, 12, 4, 8);
576 rb->lcd_set_drawmode(DRMODE_FG);
577 if(analog_mini_1<left_needle_top_x)
578 rb->lcd_mono_bitmap(sound_low_level, quarter_width-23, 12, 2, 8);
579 if(analog_mini_2<left_needle_top_x)
580 rb->lcd_mono_bitmap(sound_med_level, quarter_width-21, 12, 2, 8);
581 if(analog_mini_3<left_needle_top_x)
582 rb->lcd_mono_bitmap(sound_high_level, quarter_width-19, 12, 2, 8);
583 if(analog_mini_4<left_needle_top_x)
584 rb->lcd_mono_bitmap(sound_max_level, quarter_width-16, 12, 3, 8);
586 rb->lcd_set_drawmode(DRMODE_SOLID);
587 rb->lcd_mono_bitmap(sound_speaker, quarter_width+half_width-30, 12, 4, 8);
588 rb->lcd_set_drawmode(DRMODE_FG);
589 if(analog_mini_1<(right_needle_top_x-half_width))
590 rb->lcd_mono_bitmap(sound_low_level, quarter_width+half_width-25, 12, 2, 8);
591 if(analog_mini_2<(right_needle_top_x-half_width))
592 rb->lcd_mono_bitmap(sound_med_level, quarter_width+half_width-23, 12, 2, 8);
593 if(analog_mini_3<(right_needle_top_x-half_width))
594 rb->lcd_mono_bitmap(sound_high_level, quarter_width+half_width-21, 12, 2, 8);
595 if(analog_mini_4<(right_needle_top_x-half_width))
596 rb->lcd_mono_bitmap(sound_max_level, quarter_width+half_width-18, 12, 3, 8);
597 rb->lcd_set_drawmode(DRMODE_SOLID);
600 void draw_digital_minimeters(void) {
601 #ifdef HAVE_LCD_COLOR
602 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_left_leds, 0));
603 #endif
604 rb->lcd_mono_bitmap(sound_speaker, 34, half_height-8, 4, 8);
605 rb->lcd_set_drawmode(DRMODE_FG);
606 if(1<num_left_leds)
607 rb->lcd_mono_bitmap(sound_low_level, 39, half_height-8, 2, 8);
608 if(2<num_left_leds)
609 rb->lcd_mono_bitmap(sound_med_level, 41, half_height-8, 2, 8);
610 if(5<num_left_leds)
611 rb->lcd_mono_bitmap(sound_high_level, 43, half_height-8, 2, 8);
612 if(8<num_left_leds)
613 rb->lcd_mono_bitmap(sound_max_level, 46, half_height-8, 3, 8);
615 #ifdef HAVE_LCD_COLOR
616 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_right_leds, 0));
617 #endif
618 rb->lcd_set_drawmode(DRMODE_SOLID);
619 rb->lcd_mono_bitmap(sound_speaker, 34, half_height+8, 4, 8);
620 rb->lcd_set_drawmode(DRMODE_FG);
621 if(1<(num_right_leds))
622 rb->lcd_mono_bitmap(sound_low_level, 39, half_height+8, 2, 8);
623 if(2<(num_right_leds))
624 rb->lcd_mono_bitmap(sound_med_level, 41, half_height+8, 2, 8);
625 if(5<(num_right_leds))
626 rb->lcd_mono_bitmap(sound_high_level, 43, half_height+8, 2, 8);
627 if(8<(num_right_leds))
628 rb->lcd_mono_bitmap(sound_max_level, 46, half_height+8, 3, 8);
629 rb->lcd_set_drawmode(DRMODE_SOLID);
631 #ifdef HAVE_LCD_COLOR
632 rb->lcd_set_foreground(screen_foreground);
633 #endif
636 void analog_meter(void) {
638 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
639 int left_peak = rb->mas_codec_readreg(0xC);
640 int right_peak = rb->mas_codec_readreg(0xD);
641 #elif (CONFIG_CODEC == SWCODEC)
642 int left_peak, right_peak;
643 rb->pcm_calculate_peaks(&left_peak, &right_peak);
644 #endif
646 if(vumeter_settings.analog_use_db_scale) {
647 left_needle_top_x = analog_db_scale[left_peak * half_width / MAX_PEAK];
648 right_needle_top_x = analog_db_scale[right_peak * half_width / MAX_PEAK] + half_width;
650 else {
651 left_needle_top_x = left_peak * half_width / MAX_PEAK;
652 right_needle_top_x = right_peak * half_width / MAX_PEAK + half_width;
655 /* Makes a decay on the needle */
656 left_needle_top_x = (left_needle_top_x+last_left_needle_top_x*vumeter_settings.analog_decay)
657 /(vumeter_settings.analog_decay+1);
658 right_needle_top_x = (right_needle_top_x+last_right_needle_top_x*vumeter_settings.analog_decay)
659 /(vumeter_settings.analog_decay+1);
661 last_left_needle_top_x = left_needle_top_x;
662 last_right_needle_top_x = right_needle_top_x;
664 left_needle_top_y = y_values[left_needle_top_x];
665 right_needle_top_y = y_values[right_needle_top_x-half_width];
667 /* Needles */
668 rb->lcd_drawline(quarter_width, LCD_HEIGHT-1, left_needle_top_x, left_needle_top_y);
669 rb->lcd_drawline((quarter_width+half_width), LCD_HEIGHT-1, right_needle_top_x, right_needle_top_y);
671 if(vumeter_settings.analog_minimeters)
672 draw_analog_minimeters();
674 /* Needle covers */
675 rb->lcd_set_drawmode(DRMODE_FG);
676 rb->lcd_mono_bitmap(needle_cover, quarter_width-6, LCD_HEIGHT-5, 13, 5);
677 rb->lcd_mono_bitmap(needle_cover, half_width+quarter_width-6, LCD_HEIGHT-5, 13, 5);
678 rb->lcd_set_drawmode(DRMODE_SOLID);
680 /* Show Left/Right */
681 rb->lcd_putsxy(quarter_width-12, 12, "Left");
682 rb->lcd_putsxy(half_width+quarter_width-12, 12, "Right");
684 /* Line above/below the Left/Right text */
685 rb->lcd_hline(0,LCD_WIDTH-1,9);
686 rb->lcd_hline(0,LCD_WIDTH-1,21);
688 for(i=0; i<half_width; i++) {
689 rb->lcd_drawpixel(i, (y_values[i])-2);
690 rb->lcd_drawpixel(i+half_width, (y_values[i])-2);
694 void digital_meter(void) {
695 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
696 int left_peak = rb->mas_codec_readreg(0xC);
697 int right_peak = rb->mas_codec_readreg(0xD);
698 #elif (CONFIG_CODEC == SWCODEC)
699 int left_peak, right_peak;
700 rb->pcm_calculate_peaks(&left_peak, &right_peak);
701 #endif
703 if(vumeter_settings.digital_use_db_scale) {
704 num_left_leds = digital_db_scale[left_peak * 44 / MAX_PEAK];
705 num_right_leds = digital_db_scale[right_peak * 44 / MAX_PEAK];
707 else {
708 num_left_leds = left_peak * 11 / MAX_PEAK;
709 num_right_leds = right_peak * 11 / MAX_PEAK;
712 num_left_leds = (num_left_leds+last_num_left_leds*vumeter_settings.digital_decay)
713 /(vumeter_settings.digital_decay+1);
714 num_right_leds = (num_right_leds+last_num_right_leds*vumeter_settings.digital_decay)
715 /(vumeter_settings.digital_decay+1);
717 last_num_left_leds = num_left_leds;
718 last_num_right_leds = num_right_leds;
720 rb->lcd_set_drawmode(DRMODE_FG);
721 /* LEDS */
722 for(i=0; i<num_left_leds; i++) {
723 #ifdef HAVE_LCD_COLOR
724 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i, 0));
725 #endif
726 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
727 14, digital_block_width - digital_block_gap, digital_block_height);
730 for(i=0; i<num_right_leds; i++) {
731 #ifdef HAVE_LCD_COLOR
732 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i, 0));
733 #endif
734 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
735 (half_height + 20), digital_block_width - digital_block_gap,
736 digital_block_height);
739 #ifdef HAVE_LCD_COLOR
740 rb->lcd_set_foreground(screen_foreground);
741 #endif
742 rb->lcd_set_drawmode(DRMODE_SOLID);
744 if(vumeter_settings.digital_minimeters)
745 draw_digital_minimeters();
747 /* Lines above/below where the LEDS are */
748 rb->lcd_hline(0,LCD_WIDTH-1,12);
749 rb->lcd_hline(0,LCD_WIDTH-1,half_height-12);
751 rb->lcd_hline(0,LCD_WIDTH-1,half_height+18);
752 rb->lcd_hline(0,LCD_WIDTH-1,LCD_HEIGHT-6);
754 /* Show Left/Right */
755 rb->lcd_putsxy(2, half_height-8, "Left");
756 rb->lcd_putsxy(2, half_height+8, "Right");
758 /* Line in the middle */
759 rb->lcd_hline(0,LCD_WIDTH-1,half_height+3);
762 enum plugin_status plugin_start(const void* parameter) {
763 int button;
764 int lastbutton = BUTTON_NONE;
766 (void) parameter;
768 calc_scales();
770 load_settings();
771 rb->lcd_setfont(FONT_SYSFIXED);
772 #ifdef HAVE_LCD_COLOR
773 screen_foreground = rb->lcd_get_foreground();
774 #endif
776 while (1)
778 rb->lcd_clear_display();
780 rb->lcd_putsxy(half_width-23, 0, "VU Meter");
782 if(vumeter_settings.meter_type==ANALOG)
783 analog_meter();
784 else
785 digital_meter();
787 rb->lcd_update();
789 button = rb->button_get_w_tmo(1);
790 switch (button)
792 #ifdef VUMETER_RC_QUIT
793 case VUMETER_RC_QUIT:
794 #endif
795 case VUMETER_QUIT:
796 save_settings();
797 return PLUGIN_OK;
798 break;
800 case VUMETER_HELP:
801 #ifdef VUMETER_HELP_PRE
802 if (lastbutton != VUMETER_HELP_PRE)
803 break;
804 #endif
805 rb->lcd_clear_display();
806 rb->lcd_puts(0, 0, LABEL_QUIT ": Exit");
807 rb->lcd_puts(0, 1, LABEL_MENU ": Settings");
808 rb->lcd_puts(0, 2, LABEL_VOLUME ": Volume");
809 rb->lcd_update();
810 rb->sleep(HZ*3);
811 break;
813 case VUMETER_MENU:
815 #ifdef VUMETER_MENU2
816 case VUMETER_MENU2:
817 #endif
819 #ifdef VUMETER_MENU_PRE
820 if (lastbutton != VUMETER_MENU_PRE)
821 break;
822 #endif
823 if(vu_meter_menu())
824 return PLUGIN_OK;
825 break;
827 case VUMETER_UP:
828 case VUMETER_UP | BUTTON_REPEAT:
829 change_volume(1);
830 break;
832 case VUMETER_DOWN:
833 case VUMETER_DOWN | BUTTON_REPEAT:
834 change_volume(-1);
835 break;
837 default:
838 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
839 return PLUGIN_USB_CONNECTED;
840 break;
842 if (button != BUTTON_NONE)
843 lastbutton = button;