summaryrefslogtreecommitdiff
path: root/apps/recorder/peakmeter.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder/peakmeter.c')
-rw-r--r--apps/recorder/peakmeter.c121
1 files changed, 117 insertions, 4 deletions
diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c
index ca1b8c8750..c13c4c9539 100644
--- a/apps/recorder/peakmeter.c
+++ b/apps/recorder/peakmeter.c
@@ -28,6 +28,7 @@
28#include "storage.h" 28#include "storage.h"
29#include "lcd.h" 29#include "lcd.h"
30#include "scrollbar.h" 30#include "scrollbar.h"
31#include "string.h"
31#include "button.h" 32#include "button.h"
32#include "system.h" 33#include "system.h"
33#include "font.h" 34#include "font.h"
@@ -64,9 +65,10 @@ static int pm_cur_left; /* current values (last peak_meter_peek) */
64static int pm_cur_right; 65static int pm_cur_right;
65static int pm_max_left; /* maximum values between peak meter draws */ 66static int pm_max_left; /* maximum values between peak meter draws */
66static int pm_max_right; 67static int pm_max_right;
67#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM) 68#if defined(HAVE_AGC) || defined(HAVE_HISTOGRAM)
68static int pm_peakhold_left; /* max. peak values between peakhold calls */ 69static int pm_peakhold_left; /* max. peak values between peakhold calls */
69static int pm_peakhold_right; /* used for AGC and histogram display */ 70static int pm_peakhold_right; /* used for AGC and histogram display */
71static long next_histogram_update;
70#endif 72#endif
71 73
72/* Clip hold */ 74/* Clip hold */
@@ -134,6 +136,38 @@ static unsigned int peeks_per_redraw[PEEKS_PER_DRAW_SIZE];
134static unsigned int ticks_per_redraw[TICKS_PER_DRAW_SIZE]; 136static unsigned int ticks_per_redraw[TICKS_PER_DRAW_SIZE];
135#endif 137#endif
136 138
139#if defined(HAVE_HISTOGRAM)
140#define HIST_BUF_SIZE (LCD_WIDTH / 2)
141static int hist_l = 0;
142static int hist_r = 0;
143static unsigned char history_l[HIST_BUF_SIZE];
144static unsigned char history_r[HIST_BUF_SIZE];
145static const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
146static int history_pos = 0;
147#define HIST_W (LCD_WIDTH / 2)
148#if LCD_DEPTH > 1
149#ifdef HAVE_LCD_COLOR
150#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
151#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
152#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
153#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
154#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
155#else /* HAVE_LCD_COLOR */
156#define LCD_BATT_OK LCD_BLACK
157#define LCD_BATT_LO LCD_DARKGRAY
158#define LCD_DISK_OK LCD_BLACK
159#define LCD_DISK_LO LCD_DARKGRAY
160#define LCD_HIST_OVER LCD_BLACK
161#define LCD_HIST_OK LCD_DARKGRAY
162#define LCD_BAL LCD_DARKGRAY
163#endif /* HAVE_LCD_COLOR */
164#else /* LCD_DEPTH > 1 */
165#define LCD_HIST_OVER LCD_DEFAULT_FG
166#define LCD_HIST_OK LCD_DEFAULT_FG
167#define LCD_BAL LCD_DEFAULT_FG
168#endif /* LCD_DEPTH > 1 */
169#endif /* HAVE_HISTOGRAM */
170
137static void peak_meter_draw(struct screen *display, struct meter_scales *meter_scales, 171static void peak_meter_draw(struct screen *display, struct meter_scales *meter_scales,
138 int x, int y, int width, int height); 172 int x, int y, int width, int height);
139 173
@@ -810,7 +844,7 @@ static int peak_meter_read_l(void)
810 844
811 retval = pm_max_left; 845 retval = pm_max_left;
812 846
813#if defined(HAVE_RECORDING_HISTOGRAM) || defined(HAVE_AGC) 847#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
814 /* store max peak value for peak_meter_get_peakhold_x readout */ 848 /* store max peak value for peak_meter_get_peakhold_x readout */
815 pm_peakhold_left = MAX(pm_max_left, pm_peakhold_left); 849 pm_peakhold_left = MAX(pm_max_left, pm_peakhold_left);
816#endif 850#endif
@@ -843,7 +877,7 @@ static int peak_meter_read_r(void)
843 877
844 retval = pm_max_right; 878 retval = pm_max_right;
845 879
846#if defined(HAVE_RECORDING_HISTOGRAM) || defined(HAVE_AGC) 880#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
847 /* store max peak value for peak_meter_get_peakhold_x readout */ 881 /* store max peak value for peak_meter_get_peakhold_x readout */
848 pm_peakhold_right = MAX(pm_max_right, pm_peakhold_right); 882 pm_peakhold_right = MAX(pm_max_right, pm_peakhold_right);
849#endif 883#endif
@@ -857,7 +891,7 @@ static int peak_meter_read_r(void)
857 return retval; 891 return retval;
858} 892}
859 893
860#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM) 894#if defined(HAVE_AGC) || defined(HAVE_HISTOGRAM)
861/** 895/**
862 * Reads out the current peak-hold values since the last call. 896 * Reads out the current peak-hold values since the last call.
863 * This is used by the histogram feature in the recording screen. 897 * This is used by the histogram feature in the recording screen.
@@ -869,6 +903,14 @@ void peak_meter_get_peakhold(int *peak_left, int *peak_right)
869 *peak_left = pm_peakhold_left; 903 *peak_left = pm_peakhold_left;
870 if (peak_right) 904 if (peak_right)
871 *peak_right = pm_peakhold_right; 905 *peak_right = pm_peakhold_right;
906
907#ifdef HAVE_HISTOGRAM
908 if (*peak_left > hist_l)
909 hist_l = *peak_left;
910 if (*peak_right > hist_r)
911 hist_r = *peak_right;
912#endif
913
872 pm_peakhold_left = 0; 914 pm_peakhold_left = 0;
873 pm_peakhold_right = 0; 915 pm_peakhold_right = 0;
874} 916}
@@ -1447,4 +1489,75 @@ bool peak_meter_histogram(void)
1447} 1489}
1448#endif 1490#endif
1449 1491
1492#ifdef HAVE_HISTOGRAM
1493void histogram_init()
1494{
1495 /* get update interval, clear buffer, reset drawing position */
1496 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1497 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1498 next_histogram_update = current_tick +
1499 (global_settings.histogram_interval * HZ);
1500}
1501
1502void histogram_draw(int x1, int x2, int y1, int y2, int width, int height)
1503{
1504 int i, j;
1505 if (current_tick >= next_histogram_update)
1506 {
1507 /* fill history buffer */
1508 history_l[history_pos] = hist_l * height / 32767;
1509 history_r[history_pos] = hist_r * height / 32767;
1510 history_pos = (history_pos + 1) % HIST_BUF_SIZE;
1511 history_l[history_pos] = history_r[history_pos] = 0;
1512 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1513 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1514 hist_l = 0;
1515 hist_r = 0;
1516 next_histogram_update = current_tick +
1517 (global_settings.histogram_interval * HZ);
1518 }
1519 lcd_set_drawmode(DRMODE_SOLID);
1520 lcd_drawrect(x1, y1, width, height);
1521 lcd_drawrect(x2, y2, width, height);
1522 lcd_set_drawmode(DRMODE_FG);
1523
1524 j = history_pos;
1525 for (i = width-2; i >= 0; i--)
1526 {
1527 j--;
1528 if(j<0)
1529 j = HIST_BUF_SIZE-1;
1530 if (history_l[j])
1531 {
1532 if (history_l[j] == height)
1533 lcd_set_foreground(LCD_HIST_OVER);
1534#ifdef HAVE_LCD_COLOR
1535 else if (history_l[j] > hist_level_marks[1])
1536 lcd_set_foreground(LCD_HIST_HI);
1537#endif
1538 else
1539 lcd_set_foreground(LCD_HIST_OK);
1540 lcd_vline(x1 + i, y1 + height - 2, y1 + height - history_l[j]);
1541 }
1542 if (history_r[j])
1543 {
1544 if (history_r[j] == height)
1545 lcd_set_foreground(LCD_HIST_OVER);
1546#ifdef HAVE_LCD_COLOR
1547 else if (history_r[j] > hist_level_marks[1])
1548 lcd_set_foreground(LCD_HIST_HI);
1549#endif
1550 else
1551 lcd_set_foreground(LCD_HIST_OK);
1552 lcd_vline(x2 + i, y2 + height - 2, y2 + height - history_r[j]);
1553 }
1554 }
1555 lcd_set_foreground(
1556#ifdef HAVE_LCD_COLOR
1557 global_settings.fg_color);
1558#else
1559 LCD_DEFAULT_FG);
1560#endif
1561}
1562#endif /* HAVE_HISTOGRAM */
1450 1563