diff options
Diffstat (limited to 'apps/plugins/fft/fft.c')
-rw-r--r-- | apps/plugins/fft/fft.c | 100 |
1 files changed, 45 insertions, 55 deletions
diff --git a/apps/plugins/fft/fft.c b/apps/plugins/fft/fft.c index 28e775a9c1..b971a8f92f 100644 --- a/apps/plugins/fft/fft.c +++ b/apps/plugins/fft/fft.c | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include "lib/helper.h" | 23 | #include "lib/helper.h" |
24 | #include "lib/xlcd.h" | 24 | #include "lib/xlcd.h" |
25 | #include "lib/mylcd.h" | ||
25 | #include "math.h" | 26 | #include "math.h" |
26 | #include "fracmul.h" | 27 | #include "fracmul.h" |
27 | 28 | ||
@@ -257,16 +258,6 @@ GREY_INFO_STRUCT | |||
257 | #define FFT_SIZE 4096 /* 2048*2 */ | 258 | #define FFT_SIZE 4096 /* 2048*2 */ |
258 | #endif | 259 | #endif |
259 | 260 | ||
260 | #ifdef HAVE_LCD_COLOR | ||
261 | #define lcd_(fn) rb->lcd_##fn | ||
262 | #define lcd_scroll_up xlcd_scroll_up | ||
263 | #define lcd_scroll_left xlcd_scroll_left | ||
264 | #else | ||
265 | #define lcd_(fn) grey_##fn | ||
266 | #define lcd_scroll_up grey_scroll_up | ||
267 | #define lcd_scroll_left grey_scroll_left | ||
268 | #endif | ||
269 | |||
270 | #define ARRAYLEN_IN (FFT_SIZE) | 261 | #define ARRAYLEN_IN (FFT_SIZE) |
271 | #define ARRAYLEN_OUT (FFT_SIZE) | 262 | #define ARRAYLEN_OUT (FFT_SIZE) |
272 | #define ARRAYLEN_PLOT (FFT_SIZE/2-1) /* FFT is symmetric, ignore DC */ | 263 | #define ARRAYLEN_PLOT (FFT_SIZE/2-1) /* FFT is symmetric, ignore DC */ |
@@ -568,15 +559,14 @@ static void draw_bars_horizontal(void); | |||
568 | static void draw_spectrogram_vertical(void); | 559 | static void draw_spectrogram_vertical(void); |
569 | static void draw_spectrogram_horizontal(void); | 560 | static void draw_spectrogram_horizontal(void); |
570 | 561 | ||
562 | #define COLOR_DEFAULT_FG MYLCD_DEFAULT_FG | ||
563 | #define COLOR_DEFAULT_BG MYLCD_DEFAULT_BG | ||
564 | |||
571 | #ifdef HAVE_LCD_COLOR | 565 | #ifdef HAVE_LCD_COLOR |
572 | #define COLOR_DEFAULT_FG LCD_DEFAULT_FG | ||
573 | #define COLOR_DEFAULT_BG LCD_DEFAULT_BG | ||
574 | #define COLOR_MESSAGE_FRAME LCD_RGBPACK(0xc6, 0x00, 0x00) | 566 | #define COLOR_MESSAGE_FRAME LCD_RGBPACK(0xc6, 0x00, 0x00) |
575 | #define COLOR_MESSAGE_BG LCD_BLACK | 567 | #define COLOR_MESSAGE_BG LCD_BLACK |
576 | #define COLOR_MESSAGE_FG LCD_WHITE | 568 | #define COLOR_MESSAGE_FG LCD_WHITE |
577 | #else | 569 | #else |
578 | #define COLOR_DEFAULT_FG GREY_BLACK | ||
579 | #define COLOR_DEFAULT_BG GREY_WHITE | ||
580 | #define COLOR_MESSAGE_FRAME GREY_DARKGRAY | 570 | #define COLOR_MESSAGE_FRAME GREY_DARKGRAY |
581 | #define COLOR_MESSAGE_BG GREY_WHITE | 571 | #define COLOR_MESSAGE_BG GREY_WHITE |
582 | #define COLOR_MESSAGE_FG GREY_BLACK | 572 | #define COLOR_MESSAGE_FG GREY_BLACK |
@@ -588,7 +578,7 @@ static void draw_spectrogram_horizontal(void); | |||
588 | static void draw_message_string(const unsigned char *message, bool active) | 578 | static void draw_message_string(const unsigned char *message, bool active) |
589 | { | 579 | { |
590 | int x, y; | 580 | int x, y; |
591 | lcd_(getstringsize)(message, &x, &y); | 581 | mylcd_getstringsize(message, &x, &y); |
592 | 582 | ||
593 | /* x and y give the size of the box for the popup */ | 583 | /* x and y give the size of the box for the popup */ |
594 | x += POPUP_HPADDING*2; | 584 | x += POPUP_HPADDING*2; |
@@ -601,20 +591,20 @@ static void draw_message_string(const unsigned char *message, bool active) | |||
601 | graph_settings.orientation_vertical && | 591 | graph_settings.orientation_vertical && |
602 | graph_settings.spectrogram_pos >= LCD_WIDTH - x) | 592 | graph_settings.spectrogram_pos >= LCD_WIDTH - x) |
603 | { | 593 | { |
604 | lcd_scroll_left(graph_settings.spectrogram_pos - | 594 | mylcd_scroll_left(graph_settings.spectrogram_pos - |
605 | LCD_WIDTH + x); | 595 | LCD_WIDTH + x); |
606 | graph_settings.spectrogram_pos = LCD_WIDTH - x - 1; | 596 | graph_settings.spectrogram_pos = LCD_WIDTH - x - 1; |
607 | } | 597 | } |
608 | 598 | ||
609 | lcd_(set_foreground)(COLOR_MESSAGE_FRAME); | 599 | mylcd_set_foreground(COLOR_MESSAGE_FRAME); |
610 | lcd_(fillrect)(LCD_WIDTH - x, 0, LCD_WIDTH - 1, y); | 600 | mylcd_fillrect(LCD_WIDTH - x, 0, LCD_WIDTH - 1, y); |
611 | 601 | ||
612 | lcd_(set_foreground)(COLOR_MESSAGE_FG); | 602 | mylcd_set_foreground(COLOR_MESSAGE_FG); |
613 | lcd_(set_background)(COLOR_MESSAGE_BG); | 603 | mylcd_set_background(COLOR_MESSAGE_BG); |
614 | lcd_(putsxy)(LCD_WIDTH - x + POPUP_HPADDING, | 604 | mylcd_putsxy(LCD_WIDTH - x + POPUP_HPADDING, |
615 | POPUP_VPADDING, message); | 605 | POPUP_VPADDING, message); |
616 | lcd_(set_foreground)(COLOR_DEFAULT_FG); | 606 | mylcd_set_foreground(COLOR_DEFAULT_FG); |
617 | lcd_(set_background)(COLOR_DEFAULT_BG); | 607 | mylcd_set_background(COLOR_DEFAULT_BG); |
618 | } | 608 | } |
619 | 609 | ||
620 | static void draw(const unsigned char* message) | 610 | static void draw(const unsigned char* message) |
@@ -647,15 +637,15 @@ static void draw(const unsigned char* message) | |||
647 | if(graph_settings.changed.freq_scale) | 637 | if(graph_settings.changed.freq_scale) |
648 | graph_settings.changed.freq_scale = true; | 638 | graph_settings.changed.freq_scale = true; |
649 | 639 | ||
650 | lcd_(set_foreground)(COLOR_DEFAULT_FG); | 640 | mylcd_set_foreground(COLOR_DEFAULT_FG); |
651 | lcd_(set_background)(COLOR_DEFAULT_BG); | 641 | mylcd_set_background(COLOR_DEFAULT_BG); |
652 | 642 | ||
653 | switch (graph_settings.mode) | 643 | switch (graph_settings.mode) |
654 | { | 644 | { |
655 | default: | 645 | default: |
656 | case FFT_DM_LINES: { | 646 | case FFT_DM_LINES: { |
657 | 647 | ||
658 | lcd_(clear_display)(); | 648 | mylcd_clear_display(); |
659 | 649 | ||
660 | if (graph_settings.orientation_vertical) | 650 | if (graph_settings.orientation_vertical) |
661 | draw_lines_vertical(); | 651 | draw_lines_vertical(); |
@@ -665,7 +655,7 @@ static void draw(const unsigned char* message) | |||
665 | } | 655 | } |
666 | case FFT_DM_BARS: { | 656 | case FFT_DM_BARS: { |
667 | 657 | ||
668 | lcd_(clear_display()); | 658 | mylcd_clear_display(); |
669 | 659 | ||
670 | if(graph_settings.orientation_vertical) | 660 | if(graph_settings.orientation_vertical) |
671 | draw_bars_vertical(); | 661 | draw_bars_vertical(); |
@@ -679,7 +669,7 @@ static void draw(const unsigned char* message) | |||
679 | if(graph_settings.changed.do_clear) | 669 | if(graph_settings.changed.do_clear) |
680 | { | 670 | { |
681 | graph_settings.spectrogram_pos = 0; | 671 | graph_settings.spectrogram_pos = 0; |
682 | lcd_(clear_display)(); | 672 | mylcd_clear_display(); |
683 | } | 673 | } |
684 | 674 | ||
685 | if(graph_settings.orientation_vertical) | 675 | if(graph_settings.orientation_vertical) |
@@ -709,7 +699,7 @@ static void draw(const unsigned char* message) | |||
709 | { | 699 | { |
710 | /* Spectrogram mode - need to erase the popup */ | 700 | /* Spectrogram mode - need to erase the popup */ |
711 | int x, y; | 701 | int x, y; |
712 | lcd_(getstringsize)(last_message, &x, &y); | 702 | mylcd_getstringsize(last_message, &x, &y); |
713 | /* Recalculate the size */ | 703 | /* Recalculate the size */ |
714 | x += POPUP_HPADDING*2; | 704 | x += POPUP_HPADDING*2; |
715 | y += POPUP_VPADDING*2; | 705 | y += POPUP_VPADDING*2; |
@@ -717,7 +707,7 @@ static void draw(const unsigned char* message) | |||
717 | if(!graph_settings.orientation_vertical) | 707 | if(!graph_settings.orientation_vertical) |
718 | { | 708 | { |
719 | /* In horizontal spectrogram mode, just scroll up by Y lines */ | 709 | /* In horizontal spectrogram mode, just scroll up by Y lines */ |
720 | lcd_scroll_up(y); | 710 | mylcd_scroll_up(y); |
721 | graph_settings.spectrogram_pos -= y; | 711 | graph_settings.spectrogram_pos -= y; |
722 | if(graph_settings.spectrogram_pos < 0) | 712 | if(graph_settings.spectrogram_pos < 0) |
723 | graph_settings.spectrogram_pos = 0; | 713 | graph_settings.spectrogram_pos = 0; |
@@ -725,10 +715,10 @@ static void draw(const unsigned char* message) | |||
725 | else | 715 | else |
726 | { | 716 | { |
727 | /* In vertical spectrogram mode, erase the popup */ | 717 | /* In vertical spectrogram mode, erase the popup */ |
728 | lcd_(set_foreground)(COLOR_DEFAULT_BG); | 718 | mylcd_set_foreground(COLOR_DEFAULT_BG); |
729 | lcd_(fillrect)(graph_settings.spectrogram_pos + 1, 0, | 719 | mylcd_fillrect(graph_settings.spectrogram_pos + 1, 0, |
730 | LCD_WIDTH, y); | 720 | LCD_WIDTH, y); |
731 | lcd_(set_foreground)(COLOR_DEFAULT_FG); | 721 | mylcd_set_foreground(COLOR_DEFAULT_FG); |
732 | } | 722 | } |
733 | } | 723 | } |
734 | /* else These modes clear the screen themselves */ | 724 | /* else These modes clear the screen themselves */ |
@@ -736,7 +726,7 @@ static void draw(const unsigned char* message) | |||
736 | last_message = NULL; | 726 | last_message = NULL; |
737 | } | 727 | } |
738 | 728 | ||
739 | lcd_(update)(); | 729 | mylcd_update(); |
740 | 730 | ||
741 | graph_settings.changed.clear_all = false; | 731 | graph_settings.changed.clear_all = false; |
742 | } | 732 | } |
@@ -763,7 +753,7 @@ static void draw_lines_vertical(void) | |||
763 | 753 | ||
764 | if(this_max == 0) | 754 | if(this_max == 0) |
765 | { | 755 | { |
766 | lcd_(hline)(0, LCD_WIDTH - 1, LCD_HEIGHT - 1); /* Draw all "zero" */ | 756 | mylcd_hline(0, LCD_WIDTH - 1, LCD_HEIGHT - 1); /* Draw all "zero" */ |
767 | return; | 757 | return; |
768 | } | 758 | } |
769 | 759 | ||
@@ -812,7 +802,7 @@ static void draw_lines_vertical(void) | |||
812 | for(x = 0; x < plotwidth; ++x) | 802 | for(x = 0; x < plotwidth; ++x) |
813 | { | 803 | { |
814 | int h = LCD_HEIGHT*plot[x] / max; | 804 | int h = LCD_HEIGHT*plot[x] / max; |
815 | lcd_(vline)(x + offset, LCD_HEIGHT - h, LCD_HEIGHT-1); | 805 | mylcd_vline(x + offset, LCD_HEIGHT - h, LCD_HEIGHT-1); |
816 | } | 806 | } |
817 | } | 807 | } |
818 | 808 | ||
@@ -838,7 +828,7 @@ static void draw_lines_horizontal(void) | |||
838 | 828 | ||
839 | if(this_max == 0) | 829 | if(this_max == 0) |
840 | { | 830 | { |
841 | lcd_(vline)(0, 0, LCD_HEIGHT-1); /* Draw all "zero" */ | 831 | mylcd_vline(0, 0, LCD_HEIGHT-1); /* Draw all "zero" */ |
842 | return; | 832 | return; |
843 | } | 833 | } |
844 | 834 | ||
@@ -888,7 +878,7 @@ static void draw_lines_horizontal(void) | |||
888 | for(y = 0; y < plotwidth; ++y) | 878 | for(y = 0; y < plotwidth; ++y) |
889 | { | 879 | { |
890 | int w = LCD_WIDTH*plot[y] / max; | 880 | int w = LCD_WIDTH*plot[y] / max; |
891 | lcd_(hline)(0, w - 1, y + offset); | 881 | mylcd_hline(0, w - 1, y + offset); |
892 | } | 882 | } |
893 | } | 883 | } |
894 | 884 | ||
@@ -909,7 +899,7 @@ static void draw_bars_vertical(void) | |||
909 | if(graph_settings.changed.amp_scale) | 899 | if(graph_settings.changed.amp_scale) |
910 | max = 0; /* reset the graph on scaling mode change */ | 900 | max = 0; /* reset the graph on scaling mode change */ |
911 | 901 | ||
912 | lcd_(hline)(0, LCD_WIDTH-1, LCD_HEIGHT-1); /* Draw baseline */ | 902 | mylcd_hline(0, LCD_WIDTH-1, LCD_HEIGHT-1); /* Draw baseline */ |
913 | 903 | ||
914 | if(calc_magnitudes(graph_settings.logarithmic_amp) == 0) | 904 | if(calc_magnitudes(graph_settings.logarithmic_amp) == 0) |
915 | return; /* nothing more to draw */ | 905 | return; /* nothing more to draw */ |
@@ -948,7 +938,7 @@ static void draw_bars_vertical(void) | |||
948 | for(i = 0, x = offset; i < bars; ++i, x += barwidth) | 938 | for(i = 0, x = offset; i < bars; ++i, x += barwidth) |
949 | { | 939 | { |
950 | int h = LCD_HEIGHT * plot[i] / max; | 940 | int h = LCD_HEIGHT * plot[i] / max; |
951 | lcd_(fillrect)(x, LCD_HEIGHT - h, width, h - 1); | 941 | mylcd_fillrect(x, LCD_HEIGHT - h, width, h - 1); |
952 | } | 942 | } |
953 | } | 943 | } |
954 | 944 | ||
@@ -969,7 +959,7 @@ static void draw_bars_horizontal(void) | |||
969 | if(graph_settings.changed.amp_scale) | 959 | if(graph_settings.changed.amp_scale) |
970 | max = 0; /* reset the graph on scaling mode change */ | 960 | max = 0; /* reset the graph on scaling mode change */ |
971 | 961 | ||
972 | lcd_(vline)(0, 0, LCD_HEIGHT-1); /* Draw baseline */ | 962 | mylcd_vline(0, 0, LCD_HEIGHT-1); /* Draw baseline */ |
973 | 963 | ||
974 | if(calc_magnitudes(graph_settings.logarithmic_amp) == 0) | 964 | if(calc_magnitudes(graph_settings.logarithmic_amp) == 0) |
975 | return; /* nothing more to draw */ | 965 | return; /* nothing more to draw */ |
@@ -1008,7 +998,7 @@ static void draw_bars_horizontal(void) | |||
1008 | for(i = 0, y = offset; i < bars; ++i, y += barwidth) | 998 | for(i = 0, y = offset; i < bars; ++i, y += barwidth) |
1009 | { | 999 | { |
1010 | int w = LCD_WIDTH * plot[i] / max; | 1000 | int w = LCD_WIDTH * plot[i] / max; |
1011 | lcd_(fillrect)(1, y, w, height); | 1001 | mylcd_fillrect(1, y, w, height); |
1012 | } | 1002 | } |
1013 | } | 1003 | } |
1014 | 1004 | ||
@@ -1048,8 +1038,8 @@ static void draw_spectrogram_vertical(void) | |||
1048 | if(index >= SHADES) | 1038 | if(index >= SHADES) |
1049 | index = SHADES-1; | 1039 | index = SHADES-1; |
1050 | 1040 | ||
1051 | lcd_(set_foreground)(SPECTROGRAPH_PALETTE(index)); | 1041 | mylcd_set_foreground(SPECTROGRAPH_PALETTE(index)); |
1052 | lcd_(drawpixel)(graph_settings.spectrogram_pos, | 1042 | mylcd_drawpixel(graph_settings.spectrogram_pos, |
1053 | scale_factor-1 - y); | 1043 | scale_factor-1 - y); |
1054 | 1044 | ||
1055 | if(++y >= scale_factor) | 1045 | if(++y >= scale_factor) |
@@ -1063,7 +1053,7 @@ static void draw_spectrogram_vertical(void) | |||
1063 | if(graph_settings.spectrogram_pos < LCD_WIDTH-1) | 1053 | if(graph_settings.spectrogram_pos < LCD_WIDTH-1) |
1064 | graph_settings.spectrogram_pos++; | 1054 | graph_settings.spectrogram_pos++; |
1065 | else | 1055 | else |
1066 | lcd_scroll_left(1); | 1056 | mylcd_scroll_left(1); |
1067 | } | 1057 | } |
1068 | 1058 | ||
1069 | static void draw_spectrogram_horizontal(void) | 1059 | static void draw_spectrogram_horizontal(void) |
@@ -1102,8 +1092,8 @@ static void draw_spectrogram_horizontal(void) | |||
1102 | if(index >= SHADES) | 1092 | if(index >= SHADES) |
1103 | index = SHADES-1; | 1093 | index = SHADES-1; |
1104 | 1094 | ||
1105 | lcd_(set_foreground)(SPECTROGRAPH_PALETTE(index)); | 1095 | mylcd_set_foreground(SPECTROGRAPH_PALETTE(index)); |
1106 | lcd_(drawpixel)(x, graph_settings.spectrogram_pos); | 1096 | mylcd_drawpixel(x, graph_settings.spectrogram_pos); |
1107 | 1097 | ||
1108 | if(++x >= scale_factor) | 1098 | if(++x >= scale_factor) |
1109 | break; | 1099 | break; |
@@ -1116,7 +1106,7 @@ static void draw_spectrogram_horizontal(void) | |||
1116 | if(graph_settings.spectrogram_pos < LCD_HEIGHT-1) | 1106 | if(graph_settings.spectrogram_pos < LCD_HEIGHT-1) |
1117 | graph_settings.spectrogram_pos++; | 1107 | graph_settings.spectrogram_pos++; |
1118 | else | 1108 | else |
1119 | lcd_scroll_up(1); | 1109 | mylcd_scroll_up(1); |
1120 | } | 1110 | } |
1121 | 1111 | ||
1122 | /********************* End of plotting functions (modes) *********************/ | 1112 | /********************* End of plotting functions (modes) *********************/ |
@@ -1334,8 +1324,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
1334 | 1324 | ||
1335 | #if LCD_DEPTH > 1 | 1325 | #if LCD_DEPTH > 1 |
1336 | rb->lcd_set_backdrop(NULL); | 1326 | rb->lcd_set_backdrop(NULL); |
1337 | lcd_(clear_display)(); | 1327 | mylcd_clear_display(); |
1338 | lcd_(update)(); | 1328 | mylcd_update(); |
1339 | #endif | 1329 | #endif |
1340 | backlight_force_on(); | 1330 | backlight_force_on(); |
1341 | 1331 | ||
@@ -1357,9 +1347,9 @@ enum plugin_status plugin_start(const void* parameter) | |||
1357 | if(!rb->pcm_is_playing()) | 1347 | if(!rb->pcm_is_playing()) |
1358 | { | 1348 | { |
1359 | showing_warning = true; | 1349 | showing_warning = true; |
1360 | lcd_(clear_display)(); | 1350 | mylcd_clear_display(); |
1361 | draw_message_string("No audio playing", false); | 1351 | draw_message_string("No audio playing", false); |
1362 | lcd_(update)(); | 1352 | mylcd_update(); |
1363 | timeout = HZ/5; | 1353 | timeout = HZ/5; |
1364 | } | 1354 | } |
1365 | else | 1355 | else |
@@ -1367,8 +1357,8 @@ enum plugin_status plugin_start(const void* parameter) | |||
1367 | if(showing_warning) | 1357 | if(showing_warning) |
1368 | { | 1358 | { |
1369 | showing_warning = false; | 1359 | showing_warning = false; |
1370 | lcd_(clear_display)(); | 1360 | mylcd_clear_display(); |
1371 | lcd_(update)(); | 1361 | mylcd_update(); |
1372 | } | 1362 | } |
1373 | 1363 | ||
1374 | timeout = HZ/100; /* 'till end of curent tick, don't use 100% CPU */ | 1364 | timeout = HZ/100; /* 'till end of curent tick, don't use 100% CPU */ |