summaryrefslogtreecommitdiffstats
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.tar.bz2
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 @@
#include "storage.h"
#include "lcd.h"
#include "scrollbar.h"
+#include "string.h"
#include "button.h"
#include "system.h"
#include "font.h"
@@ -64,9 +65,10 @@ static int pm_cur_left; /* current values (last peak_meter_peek) */
static int pm_cur_right;
static int pm_max_left; /* maximum values between peak meter draws */
static int pm_max_right;
-#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
+#if defined(HAVE_AGC) || defined(HAVE_HISTOGRAM)
static int pm_peakhold_left; /* max. peak values between peakhold calls */
static int pm_peakhold_right; /* used for AGC and histogram display */
+static long next_histogram_update;
#endif
/* Clip hold */
@@ -134,6 +136,38 @@ static unsigned int peeks_per_redraw[PEEKS_PER_DRAW_SIZE];
static unsigned int ticks_per_redraw[TICKS_PER_DRAW_SIZE];
#endif
+#if defined(HAVE_HISTOGRAM)
+#define HIST_BUF_SIZE (LCD_WIDTH / 2)
+static int hist_l = 0;
+static int hist_r = 0;
+static unsigned char history_l[HIST_BUF_SIZE];
+static unsigned char history_r[HIST_BUF_SIZE];
+static const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
+static int history_pos = 0;
+#define HIST_W (LCD_WIDTH / 2)
+#if LCD_DEPTH > 1
+#ifdef HAVE_LCD_COLOR
+#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
+#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
+#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
+#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
+#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
+#else /* HAVE_LCD_COLOR */
+#define LCD_BATT_OK LCD_BLACK
+#define LCD_BATT_LO LCD_DARKGRAY
+#define LCD_DISK_OK LCD_BLACK
+#define LCD_DISK_LO LCD_DARKGRAY
+#define LCD_HIST_OVER LCD_BLACK
+#define LCD_HIST_OK LCD_DARKGRAY
+#define LCD_BAL LCD_DARKGRAY
+#endif /* HAVE_LCD_COLOR */
+#else /* LCD_DEPTH > 1 */
+#define LCD_HIST_OVER LCD_DEFAULT_FG
+#define LCD_HIST_OK LCD_DEFAULT_FG
+#define LCD_BAL LCD_DEFAULT_FG
+#endif /* LCD_DEPTH > 1 */
+#endif /* HAVE_HISTOGRAM */
+
static void peak_meter_draw(struct screen *display, struct meter_scales *meter_scales,
int x, int y, int width, int height);
@@ -810,7 +844,7 @@ static int peak_meter_read_l(void)
retval = pm_max_left;
-#if defined(HAVE_RECORDING_HISTOGRAM) || defined(HAVE_AGC)
+#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
/* store max peak value for peak_meter_get_peakhold_x readout */
pm_peakhold_left = MAX(pm_max_left, pm_peakhold_left);
#endif
@@ -843,7 +877,7 @@ static int peak_meter_read_r(void)
retval = pm_max_right;
-#if defined(HAVE_RECORDING_HISTOGRAM) || defined(HAVE_AGC)
+#if defined(HAVE_HISTOGRAM) || defined(HAVE_AGC)
/* store max peak value for peak_meter_get_peakhold_x readout */
pm_peakhold_right = MAX(pm_max_right, pm_peakhold_right);
#endif
@@ -857,7 +891,7 @@ static int peak_meter_read_r(void)
return retval;
}
-#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
+#if defined(HAVE_AGC) || defined(HAVE_HISTOGRAM)
/**
* Reads out the current peak-hold values since the last call.
* 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)
*peak_left = pm_peakhold_left;
if (peak_right)
*peak_right = pm_peakhold_right;
+
+#ifdef HAVE_HISTOGRAM
+ if (*peak_left > hist_l)
+ hist_l = *peak_left;
+ if (*peak_right > hist_r)
+ hist_r = *peak_right;
+#endif
+
pm_peakhold_left = 0;
pm_peakhold_right = 0;
}
@@ -1447,4 +1489,75 @@ bool peak_meter_histogram(void)
}
#endif
+#ifdef HAVE_HISTOGRAM
+void histogram_init()
+{
+ /* get update interval, clear buffer, reset drawing position */
+ memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
+ memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
+ next_histogram_update = current_tick +
+ (global_settings.histogram_interval * HZ);
+}
+
+void histogram_draw(int x1, int x2, int y1, int y2, int width, int height)
+{
+ int i, j;
+ if (current_tick >= next_histogram_update)
+ {
+ /* fill history buffer */
+ history_l[history_pos] = hist_l * height / 32767;
+ history_r[history_pos] = hist_r * height / 32767;
+ history_pos = (history_pos + 1) % HIST_BUF_SIZE;
+ history_l[history_pos] = history_r[history_pos] = 0;
+ history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
+ history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
+ hist_l = 0;
+ hist_r = 0;
+ next_histogram_update = current_tick +
+ (global_settings.histogram_interval * HZ);
+ }
+ lcd_set_drawmode(DRMODE_SOLID);
+ lcd_drawrect(x1, y1, width, height);
+ lcd_drawrect(x2, y2, width, height);
+ lcd_set_drawmode(DRMODE_FG);
+
+ j = history_pos;
+ for (i = width-2; i >= 0; i--)
+ {
+ j--;
+ if(j<0)
+ j = HIST_BUF_SIZE-1;
+ if (history_l[j])
+ {
+ if (history_l[j] == height)
+ lcd_set_foreground(LCD_HIST_OVER);
+#ifdef HAVE_LCD_COLOR
+ else if (history_l[j] > hist_level_marks[1])
+ lcd_set_foreground(LCD_HIST_HI);
+#endif
+ else
+ lcd_set_foreground(LCD_HIST_OK);
+ lcd_vline(x1 + i, y1 + height - 2, y1 + height - history_l[j]);
+ }
+ if (history_r[j])
+ {
+ if (history_r[j] == height)
+ lcd_set_foreground(LCD_HIST_OVER);
+#ifdef HAVE_LCD_COLOR
+ else if (history_r[j] > hist_level_marks[1])
+ lcd_set_foreground(LCD_HIST_HI);
+#endif
+ else
+ lcd_set_foreground(LCD_HIST_OK);
+ lcd_vline(x2 + i, y2 + height - 2, y2 + height - history_r[j]);
+ }
+ }
+ lcd_set_foreground(
+#ifdef HAVE_LCD_COLOR
+ global_settings.fg_color);
+#else
+ LCD_DEFAULT_FG);
+#endif
+}
+#endif /* HAVE_HISTOGRAM */
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);
extern int peak_meter_db2sample(int db);
extern unsigned short peak_meter_scale_value(unsigned short val, int meterwidth);
+#ifdef HAVE_HISTOGRAM
+extern void histogram_init(void);
+extern void histogram_draw(int x1, int x2, int y1, int y2, int width, int height);
+#endif
+
/* valid values for trigger_status */
#define TRIG_OFF 0x00
#define TRIG_READY 0x01
@@ -103,3 +108,4 @@ struct meter_scales{
extern void peak_meter_screen(struct screen *display, int x, int y, int height);
#endif /* __PEAKMETER_H__ */
+
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;
/* AGC maximum gain */
static short agc_maxgain;
#endif /* HAVE_AGC */
-#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
+#if defined(HAVE_AGC)
static long hist_time = 0;
-#endif /* HAVE_AGC or HAVE_RECORDING_HISTOGRAM */
-/* Histogram data */
-/* TO DO: move some of this stuff inside the recording function? */
-#ifdef HAVE_RECORDING_HISTOGRAM
-static int hist_l = 0;
-static int hist_r = 0;
-#define HIST_BUF_SIZE (LCD_WIDTH)
-#define HIST_Y (hist_pos_y+hist_size_h-1)
-#define HIST_W (LCD_WIDTH / 2 - 4)
-#if LCD_DEPTH > 1
-#ifdef HAVE_LCD_COLOR
-#define LCD_BAL_L LCD_RGBPACK(0, 0, 255)
-#define LCD_BAL_R LCD_RGBPACK(204, 0, 0)
-#define LCD_HIST_OVER LCD_RGBPACK(204, 0, 0)
-#define LCD_HIST_HI LCD_RGBPACK(255, 204, 0)
-#define LCD_HIST_OK LCD_RGBPACK(51, 153, 0)
-#else /* HAVE_LCD_COLOR */
-#define LCD_BATT_OK LCD_BLACK
-#define LCD_BATT_LO LCD_DARKGRAY
-#define LCD_DISK_OK LCD_BLACK
-#define LCD_DISK_LO LCD_DARKGRAY
-#define LCD_HIST_OVER LCD_BLACK
-#define LCD_HIST_OK LCD_DARKGRAY
-#define LCD_BAL LCD_DARKGRAY
-#endif /* HAVE_LCD_COLOR */
-#else /* LCD_DEPTH > 1 */
-#define LCD_HIST_OVER LCD_DEFAULT_FG
-#define LCD_HIST_OK LCD_DEFAULT_FG
-#define LCD_BAL LCD_DEFAULT_FG
-#endif /* LCD_DEPTH > 1 */
-#endif /* HAVE_RECORDING_HISTOGRAM */
+#endif /* HAVE_AGC */
static void set_gain(void)
{
@@ -368,13 +338,6 @@ static bool read_peak_levels(int *peak_l, int *peak_r, int *balance)
*balance += balance_mem[i];
*balance = *balance / BAL_MEM_SIZE;
-#ifdef HAVE_RECORDING_HISTOGRAM
- if (*peak_l > hist_l)
- hist_l = *peak_l;
- if (*peak_r > hist_r)
- hist_r = *peak_r;
-#endif
-
return true;
}
@@ -1089,18 +1052,12 @@ bool recording_screen(bool no_source)
/* tweak layout tiny screens / big fonts */
bool compact_view[NB_SCREENS] = { false };
struct gui_synclist lists; /* the list in the bottom vp */
-#if defined(HAVE_AGC) || defined(HAVE_RECORDING_HISTOGRAM)
+#if defined(HAVE_AGC)
bool peak_valid = false;
#endif
-#if defined(HAVE_RECORDING_HISTOGRAM)
- int j;
+#if defined(HAVE_HISTOGRAM)
unsigned short hist_pos_y = 0;
unsigned short hist_size_h = 0;
- int history_pos = 0;
- short hist_time_interval = 1; /* 1, 2, 4, 8 */
- unsigned char history_l[HIST_BUF_SIZE];
- unsigned char history_r[HIST_BUF_SIZE];
- const char hist_level_marks[6] = { 29, 26, 23, 17, 9, 2};
#endif
#ifdef HAVE_FMRADIO_REC
int prev_rec_source = global_settings.rec_source; /* detect source change */
@@ -1186,10 +1143,9 @@ bool recording_screen(bool no_source)
/* top vp, 4 lines, force sys font if total screen < 6 lines
NOTE: one could limit the list to 1 line and get away with 5 lines */
top_height_req[i] = 4;
-#if defined(HAVE_RECORDING_HISTOGRAM)
- if((global_settings.rec_histogram_interval) && (!i))
+#if defined(HAVE_HISTOGRAM)
+ if((global_settings.histogram_interval) && (!i))
top_height_req[i] += 1; /* use one line for histogram */
- hist_time_interval = 1 << global_settings.rec_histogram_interval;
#endif
v = &vp_top[i];
viewport_set_defaults(v, i);
@@ -1229,13 +1185,11 @@ bool recording_screen(bool no_source)
send_event(GUI_EVENT_ACTIONUPDATE, (void*)1); /* force a redraw */
-#if defined(HAVE_RECORDING_HISTOGRAM)
- history_pos = 0;
+#if defined(HAVE_HISTOGRAM)
hist_pos_y = (compact_view[0] ? 3 : 4) * (font_get(vp_top[0].font)->height)
+ 1;
hist_size_h = font_get(vp_top[0].font)->height - 2;
- memset(history_l, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
- memset(history_r, 0, sizeof(unsigned char)*HIST_BUF_SIZE);
+ histogram_init();
#endif
FOR_NB_SCREENS(i)
@@ -1887,75 +1841,21 @@ bool recording_screen(bool no_source)
}
}
-#ifdef HAVE_RECORDING_HISTOGRAM
- if(global_settings.rec_histogram_interval)
- {
- if (peak_valid && !(hist_time % hist_time_interval) && hist_l)
+#ifdef HAVE_HISTOGRAM
+ if(global_settings.histogram_interval)
{
- /* fill history buffer */
- history_l[history_pos] = hist_l * hist_size_h / 32767;
- history_r[history_pos] = hist_r * hist_size_h / 32767;
- history_pos = (history_pos + 1) % HIST_BUF_SIZE;
- history_l[history_pos] = history_r[history_pos] = 0;
- history_l[(history_pos + 1) % HIST_BUF_SIZE] = 0;
- history_r[(history_pos + 1) % HIST_BUF_SIZE] = 0;
- hist_l = 0;
- hist_r = 0;
+ histogram_draw(0,
+ screens[0].getwidth()/2,
+ hist_pos_y,
+ hist_pos_y,
+ screens[0].getwidth()/2,
+ hist_size_h);
}
- lcd_set_drawmode(DRMODE_SOLID);
- lcd_drawrect(0, hist_pos_y - 1,
- HIST_W + 2, hist_size_h + 1);
- lcd_drawrect(HIST_W + 6, hist_pos_y - 1,
- HIST_W + 2, hist_size_h + 1);
- lcd_set_drawmode(DRMODE_FG);
-
- j = history_pos;
- for (i = HIST_W-1; i >= 0; i--)
- {
- j--;
- if(j<0)
- j = HIST_BUF_SIZE-1;
- if (history_l[j])
- {
- if (history_l[j] == hist_size_h)
- lcd_set_foreground(LCD_HIST_OVER);
-#ifdef HAVE_LCD_COLOR
- else if (history_l[j] > hist_level_marks[1])
- lcd_set_foreground(LCD_HIST_HI);
#endif
- else
- lcd_set_foreground(LCD_HIST_OK);
- lcd_vline(1 + i, HIST_Y-1, HIST_Y - history_l[j]);
- }
- if (history_r[j])
- {
- if (history_r[j] == hist_size_h)
- lcd_set_foreground(LCD_HIST_OVER);
-#ifdef HAVE_LCD_COLOR
- else if (history_r[j] > hist_level_marks[1])
- lcd_set_foreground(LCD_HIST_HI);
-#endif
- else
- lcd_set_foreground(LCD_HIST_OK);
- lcd_vline(HIST_W+7 + i, HIST_Y-1, HIST_Y - history_r[j]);
- }
- }
- lcd_set_foreground(
-#ifdef HAVE_LCD_COLOR
- global_settings.fg_color);
-#else
- LCD_DEFAULT_FG);
-#endif
- for (i = 0; i < 6; i++)
- lcd_hline(HIST_W + 3, HIST_W + 4,
- HIST_Y - hist_level_marks[i]);
- }
-#endif /* HAVE_RECORDING_HISTOGRAM */
#ifdef HAVE_AGC
hist_time++;
#endif
-
/* draw the trigger status */
if (peak_meter_trigger_status() != TRIG_OFF)
{