summaryrefslogtreecommitdiff
path: root/apps/recorder
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2011-06-05 12:36:27 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2011-06-05 12:36:27 +0000
commit82f4c60db4f16642c1ee9f461d7eb060c11a49d8 (patch)
treea7a75d4e57941ebd1b5b15b051a28d1d4751964e /apps/recorder
parent62e06cc2a432bb9499646f089796157135829195 (diff)
downloadrockbox-82f4c60db4f16642c1ee9f461d7eb060c11a49d8.tar.gz
rockbox-82f4c60db4f16642c1ee9f461d7eb060c11a49d8.zip
Make the histogram code usable for playback as well. Move the recording histogram code to peakmeter, rename it to remove the recording reference, and rename anything referring to it as well. Change the drawing code so there are more options to position them. This may change your histogram settings, so check after upgrading.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29969 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/recorder')
-rw-r--r--apps/recorder/peakmeter.c121
-rw-r--r--apps/recorder/peakmeter.h6
-rw-r--r--apps/recorder/recording.c132
3 files changed, 139 insertions, 120 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
diff --git a/apps/recorder/peakmeter.h b/apps/recorder/peakmeter.h
index fee4882679..6be43a5f3a 100644
--- a/apps/recorder/peakmeter.h
+++ b/apps/recorder/peakmeter.h
@@ -56,6 +56,11 @@ extern int calc_db (int isample);
56extern int peak_meter_db2sample(int db); 56extern int peak_meter_db2sample(int db);
57extern unsigned short peak_meter_scale_value(unsigned short val, int meterwidth); 57extern unsigned short peak_meter_scale_value(unsigned short val, int meterwidth);
58 58
59#ifdef HAVE_HISTOGRAM
60extern void histogram_init(void);
61extern void histogram_draw(int x1, int x2, int y1, int y2, int width, int height);
62#endif
63
59/* valid values for trigger_status */ 64/* valid values for trigger_status */
60#define TRIG_OFF 0x00 65#define TRIG_OFF 0x00
61#define TRIG_READY 0x01 66#define TRIG_READY 0x01
@@ -103,3 +108,4 @@ struct meter_scales{
103 108
104extern void peak_meter_screen(struct screen *display, int x, int y, int height); 109extern void peak_meter_screen(struct screen *display, int x, int y, int height);
105#endif /* __PEAKMETER_H__ */ 110#endif /* __PEAKMETER_H__ */
111
diff --git a/apps/recorder/recording.c b/apps/recorder/recording.c
index 34283b6cb5..6faaa6c48c 100644
--- a/apps/recorder/recording.c
+++ b/apps/recorder/recording.c
@@ -269,39 +269,9 @@ static short agc_baltime = 0;
269/* AGC maximum gain */ 269/* AGC maximum gain */
270static short agc_maxgain; 270static short agc_maxgain;
271#endif /* HAVE_AGC */ 271#endif /* HAVE_AGC */
272#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM) 272#if defined(HAVE_AGC)
273static long hist_time = 0; 273static long hist_time = 0;
274#endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */ 274#endif /* HAVE_AGC */
275/* Histogram data */
276/* TO DO: move some of this stuff inside the recording function? */
277#ifdef HAVE_RECORDING_HISTOGRAM
278static int hist_l = 0;
279static int hist_r = 0;
280#define HIST_BUF_SIZE (LCD_WIDTH)
281#define HIST_Y (hist_pos_y+hist_size_h-1)
282#define HIST_W (LCD_WIDTH / 2 - 4)
283#if LCD_DEPTH > 1
284#ifdef HAVE_LCD_COLOR
285#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
286#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
287#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
288#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
289#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
290#else /* HAVE_LCD_COLOR */
291#define LCD_BATT_OK LCD_BLACK
292#define LCD_BATT_LO LCD_DARKGRAY
293#define LCD_DISK_OK LCD_BLACK
294#define LCD_DISK_LO LCD_DARKGRAY
295#define LCD_HIST_OVER LCD_BLACK
296#define LCD_HIST_OK LCD_DARKGRAY
297#define LCD_BAL LCD_DARKGRAY
298#endif /* HAVE_LCD_COLOR */
299#else /* LCD_DEPTH > 1 */
300#define LCD_HIST_OVER LCD_DEFAULT_FG
301#define LCD_HIST_OK LCD_DEFAULT_FG
302#define LCD_BAL LCD_DEFAULT_FG
303#endif /* LCD_DEPTH > 1 */
304#endif /* HAVE_RECORDING_HISTOGRAM */
305 275
306static void set_gain(void) 276static void set_gain(void)
307{ 277{
@@ -368,13 +338,6 @@ static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
368 *balance += balance_mem[i]; 338 *balance += balance_mem[i];
369 *balance = *balance / BAL_MEM_SIZE; 339 *balance = *balance / BAL_MEM_SIZE;
370 340
371#ifdef HAVE_RECORDING_HISTOGRAM
372 if (*peak_l > hist_l)
373 hist_l = *peak_l;
374 if (*peak_r > hist_r)
375 hist_r = *peak_r;
376#endif
377
378 return true; 341 return true;
379} 342}
380 343
@@ -1089,18 +1052,12 @@ bool recording_screen(bool no_source)
1089 /* tweak layout tiny screens / big fonts */ 1052 /* tweak layout tiny screens / big fonts */
1090 bool compact_view[NB_SCREENS] = { false }; 1053 bool compact_view[NB_SCREENS] = { false };
1091 struct gui_synclist lists; /* the list in the bottom vp */ 1054 struct gui_synclist lists; /* the list in the bottom vp */
1092#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM) 1055#if defined(HAVE_AGC)
1093 bool peak_valid = false; 1056 bool peak_valid = false;
1094#endif 1057#endif
1095#if defined(HAVE_RECORDING_HISTOGRAM) 1058#if defined(HAVE_HISTOGRAM)
1096 int j;
1097 unsigned short hist_pos_y = 0; 1059 unsigned short hist_pos_y = 0;
1098 unsigned short hist_size_h = 0; 1060 unsigned short hist_size_h = 0;
1099 int history_pos = 0;
1100 short hist_time_interval = 1; /* 1, 2, 4, 8 */
1101 unsigned char history_l[HIST_BUF_SIZE];
1102 unsigned char history_r[HIST_BUF_SIZE];
1103 const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
1104#endif 1061#endif
1105#ifdef HAVE_FMRADIO_REC 1062#ifdef HAVE_FMRADIO_REC
1106 int prev_rec_source = global_settings.rec_source; /* detect source change */ 1063 int prev_rec_source = global_settings.rec_source; /* detect source change */
@@ -1186,10 +1143,9 @@ bool recording_screen(bool no_source)
1186 /* top vp, 4 lines, force sys font if total screen < 6 lines 1143 /* top vp, 4 lines, force sys font if total screen < 6 lines
1187 NOTE: one could limit the list to 1 line and get away with 5 lines */ 1144 NOTE: one could limit the list to 1 line and get away with 5 lines */
1188 top_height_req[i] = 4; 1145 top_height_req[i] = 4;
1189#if defined(HAVE_RECORDING_HISTOGRAM) 1146#if defined(HAVE_HISTOGRAM)
1190 if((global_settings.rec_histogram_interval) && (!i)) 1147 if((global_settings.histogram_interval) && (!i))
1191 top_height_req[i] += 1; /* use one line for histogram */ 1148 top_height_req[i] += 1; /* use one line for histogram */
1192 hist_time_interval = 1 << global_settings.rec_histogram_interval;
1193#endif 1149#endif
1194 v = &vp_top[i]; 1150 v = &vp_top[i];
1195 viewport_set_defaults(v, i); 1151 viewport_set_defaults(v, i);
@@ -1229,13 +1185,11 @@ bool recording_screen(bool no_source)
1229 1185
1230 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */ 1186 send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
1231 1187
1232#if defined(HAVE_RECORDING_HISTOGRAM) 1188#if defined(HAVE_HISTOGRAM)
1233 history_pos = 0;
1234 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height) 1189 hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
1235 + 1; 1190 + 1;
1236 hist_size_h = font_get(vp_top[0].font)->height - 2; 1191 hist_size_h = font_get(vp_top[0].font)->height - 2;
1237 memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE); 1192 histogram_init();
1238 memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
1239#endif 1193#endif
1240 1194
1241 FOR_NB_SCREENS(i) 1195 FOR_NB_SCREENS(i)
@@ -1887,75 +1841,21 @@ bool recording_screen(bool no_source)
1887 } 1841 }
1888 } 1842 }
1889 1843
1890#ifdef HAVE_RECORDING_HISTOGRAM 1844#ifdef HAVE_HISTOGRAM
1891 if(global_settings.rec_histogram_interval) 1845 if(global_settings.histogram_interval)
1892 {
1893 if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
1894 { 1846 {
1895 /* fill history buffer */ 1847 histogram_draw(0,
1896 history_l[history_pos] = hist_l * hist_size_h / 32767; 1848 screens[0].getwidth()/2,
1897 history_r[history_pos] = hist_r * hist_size_h / 32767; 1849 hist_pos_y,
1898 history_pos = (history_pos + 1) % HIST_BUF_SIZE; 1850 hist_pos_y,
1899 history_l[history_pos] = history_r[history_pos] = 0; 1851 screens[0].getwidth()/2,
1900 history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0; 1852 hist_size_h);
1901 history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
1902 hist_l = 0;
1903 hist_r = 0;
1904 } 1853 }
1905 lcd_set_drawmode(DRMODE_SOLID);
1906 lcd_drawrect(0, hist_pos_y - 1,
1907 HIST_W + 2, hist_size_h + 1);
1908 lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
1909 HIST_W + 2, hist_size_h + 1);
1910 lcd_set_drawmode(DRMODE_FG);
1911
1912 j = history_pos;
1913 for (i = HIST_W-1; i >= 0; i--)
1914 {
1915 j--;
1916 if(j<0)
1917 j = HIST_BUF_SIZE-1;
1918 if (history_l[j])
1919 {
1920 if (history_l[j] == hist_size_h)
1921 lcd_set_foreground(LCD_HIST_OVER);
1922#ifdef HAVE_LCD_COLOR
1923 else if (history_l[j] > hist_level_marks[1])
1924 lcd_set_foreground(LCD_HIST_HI);
1925#endif 1854#endif
1926 else
1927 lcd_set_foreground(LCD_HIST_OK);
1928 lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
1929 }
1930 if (history_r[j])
1931 {
1932 if (history_r[j] == hist_size_h)
1933 lcd_set_foreground(LCD_HIST_OVER);
1934#ifdef HAVE_LCD_COLOR
1935 else if (history_r[j] > hist_level_marks[1])
1936 lcd_set_foreground(LCD_HIST_HI);
1937#endif
1938 else
1939 lcd_set_foreground(LCD_HIST_OK);
1940 lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
1941 }
1942 }
1943 lcd_set_foreground(
1944#ifdef HAVE_LCD_COLOR
1945 global_settings.fg_color);
1946#else
1947 LCD_DEFAULT_FG);
1948#endif
1949 for (i = 0; i < 6; i++)
1950 lcd_hline(HIST_W + 3, HIST_W + 4,
1951 HIST_Y - hist_level_marks[i]);
1952 }
1953#endif /* HAVE_RECORDING_HISTOGRAM */
1954 1855
1955#ifdef HAVE_AGC 1856#ifdef HAVE_AGC
1956 hist_time++; 1857 hist_time++;
1957#endif 1858#endif
1958
1959 /* draw the trigger status */ 1859 /* draw the trigger status */
1960 if (peak_meter_trigger_status() != TRIG_OFF) 1860 if (peak_meter_trigger_status() != TRIG_OFF)
1961 { 1861 {