Use the AMS_LOWMEM define to indicate memory size as the .lds files do in config...
[kugel-rb.git] / apps / plugins / vu_meter.c
blob16aac3a0114299d9f41bc970f929c5a3a44c6a4b
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_MENU_EXIT BUTTON_F1
32 #define VUMETER_MENU_EXIT2 BUTTON_OFF
33 #define VUMETER_UP BUTTON_UP
34 #define VUMETER_DOWN BUTTON_DOWN
35 #define LABEL_HELP "ON"
36 #define LABEL_QUIT "OFF"
37 #define LABEL_MENU "F1"
38 #define LABEL_VOLUME "UP/DOWN"
40 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
41 #define VUMETER_QUIT BUTTON_OFF
42 #define VUMETER_HELP BUTTON_ON
43 #define VUMETER_MENU BUTTON_F1
44 #define VUMETER_MENU_EXIT BUTTON_F1
45 #define VUMETER_MENU_EXIT2 BUTTON_OFF
46 #define VUMETER_UP BUTTON_UP
47 #define VUMETER_DOWN BUTTON_DOWN
48 #define LABEL_HELP "ON"
49 #define LABEL_QUIT "OFF"
50 #define LABEL_MENU "F1"
51 #define LABEL_VOLUME "UP/DOWN"
53 #elif CONFIG_KEYPAD == ONDIO_PAD
54 #define VUMETER_QUIT BUTTON_OFF
55 #define VUMETER_HELP_PRE BUTTON_MENU
56 #define VUMETER_HELP (BUTTON_MENU | BUTTON_REL)
57 #define VUMETER_MENU_PRE BUTTON_MENU
58 #define VUMETER_MENU (BUTTON_MENU | BUTTON_REPEAT)
59 #define VUMETER_MENU_EXIT BUTTON_MENU
60 #define VUMETER_MENU_EXIT2 BUTTON_OFF
61 #define VUMETER_UP BUTTON_UP
62 #define VUMETER_DOWN BUTTON_DOWN
63 #define LABEL_HELP "MODE"
64 #define LABEL_QUIT "OFF"
65 #define LABEL_MENU "MODE.."
66 #define LABEL_VOLUME "UP/DOWN"
68 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
69 (CONFIG_KEYPAD == IRIVER_H300_PAD)
70 #define VUMETER_QUIT BUTTON_OFF
71 #define VUMETER_HELP BUTTON_ON
72 #define VUMETER_MENU BUTTON_SELECT
73 #define VUMETER_MENU2 BUTTON_MODE
74 #define VUMETER_MENU_EXIT BUTTON_SELECT
75 #define VUMETER_MENU_EXIT2 BUTTON_OFF
76 #define VUMETER_UP BUTTON_UP
77 #define VUMETER_DOWN BUTTON_DOWN
78 #define LABEL_HELP "PLAY"
79 #define LABEL_QUIT "STOP"
80 #define LABEL_MENU "SELECT,MODE"
81 #define LABEL_VOLUME "UP/DOWN"
83 #define VUMETER_RC_QUIT BUTTON_RC_STOP
85 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
86 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
87 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
88 #define VUMETER_QUIT BUTTON_MENU
89 #define VUMETER_HELP BUTTON_PLAY
90 #define VUMETER_MENU BUTTON_SELECT
91 #define VUMETER_MENU_EXIT BUTTON_SELECT
92 #define VUMETER_MENU_EXIT2 BUTTON_MENU
93 #define VUMETER_UP BUTTON_SCROLL_FWD
94 #define VUMETER_DOWN BUTTON_SCROLL_BACK
95 #define LABEL_HELP "PLAY"
96 #define LABEL_QUIT "MENU"
97 #define LABEL_MENU "SELECT"
98 #define LABEL_VOLUME "Wheel"
100 #elif (CONFIG_KEYPAD == GIGABEAT_PAD)
101 #define VUMETER_QUIT BUTTON_POWER
102 #define VUMETER_HELP BUTTON_A
103 #define VUMETER_MENU BUTTON_MENU
104 #define VUMETER_MENU_EXIT BUTTON_MENU
105 #define VUMETER_MENU_EXIT2 BUTTON_POWER
106 #define VUMETER_UP BUTTON_UP
107 #define VUMETER_DOWN BUTTON_DOWN
108 #define LABEL_HELP "A"
109 #define LABEL_QUIT "POWER"
110 #define LABEL_MENU "MENU"
111 #define LABEL_VOLUME "UP/DOWN"
113 #elif (CONFIG_KEYPAD == SANSA_E200_PAD)
114 #define VUMETER_QUIT BUTTON_POWER
115 #define VUMETER_HELP BUTTON_REC
116 #define VUMETER_MENU BUTTON_SELECT
117 #define VUMETER_MENU_EXIT BUTTON_SELECT
118 #define VUMETER_MENU_EXIT2 BUTTON_POWER
119 #define VUMETER_UP BUTTON_SCROLL_FWD
120 #define VUMETER_DOWN BUTTON_SCROLL_BACK
121 #define LABEL_HELP "REC"
122 #define LABEL_QUIT "POWER"
123 #define LABEL_MENU "SELECT"
124 #define LABEL_VOLUME "Wheel"
126 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
127 #define VUMETER_QUIT (BUTTON_HOME|BUTTON_REPEAT)
128 #define VUMETER_HELP BUTTON_SELECT|BUTTON_REPEAT
129 #define VUMETER_MENU BUTTON_SELECT|BUTTON_REL
130 #define VUMETER_MENU_EXIT BUTTON_SELECT
131 #define VUMETER_MENU_EXIT2 BUTTON_DOWN
132 #define VUMETER_UP BUTTON_SCROLL_FWD
133 #define VUMETER_DOWN BUTTON_SCROLL_BACK
134 #define LABEL_HELP "Hold Select"
135 #define LABEL_QUIT "HOME"
136 #define LABEL_MENU "Select"
137 #define LABEL_VOLUME "Scrollwheel"
139 #elif (CONFIG_KEYPAD == SANSA_C200_PAD)
140 #define VUMETER_QUIT BUTTON_POWER
141 #define VUMETER_HELP BUTTON_REC
142 #define VUMETER_MENU BUTTON_SELECT
143 #define VUMETER_MENU_EXIT BUTTON_SELECT
144 #define VUMETER_MENU_EXIT2 BUTTON_POWER
145 #define VUMETER_UP BUTTON_VOL_UP
146 #define VUMETER_DOWN BUTTON_VOL_DOWN
147 #define LABEL_HELP "REC"
148 #define LABEL_QUIT "POWER"
149 #define LABEL_MENU "SELECT"
150 #define LABEL_VOLUME "VOL UP/DN"
152 #elif (CONFIG_KEYPAD == SANSA_CLIP_PAD)
153 #define VUMETER_QUIT BUTTON_POWER
154 #define VUMETER_HELP BUTTON_HOME
155 #define VUMETER_MENU BUTTON_SELECT
156 #define VUMETER_MENU_EXIT BUTTON_SELECT
157 #define VUMETER_MENU_EXIT2 BUTTON_POWER
158 #define VUMETER_UP BUTTON_VOL_UP
159 #define VUMETER_DOWN BUTTON_VOL_DOWN
160 #define LABEL_HELP "HOME"
161 #define LABEL_QUIT "POWER"
162 #define LABEL_MENU "SELECT"
163 #define LABEL_VOLUME "VOL UP/DN"
165 #elif (CONFIG_KEYPAD == SANSA_M200_PAD)
166 #define VUMETER_QUIT BUTTON_POWER
167 #define VUMETER_HELP (BUTTON_SELECT | BUTTON_UP)
168 #define VUMETER_MENU (BUTTON_SELECT | BUTTON_REL)
169 #define VUMETER_MENU_EXIT (BUTTON_SELECT | BUTTON_REL)
170 #define VUMETER_MENU_EXIT2 BUTTON_POWER
171 #define VUMETER_UP BUTTON_VOL_UP
172 #define VUMETER_DOWN BUTTON_VOL_DOWN
173 #define LABEL_HELP "SELECT + UP"
174 #define LABEL_QUIT "POWER"
175 #define LABEL_MENU "SELECT"
176 #define LABEL_VOLUME "VOL UP/DN"
178 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
179 #define VUMETER_QUIT BUTTON_POWER
180 #define VUMETER_HELP BUTTON_PLAY
181 #define VUMETER_MENU BUTTON_SELECT
182 #define VUMETER_MENU_EXIT BUTTON_SELECT
183 #define VUMETER_MENU_EXIT2 BUTTON_POWER
184 #define VUMETER_UP BUTTON_UP
185 #define VUMETER_DOWN BUTTON_DOWN
186 #define LABEL_HELP "PLAY"
187 #define LABEL_QUIT "POWER"
188 #define LABEL_MENU "SELECT"
189 #define LABEL_VOLUME "UP/DOWN"
191 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
192 #define VUMETER_QUIT BUTTON_POWER
193 #define VUMETER_HELP BUTTON_PLAY
194 #define VUMETER_MENU BUTTON_REW
195 #define VUMETER_MENU_EXIT BUTTON_REW
196 #define VUMETER_MENU_EXIT2 BUTTON_POWER
197 #define VUMETER_UP BUTTON_SCROLL_UP
198 #define VUMETER_DOWN BUTTON_SCROLL_DOWN
199 #define LABEL_HELP "PLAY"
200 #define LABEL_QUIT "POWER"
201 #define LABEL_MENU "REW"
202 #define LABEL_VOLUME "Scroller"
204 #elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
205 #define VUMETER_QUIT BUTTON_BACK
206 #define VUMETER_HELP BUTTON_NEXT
207 #define VUMETER_MENU BUTTON_MENU
208 #define VUMETER_MENU_EXIT BUTTON_MENU
209 #define VUMETER_MENU_EXIT2 BUTTON_PLAY
210 #define VUMETER_UP BUTTON_UP
211 #define VUMETER_DOWN BUTTON_DOWN
212 #define LABEL_HELP "NEXT"
213 #define LABEL_QUIT "BACK"
214 #define LABEL_MENU "MENU"
215 #define LABEL_VOLUME "UP/DOWN"
217 #elif (CONFIG_KEYPAD == MROBE100_PAD)
218 #define VUMETER_QUIT BUTTON_POWER
219 #define VUMETER_HELP BUTTON_DISPLAY
220 #define VUMETER_MENU BUTTON_MENU
221 #define VUMETER_MENU_EXIT BUTTON_MENU
222 #define VUMETER_MENU_EXIT2 BUTTON_POWER
223 #define VUMETER_UP BUTTON_UP
224 #define VUMETER_DOWN BUTTON_DOWN
225 #define LABEL_HELP "DISPLAY"
226 #define LABEL_QUIT "POWER"
227 #define LABEL_MENU "MENU"
228 #define LABEL_VOLUME "UP/DOWN"
230 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
231 #define VUMETER_QUIT BUTTON_RC_REC
232 #define VUMETER_HELP BUTTON_RC_MODE
233 #define VUMETER_MENU BUTTON_RC_MENU
234 #define VUMETER_MENU_EXIT BUTTON_RC_MENU
235 #define VUMETER_MENU_EXIT2 BUTTON_RC_REC
236 #define VUMETER_UP BUTTON_RC_VOL_UP
237 #define VUMETER_DOWN BUTTON_RC_VOL_DOWN
238 #define LABEL_HELP "MODE"
239 #define LABEL_QUIT "REC"
240 #define LABEL_MENU "MENU"
241 #define LABEL_VOLUME "VOL UP/DN"
243 #elif CONFIG_KEYPAD == COWOND2_PAD
244 #define VUMETER_QUIT BUTTON_POWER
245 #define VUMETER_MENU BUTTON_MENU
246 #define VUMETER_MENU_EXIT BUTTON_POWER
247 #define LABEL_QUIT "POWER"
248 #define LABEL_MENU "MENU"
250 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
251 #define VUMETER_QUIT BUTTON_BACK
252 #define VUMETER_HELP BUTTON_SELECT
253 #define VUMETER_MENU BUTTON_MENU
254 #define VUMETER_MENU_EXIT BUTTON_MENU
255 #define VUMETER_UP BUTTON_UP
256 #define VUMETER_DOWN BUTTON_DOWN
257 #define LABEL_HELP "MIDDLE"
258 #define LABEL_QUIT "BACK"
259 #define LABEL_MENU "MENU"
260 #define LABEL_VOLUME "UP/DOWN"
262 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
263 #define VUMETER_QUIT BUTTON_POWER
264 #define VUMETER_HELP BUTTON_VIEW
265 #define VUMETER_MENU BUTTON_MENU
266 #define VUMETER_MENU_EXIT BUTTON_MENU
267 #define VUMETER_MENU_EXIT2 BUTTON_POWER
268 #define VUMETER_UP BUTTON_UP
269 #define VUMETER_DOWN BUTTON_DOWN
270 #define LABEL_HELP "VIEW"
271 #define LABEL_QUIT "POWER"
272 #define LABEL_MENU "MENU"
273 #define LABEL_VOLUME "UP/DOWN"
275 #elif CONFIG_KEYPAD == ONDAVX747_PAD
276 #define VUMETER_QUIT BUTTON_POWER
277 #define VUMETER_MENU BUTTON_MENU
278 #define VUMETER_MENU_EXIT BUTTON_POWER
279 #define LABEL_QUIT "POWER"
280 #define LABEL_MENU "MENU"
282 #elif CONFIG_KEYPAD == MROBE500_PAD
283 #define VUMETER_QUIT BUTTON_POWER
284 #define LABEL_QUIT "POWER"
286 #else
287 #error No keymap defined!
288 #endif
290 #ifdef HAVE_TOUCHSCREEN
291 #ifndef VUMETER_QUIT
292 #define VUMETER_QUIT BUTTON_TOPLEFT
293 #define LABEL_QUIT "TOPLEFT"
294 #endif
295 #ifndef VUMETER_HELP
296 #define VUMETER_HELP BUTTON_CENTER
297 #define LABEL_HELP "CENTRE"
298 #endif
299 #ifndef VUMETER_MENU
300 #define VUMETER_MENU BUTTON_TOPRIGHT
301 #define LABEL_MENU "TOPRIGHT"
302 #endif
303 #ifndef VUMETER_MENU_EXIT
304 #define VUMETER_MENU_EXIT BUTTON_TOPLEFT
305 #endif
306 #ifndef VUMETER_UP
307 #define VUMETER_UP BUTTON_TOPMIDDLE
308 #endif
309 #ifndef VUMETER_DOWN
310 #define VUMETER_DOWN BUTTON_BOTTOMMIDDLE
311 #endif
312 #ifndef LABEL_VOLUME
313 #define LABEL_VOLUME "UP/DOWN"
314 #endif
315 #endif
317 #if defined(SIMULATOR) && (CONFIG_CODEC != SWCODEC)
318 #define mas_codec_readreg(x) rand()%MAX_PEAK
319 #endif
321 /* Defines x positions on a logarithmic (dBfs) scale. */
322 unsigned char analog_db_scale[LCD_WIDTH/2];
324 /* Define's y positions, to make the needle arch, like a real needle would. */
325 unsigned char y_values[LCD_WIDTH/2];
327 const unsigned char digital_db_scale[] =
328 {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,
329 10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11};
331 const unsigned char needle_cover[] =
332 {0x18, 0x1c, 0x1c, 0x1e, 0x1e, 0x1f, 0x1f, 0x1f, 0x1e, 0x1e, 0x1c, 0x1c, 0x18};
334 const unsigned char sound_speaker[] = {0x18,0x24,0x42,0xFF};
335 const unsigned char sound_low_level[] = {0x24,0x18};
336 const unsigned char sound_med_level[] = {0x42,0x3C};
337 const unsigned char sound_high_level[] = {0x81,0x7E};
338 const unsigned char sound_max_level[] = {0x0E,0xDF,0x0E};
340 const int half_width = LCD_WIDTH / 2;
341 const int quarter_width = LCD_WIDTH / 4;
342 const int half_height = LCD_HEIGHT / 2;
344 /* approx ratio of the previous hard coded values */
345 const int analog_mini_1 = (LCD_WIDTH / 2)*0.1;
346 const int analog_mini_2 = (LCD_WIDTH / 2)*0.25;
347 const int analog_mini_3 = (LCD_WIDTH / 2)*0.4;
348 const int analog_mini_4 = (LCD_WIDTH / 2)*0.75;
350 const int digital_block_width = LCD_WIDTH / 11;
351 const int digital_block_gap = (int)(LCD_WIDTH / 11) / 10;
352 /* ammount to lead in on left so 11x blocks are centered - is often 0 */
353 const int digital_lead = (LCD_WIDTH - (((int)(LCD_WIDTH / 11))*11) ) / 2;
355 const int digital_block_height = (LCD_HEIGHT - 54) / 2 ;
357 #define ANALOG 0 /* The two meter types */
358 #define DIGITAL 1
360 int left_needle_top_y;
361 int left_needle_top_x;
362 int last_left_needle_top_x;
363 int right_needle_top_y;
364 int right_needle_top_x;
365 int last_right_needle_top_x = LCD_WIDTH / 2;
367 int num_left_leds;
368 int num_right_leds;
369 int last_num_left_leds;
370 int last_num_right_leds;
372 int i;
373 #ifdef HAVE_LCD_COLOR
374 int screen_foreground;
375 #endif
377 #define MAX_PEAK 0x8000
379 /* gap at the top for left/right etc */
380 #define NEEDLE_TOP 25
382 /* pow(M_E, 5) * 65536 */
383 #define E_POW_5 9726404
385 struct saved_settings {
386 int meter_type;
387 bool analog_use_db_scale;
388 bool digital_use_db_scale;
389 bool analog_minimeters;
390 bool digital_minimeters;
391 int analog_decay;
392 int digital_decay;
393 } vumeter_settings;
395 void reset_settings(void) {
396 vumeter_settings.meter_type=ANALOG;
397 vumeter_settings.analog_use_db_scale=true;
398 vumeter_settings.digital_use_db_scale=true;
399 vumeter_settings.analog_minimeters=true;
400 vumeter_settings.digital_minimeters=false;
401 vumeter_settings.analog_decay=3;
402 vumeter_settings.digital_decay=0;
405 void calc_scales(void)
407 unsigned int fx_log_factor = E_POW_5/half_width;
408 unsigned int y,z;
410 long j;
411 long k;
412 int nh = LCD_HEIGHT - NEEDLE_TOP;
413 long nh2 = nh*nh;
415 for (i=1; i <= half_width; i++)
417 /* analog scale */
418 y = (half_width/5)*flog(i*fx_log_factor);
420 /* better way of checking for negative values? */
421 z = y>>16;
422 if (z > LCD_WIDTH)
423 z = 0;
425 analog_db_scale[i-1] = z;
426 /* play nice */
427 rb->yield();
429 /* y values (analog needle co-ords) */
430 j = i - (int)(half_width/2);
431 k = nh2 - ( j * j );
433 /* fsqrt+1 seems to give a closer approximation */
434 y_values[i-1] = LCD_HEIGHT - (fsqrt(k, 16)>>8) - 1;
435 rb->yield();
439 void load_settings(void) {
440 int fp = rb->open(PLUGIN_DEMOS_DIR "/.vu_meter", O_RDONLY);
441 if(fp>=0) {
442 rb->read(fp, &vumeter_settings, sizeof(struct saved_settings));
443 rb->close(fp);
445 else {
446 reset_settings();
447 rb->splash(HZ, "Press " LABEL_HELP " for help");
451 void save_settings(void) {
452 int fp = rb->creat(PLUGIN_DEMOS_DIR "/.vu_meter");
453 if(fp >= 0) {
454 rb->write (fp, &vumeter_settings, sizeof(struct saved_settings));
455 rb->close(fp);
459 void change_volume(int delta) {
460 char curr_vol[5];
461 int minvol = rb->sound_min(SOUND_VOLUME);
462 int maxvol = rb->sound_max(SOUND_VOLUME);
463 int vol = rb->global_settings->volume + delta;
465 if (vol > maxvol) vol = maxvol;
466 else if (vol < minvol) vol = minvol;
467 if (vol != rb->global_settings->volume) {
468 rb->sound_set(SOUND_VOLUME, vol);
469 rb->global_settings->volume = vol;
470 rb->snprintf(curr_vol, sizeof(curr_vol), "%d", vol);
471 rb->lcd_putsxy(0,0, curr_vol);
472 rb->lcd_update();
473 rb->sleep(HZ/12);
477 static bool vu_meter_menu(void)
479 int selection;
480 bool menu_quit = false;
481 bool exit = false;
483 MENUITEM_STRINGLIST(menu,"VU Meter Menu",NULL,"Meter Type","Scale",
484 "Minimeters","Decay Speed","Playback Control",
485 "Quit");
487 static const struct opt_items meter_type_option[2] = {
488 { "Analog", -1 },
489 { "Digital", -1 },
492 static const struct opt_items decay_speed_option[7] = {
493 { "No Decay", -1 },
494 { "Very Fast", -1 },
495 { "Fast", -1 },
496 { "Medium", -1 },
497 { "Medium-Slow", -1 },
498 { "Slow", -1 },
499 { "Very Slow", -1 },
502 while (!menu_quit) {
503 switch(rb->do_menu(&menu, &selection, NULL, false))
505 case 0:
506 rb->set_option("Meter Type", &vumeter_settings.meter_type, INT,
507 meter_type_option, 2, NULL);
508 break;
510 case 1:
511 if(vumeter_settings.meter_type==ANALOG)
513 rb->set_bool_options("Scale", &vumeter_settings.analog_use_db_scale,
514 "dBfs", -1, "Linear", -1, NULL);
516 else
518 rb->set_bool_options("Scale", &vumeter_settings.digital_use_db_scale,
519 "dBfs", -1, "Linear", -1, NULL);
521 break;
523 case 2:
524 if(vumeter_settings.meter_type==ANALOG)
526 rb->set_bool("Enable Minimeters",
527 &vumeter_settings.analog_minimeters);
529 else
531 rb->set_bool("Enable Minimeters",
532 &vumeter_settings.digital_minimeters);
534 break;
536 case 3:
537 if(vumeter_settings.meter_type==ANALOG)
539 rb->set_option("Decay Speed", &vumeter_settings.analog_decay, INT,
540 decay_speed_option, 7, NULL);
542 else
544 rb->set_option("Decay Speed", &vumeter_settings.digital_decay, INT,
545 decay_speed_option, 7, NULL);
547 break;
549 case 4:
550 playback_control(NULL);
551 break;
553 case 5:
554 exit = true;
555 /* fall through to exit the menu */
556 default:
557 menu_quit = true;
558 break;
561 /* the menu uses the userfont, set it back to sysfont */
562 rb->lcd_setfont(FONT_SYSFIXED);
563 return exit;
566 void draw_analog_minimeters(void) {
567 rb->lcd_mono_bitmap(sound_speaker, quarter_width-28, 12, 4, 8);
568 rb->lcd_set_drawmode(DRMODE_FG);
569 if(analog_mini_1<left_needle_top_x)
570 rb->lcd_mono_bitmap(sound_low_level, quarter_width-23, 12, 2, 8);
571 if(analog_mini_2<left_needle_top_x)
572 rb->lcd_mono_bitmap(sound_med_level, quarter_width-21, 12, 2, 8);
573 if(analog_mini_3<left_needle_top_x)
574 rb->lcd_mono_bitmap(sound_high_level, quarter_width-19, 12, 2, 8);
575 if(analog_mini_4<left_needle_top_x)
576 rb->lcd_mono_bitmap(sound_max_level, quarter_width-16, 12, 3, 8);
578 rb->lcd_set_drawmode(DRMODE_SOLID);
579 rb->lcd_mono_bitmap(sound_speaker, quarter_width+half_width-30, 12, 4, 8);
580 rb->lcd_set_drawmode(DRMODE_FG);
581 if(analog_mini_1<(right_needle_top_x-half_width))
582 rb->lcd_mono_bitmap(sound_low_level, quarter_width+half_width-25, 12, 2, 8);
583 if(analog_mini_2<(right_needle_top_x-half_width))
584 rb->lcd_mono_bitmap(sound_med_level, quarter_width+half_width-23, 12, 2, 8);
585 if(analog_mini_3<(right_needle_top_x-half_width))
586 rb->lcd_mono_bitmap(sound_high_level, quarter_width+half_width-21, 12, 2, 8);
587 if(analog_mini_4<(right_needle_top_x-half_width))
588 rb->lcd_mono_bitmap(sound_max_level, quarter_width+half_width-18, 12, 3, 8);
589 rb->lcd_set_drawmode(DRMODE_SOLID);
592 void draw_digital_minimeters(void) {
593 #ifdef HAVE_LCD_COLOR
594 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_left_leds, 0));
595 #endif
596 rb->lcd_mono_bitmap(sound_speaker, 34, half_height-8, 4, 8);
597 rb->lcd_set_drawmode(DRMODE_FG);
598 if(1<num_left_leds)
599 rb->lcd_mono_bitmap(sound_low_level, 39, half_height-8, 2, 8);
600 if(2<num_left_leds)
601 rb->lcd_mono_bitmap(sound_med_level, 41, half_height-8, 2, 8);
602 if(5<num_left_leds)
603 rb->lcd_mono_bitmap(sound_high_level, 43, half_height-8, 2, 8);
604 if(8<num_left_leds)
605 rb->lcd_mono_bitmap(sound_max_level, 46, half_height-8, 3, 8);
607 #ifdef HAVE_LCD_COLOR
608 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * num_right_leds, 0));
609 #endif
610 rb->lcd_set_drawmode(DRMODE_SOLID);
611 rb->lcd_mono_bitmap(sound_speaker, 34, half_height+8, 4, 8);
612 rb->lcd_set_drawmode(DRMODE_FG);
613 if(1<(num_right_leds))
614 rb->lcd_mono_bitmap(sound_low_level, 39, half_height+8, 2, 8);
615 if(2<(num_right_leds))
616 rb->lcd_mono_bitmap(sound_med_level, 41, half_height+8, 2, 8);
617 if(5<(num_right_leds))
618 rb->lcd_mono_bitmap(sound_high_level, 43, half_height+8, 2, 8);
619 if(8<(num_right_leds))
620 rb->lcd_mono_bitmap(sound_max_level, 46, half_height+8, 3, 8);
621 rb->lcd_set_drawmode(DRMODE_SOLID);
623 #ifdef HAVE_LCD_COLOR
624 rb->lcd_set_foreground(screen_foreground);
625 #endif
628 void analog_meter(void) {
630 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
631 int left_peak = rb->mas_codec_readreg(0xC);
632 int right_peak = rb->mas_codec_readreg(0xD);
633 #elif (CONFIG_CODEC == SWCODEC)
634 int left_peak, right_peak;
635 rb->pcm_calculate_peaks(&left_peak, &right_peak);
636 #endif
638 if(vumeter_settings.analog_use_db_scale) {
639 left_needle_top_x = analog_db_scale[left_peak * half_width / MAX_PEAK];
640 right_needle_top_x = analog_db_scale[right_peak * half_width / MAX_PEAK] + half_width;
642 else {
643 left_needle_top_x = left_peak * half_width / MAX_PEAK;
644 right_needle_top_x = right_peak * half_width / MAX_PEAK + half_width;
647 /* Makes a decay on the needle */
648 left_needle_top_x = (left_needle_top_x+last_left_needle_top_x*vumeter_settings.analog_decay)
649 /(vumeter_settings.analog_decay+1);
650 right_needle_top_x = (right_needle_top_x+last_right_needle_top_x*vumeter_settings.analog_decay)
651 /(vumeter_settings.analog_decay+1);
653 last_left_needle_top_x = left_needle_top_x;
654 last_right_needle_top_x = right_needle_top_x;
656 left_needle_top_y = y_values[left_needle_top_x];
657 right_needle_top_y = y_values[right_needle_top_x-half_width];
659 /* Needles */
660 rb->lcd_drawline(quarter_width, LCD_HEIGHT-1, left_needle_top_x, left_needle_top_y);
661 rb->lcd_drawline((quarter_width+half_width), LCD_HEIGHT-1, right_needle_top_x, right_needle_top_y);
663 if(vumeter_settings.analog_minimeters)
664 draw_analog_minimeters();
666 /* Needle covers */
667 rb->lcd_set_drawmode(DRMODE_FG);
668 rb->lcd_mono_bitmap(needle_cover, quarter_width-6, LCD_HEIGHT-5, 13, 5);
669 rb->lcd_mono_bitmap(needle_cover, half_width+quarter_width-6, LCD_HEIGHT-5, 13, 5);
670 rb->lcd_set_drawmode(DRMODE_SOLID);
672 /* Show Left/Right */
673 rb->lcd_putsxy(quarter_width-12, 12, "Left");
674 rb->lcd_putsxy(half_width+quarter_width-12, 12, "Right");
676 /* Line above/below the Left/Right text */
677 rb->lcd_hline(0,LCD_WIDTH-1,9);
678 rb->lcd_hline(0,LCD_WIDTH-1,21);
680 for(i=0; i<half_width; i++) {
681 rb->lcd_drawpixel(i, (y_values[i])-2);
682 rb->lcd_drawpixel(i+half_width, (y_values[i])-2);
686 void digital_meter(void) {
687 #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F)
688 int left_peak = rb->mas_codec_readreg(0xC);
689 int right_peak = rb->mas_codec_readreg(0xD);
690 #elif (CONFIG_CODEC == SWCODEC)
691 int left_peak, right_peak;
692 rb->pcm_calculate_peaks(&left_peak, &right_peak);
693 #endif
695 if(vumeter_settings.digital_use_db_scale) {
696 num_left_leds = digital_db_scale[left_peak * 44 / MAX_PEAK];
697 num_right_leds = digital_db_scale[right_peak * 44 / MAX_PEAK];
699 else {
700 num_left_leds = left_peak * 11 / MAX_PEAK;
701 num_right_leds = right_peak * 11 / MAX_PEAK;
704 num_left_leds = (num_left_leds+last_num_left_leds*vumeter_settings.digital_decay)
705 /(vumeter_settings.digital_decay+1);
706 num_right_leds = (num_right_leds+last_num_right_leds*vumeter_settings.digital_decay)
707 /(vumeter_settings.digital_decay+1);
709 last_num_left_leds = num_left_leds;
710 last_num_right_leds = num_right_leds;
712 rb->lcd_set_drawmode(DRMODE_FG);
713 /* LEDS */
714 for(i=0; i<num_left_leds; i++) {
715 #ifdef HAVE_LCD_COLOR
716 rb->lcd_set_foreground(LCD_RGBPACK(255, 255 - 23 * i, 0));
717 #endif
718 rb->lcd_fillrect((digital_lead + (i*digital_block_width)),
719 14, digital_block_width - digital_block_gap, digital_block_height);
722 for(i=0; i<num_right_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 (half_height + 20), digital_block_width - digital_block_gap,
728 digital_block_height);
731 #ifdef HAVE_LCD_COLOR
732 rb->lcd_set_foreground(screen_foreground);
733 #endif
734 rb->lcd_set_drawmode(DRMODE_SOLID);
736 if(vumeter_settings.digital_minimeters)
737 draw_digital_minimeters();
739 /* Lines above/below where the LEDS are */
740 rb->lcd_hline(0,LCD_WIDTH-1,12);
741 rb->lcd_hline(0,LCD_WIDTH-1,half_height-12);
743 rb->lcd_hline(0,LCD_WIDTH-1,half_height+18);
744 rb->lcd_hline(0,LCD_WIDTH-1,LCD_HEIGHT-6);
746 /* Show Left/Right */
747 rb->lcd_putsxy(2, half_height-8, "Left");
748 rb->lcd_putsxy(2, half_height+8, "Right");
750 /* Line in the middle */
751 rb->lcd_hline(0,LCD_WIDTH-1,half_height+3);
754 enum plugin_status plugin_start(const void* parameter) {
755 int button;
756 int lastbutton = BUTTON_NONE;
758 (void) parameter;
760 calc_scales();
762 load_settings();
763 rb->lcd_setfont(FONT_SYSFIXED);
764 #ifdef HAVE_LCD_COLOR
765 screen_foreground = rb->lcd_get_foreground();
766 #endif
768 while (1)
770 rb->lcd_clear_display();
772 rb->lcd_putsxy(half_width-23, 0, "VU Meter");
774 if(vumeter_settings.meter_type==ANALOG)
775 analog_meter();
776 else
777 digital_meter();
779 rb->lcd_update();
781 button = rb->button_get_w_tmo(1);
782 switch (button)
784 #ifdef VUMETER_RC_QUIT
785 case VUMETER_RC_QUIT:
786 #endif
787 case VUMETER_QUIT:
788 save_settings();
789 return PLUGIN_OK;
790 break;
792 case VUMETER_HELP:
793 #ifdef VUMETER_HELP_PRE
794 if (lastbutton != VUMETER_HELP_PRE)
795 break;
796 #endif
797 rb->lcd_clear_display();
798 rb->lcd_puts(0, 0, LABEL_QUIT ": Exit");
799 rb->lcd_puts(0, 1, LABEL_MENU ": Settings");
800 rb->lcd_puts(0, 2, LABEL_VOLUME ": Volume");
801 rb->lcd_update();
802 rb->sleep(HZ*3);
803 break;
805 case VUMETER_MENU:
807 #ifdef VUMETER_MENU2
808 case VUMETER_MENU2:
809 #endif
811 #ifdef VUMETER_MENU_PRE
812 if (lastbutton != VUMETER_MENU_PRE)
813 break;
814 #endif
815 if(vu_meter_menu())
816 return PLUGIN_OK;
817 break;
819 case VUMETER_UP:
820 case VUMETER_UP | BUTTON_REPEAT:
821 change_volume(1);
822 break;
824 case VUMETER_DOWN:
825 case VUMETER_DOWN | BUTTON_REPEAT:
826 change_volume(-1);
827 break;
829 default:
830 if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
831 return PLUGIN_USB_CONNECTED;
832 break;
834 if (button != BUTTON_NONE)
835 lastbutton = button;