summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-10-30 23:01:27 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-10-30 23:01:27 +0000
commita02ffd5afaa7a1a82f2da572b4c3cea01782b7c5 (patch)
tree015c75b9213e150503f37f12c300c90bd53948a9
parentd2df3c01dc34157fe3c0d414df7c68687f6aaedc (diff)
Some peak meter optimizations
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2784 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/recorder/peakmeter.c50
-rw-r--r--apps/recorder/peakmeter.h2
-rw-r--r--apps/wps-display.c30
-rw-r--r--apps/wps.c2
-rw-r--r--firmware/drivers/lcd-recorder.c9
5 files changed, 46 insertions, 47 deletions
diff --git a/apps/recorder/peakmeter.c b/apps/recorder/peakmeter.c
index e1850a4bb0..2e787ba982 100644
--- a/apps/recorder/peakmeter.c
+++ b/apps/recorder/peakmeter.c
@@ -51,11 +51,15 @@ static int peak_meter_clip_hold;
/* specifies the value range in peak volume values */
unsigned short peak_meter_range_min;
unsigned short peak_meter_range_max;
+unsigned short peak_meter_range;
/* if set to true clip timeout is disabled */
static bool peak_meter_clip_eternal = false;
static bool peak_meter_use_dbfs = true;
+static unsigned short db_min = 0;
+static unsigned short db_max = 9000;
+static unsigned short db_range = 9000;
#ifndef SIMULATOR
@@ -110,8 +114,9 @@ static long clip_time_out[] = {
/* precalculated peak values that represent magical
dBfs values. Used to draw the scale */
+#define DB_SCALE_SRC_VALUES_SIZE 11
#if 0
-static int db_scale_src_values[] = {
+const static int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = {
32767, /* 0 db */
23197, /* - 3 db */
16422, /* - 6 db */
@@ -125,7 +130,7 @@ static int db_scale_src_values[] = {
33, /* -60 db */
};
#else
-static int db_scale_src_values[] = {
+static const int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = {
32752, /* 0 db */
22784, /* - 3 db */
14256, /* - 6 db */
@@ -140,7 +145,7 @@ static int db_scale_src_values[] = {
};
#endif
-int db_scale_count = sizeof db_scale_src_values / sizeof (int);
+static int db_scale_count = DB_SCALE_SRC_VALUES_SIZE;
/* if db_scale_valid is false the content of
db_scale_lcd_coord needs recalculation */
@@ -343,6 +348,11 @@ void peak_meter_set_min(int newmin) {
peak_meter_range_min = newmin * MAX_PEAK / 100;
}
}
+
+ peak_meter_range = peak_meter_range_max - peak_meter_range_min;
+
+ db_min = calc_db(peak_meter_range_min);
+ db_range = db_max - db_min;
db_scale_valid = false;
}
@@ -378,6 +388,11 @@ void peak_meter_set_max(int newmax) {
peak_meter_range_max = newmax * MAX_PEAK / 100;
}
}
+
+ peak_meter_range = peak_meter_range_max - peak_meter_range_min;
+
+ db_max = calc_db(peak_meter_range_max);
+ db_range = db_max - db_min;
db_scale_valid = false;
}
@@ -482,7 +497,7 @@ void peak_meter_playback(bool playback) {
* that ocurred. This function could be used by a thread for
* busy reading the MAS.
*/
-void peak_meter_peek(void) {
+inline void peak_meter_peek(void) {
#ifdef SIMULATOR
int left = 8000;
int right = 9000;
@@ -632,7 +647,6 @@ void peak_meter_set_clip_hold(int time) {
* @return unsigned short - A value 0 <= return value <= meterwidth
*/
unsigned short peak_meter_scale_value(unsigned short val, int meterwidth){
- int range;
int retval;
if (val <= peak_meter_range_min) {
@@ -648,22 +662,16 @@ unsigned short peak_meter_scale_value(unsigned short val, int meterwidth){
/* different scaling is used for dBfs and linear percent */
if (peak_meter_use_dbfs) {
- /* needed the offset in 'zoomed' meters */
- int dbmin = calc_db(peak_meter_range_min);
-
- range = calc_db(peak_meter_range_max) - dbmin;
-
/* scale the samples dBfs */
- retval = (calc_db(retval) - dbmin) * meterwidth / range;
+ retval = (calc_db(retval) - db_min) * meterwidth / db_range;
}
/* Scale for linear percent display */
else
{
- range =(peak_meter_range_max - peak_meter_range_min);
-
/* scale the samples */
- retval = ((retval - peak_meter_range_min) * meterwidth) / range;
+ retval = ((retval - peak_meter_range_min) * meterwidth)
+ / peak_meter_range;
}
return retval;
}
@@ -697,14 +705,7 @@ void peak_meter_draw(int x, int y, int width, int height) {
/* read the volume info from MAS */
left = peak_meter_read_l();
right = peak_meter_read_r();
- peak_meter_peek();
-
- /* restrict the range to avoid drawing outside the lcd */
- left = MAX(peak_meter_range_min, left);
- left = MIN(peak_meter_range_max, left);
-
- right = MAX(peak_meter_range_min, right);
- right = MIN(peak_meter_range_max, right);
+ /*peak_meter_peek();*/
/* scale the samples dBfs */
left = peak_meter_scale_value(left, meterwidth);
@@ -715,7 +716,7 @@ void peak_meter_draw(int x, int y, int width, int height) {
if (!db_scale_valid){
if (peak_meter_use_dbfs) {
- db_scale_count = sizeof db_scale_src_values / sizeof (int);
+ db_scale_count = DB_SCALE_SRC_VALUES_SIZE;
for (i = 0; i < db_scale_count; i++){
/* find the real x-coords for predefined interesting
dBfs values. These only are recalculated when the
@@ -729,12 +730,11 @@ void peak_meter_draw(int x, int y, int width, int height) {
/* when scaling linear we simly make 10% steps */
else {
- int range = peak_meter_range_max - peak_meter_range_min;
db_scale_count = 10;
for (i = 0; i < db_scale_count; i++) {
db_scale_lcd_coord[i] =
(i * (MAX_PEAK / 10) - peak_meter_range_min) *
- meterwidth / range;
+ meterwidth / peak_meter_range;
}
}
diff --git a/apps/recorder/peakmeter.h b/apps/recorder/peakmeter.h
index 356926f9de..db419a0afa 100644
--- a/apps/recorder/peakmeter.h
+++ b/apps/recorder/peakmeter.h
@@ -21,7 +21,7 @@
/*#define PM_DEBUG */
#ifdef PM_DEBUG
-extern bool peak_meter_histogramm(void);
+extern bool peak_meter_histogram(void);
#endif
diff --git a/apps/wps-display.c b/apps/wps-display.c
index f8dbcde420..cfc968a3ec 100644
--- a/apps/wps-display.c
+++ b/apps/wps-display.c
@@ -524,6 +524,8 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
char buf[MAX_PATH];
unsigned char flags;
int i;
+ int h = font_get(FONT_UI)->height;
+ bool update_line;
#ifdef HAVE_LCD_BITMAP
/* to find out wether the peak meter is enabled we
assume it wasn't until we find a line that contains
@@ -544,6 +546,7 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
for (i = 0; i < MAX_LINES; i++)
{
+ update_line = false;
if ( !format_lines[i] )
break;
@@ -559,24 +562,21 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
#ifdef HAVE_LCD_CHARCELLS
draw_player_progress(id3, ff_rewind_count);
#else
- int w,h;
int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
- lcd_getstringsize("M",&w,&h);
slidebar(0, i*h + offset + 1, LCD_WIDTH, 6,
(id3->elapsed + ff_rewind_count) * 100 / id3->length,
Grow_Right);
- continue;
#endif
- }
+ update_line = true;
+ } else
#ifdef HAVE_LCD_BITMAP
/* peak meter */
if (flags & refresh_mode & WPS_REFRESH_PEAK_METER) {
int peak_meter_y;
- struct font *fnt = font_get(FONT_UI);
- int h = fnt->height;
int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
+ update_line = true;
peak_meter_y = i * h + offset;
/* The user might decide to have the peak meter in the last
@@ -590,29 +590,35 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
peak_meter_draw(0, peak_meter_y, LCD_WIDTH,
MIN(h, LCD_HEIGHT - peak_meter_y));
}
- continue;
- }
+ } else
#endif
- /* static line */
+ /* scroll line */
if (flags & WPS_REFRESH_SCROLL)
{
- if (refresh_mode & WPS_REFRESH_SCROLL) {
+ if (refresh_mode & WPS_REFRESH_SCROLL)
+ {
lcd_puts_scroll(0, i, buf);
}
}
- else
+
+ /* dynamic / static line */
+ if ((flags & refresh_mode & WPS_REFRESH_DYNAMIC) ||
+ (flags & refresh_mode & WPS_REFRESH_STATIC))
{
+ update_line = true;
lcd_puts(0, i, buf);
}
}
+ if (update_line) {
+ lcd_update_rect(0, i * h, LCD_WIDTH, h);
+ }
}
#ifdef HAVE_LCD_BITMAP
/* Now we know wether the peak meter is used.
So we can enable / disable the peak meter thread */
peak_meter_enabled = enable_pm;
#endif
- lcd_update();
return true;
}
diff --git a/apps/wps.c b/apps/wps.c
index 8f9295a293..68d158e18e 100644
--- a/apps/wps.c
+++ b/apps/wps.c
@@ -687,7 +687,7 @@ int wps_show(void)
break;
}
peak_meter_peek();
- yield();
+ sleep(1);
if (TIME_AFTER(current_tick, next_refresh)) {
wps_refresh(id3, 0, WPS_REFRESH_PEAK_METER);
diff --git a/firmware/drivers/lcd-recorder.c b/firmware/drivers/lcd-recorder.c
index 10071dc3d7..16729464fc 100644
--- a/firmware/drivers/lcd-recorder.c
+++ b/firmware/drivers/lcd-recorder.c
@@ -823,7 +823,6 @@ static void scroll_thread(void)
int index;
int w, h;
int xpos, ypos;
- bool update;
/* initialize scroll struct array */
for (index = 0; index < SCROLLABLE_LINES; index++) {
@@ -834,15 +833,12 @@ static void scroll_thread(void)
while ( 1 ) {
- update = false;
-
/* wait 0.5s before starting scroll */
if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) {
- update = true;
s->offset += scroll_step;
@@ -855,12 +851,9 @@ static void scroll_thread(void)
lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h);
lcd_putsxyofs(xpos, ypos, s->offset, s->line);
+ lcd_update_rect(xpos, ypos, LCD_WIDTH - xmargin, h);
}
}
-
- if (update) {
- lcd_update();
- }
}
sleep(HZ/scroll_speed);