1
0
Fork 0
forked from len0rd/rockbox

Some peak meter optimizations

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2784 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2002-10-30 23:01:27 +00:00
parent d2df3c01dc
commit a02ffd5afa
5 changed files with 46 additions and 47 deletions

View file

@ -51,11 +51,15 @@ static int peak_meter_clip_hold;
/* specifies the value range in peak volume values */ /* specifies the value range in peak volume values */
unsigned short peak_meter_range_min; unsigned short peak_meter_range_min;
unsigned short peak_meter_range_max; unsigned short peak_meter_range_max;
unsigned short peak_meter_range;
/* if set to true clip timeout is disabled */ /* if set to true clip timeout is disabled */
static bool peak_meter_clip_eternal = false; static bool peak_meter_clip_eternal = false;
static bool peak_meter_use_dbfs = true; 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 #ifndef SIMULATOR
@ -110,8 +114,9 @@ static long clip_time_out[] = {
/* precalculated peak values that represent magical /* precalculated peak values that represent magical
dBfs values. Used to draw the scale */ dBfs values. Used to draw the scale */
#define DB_SCALE_SRC_VALUES_SIZE 11
#if 0 #if 0
static int db_scale_src_values[] = { const static int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = {
32767, /* 0 db */ 32767, /* 0 db */
23197, /* - 3 db */ 23197, /* - 3 db */
16422, /* - 6 db */ 16422, /* - 6 db */
@ -125,7 +130,7 @@ static int db_scale_src_values[] = {
33, /* -60 db */ 33, /* -60 db */
}; };
#else #else
static int db_scale_src_values[] = { static const int db_scale_src_values[DB_SCALE_SRC_VALUES_SIZE] = {
32752, /* 0 db */ 32752, /* 0 db */
22784, /* - 3 db */ 22784, /* - 3 db */
14256, /* - 6 db */ 14256, /* - 6 db */
@ -140,7 +145,7 @@ static int db_scale_src_values[] = {
}; };
#endif #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 /* if db_scale_valid is false the content of
db_scale_lcd_coord needs recalculation */ 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_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; 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_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; 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 * that ocurred. This function could be used by a thread for
* busy reading the MAS. * busy reading the MAS.
*/ */
void peak_meter_peek(void) { inline void peak_meter_peek(void) {
#ifdef SIMULATOR #ifdef SIMULATOR
int left = 8000; int left = 8000;
int right = 9000; int right = 9000;
@ -632,7 +647,6 @@ void peak_meter_set_clip_hold(int time) {
* @return unsigned short - A value 0 <= return value <= meterwidth * @return unsigned short - A value 0 <= return value <= meterwidth
*/ */
unsigned short peak_meter_scale_value(unsigned short val, int meterwidth){ unsigned short peak_meter_scale_value(unsigned short val, int meterwidth){
int range;
int retval; int retval;
if (val <= peak_meter_range_min) { 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 */ /* different scaling is used for dBfs and linear percent */
if (peak_meter_use_dbfs) { 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 */ /* 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 */ /* Scale for linear percent display */
else else
{ {
range =(peak_meter_range_max - peak_meter_range_min);
/* scale the samples */ /* scale the samples */
retval = ((retval - peak_meter_range_min) * meterwidth) / range; retval = ((retval - peak_meter_range_min) * meterwidth)
/ peak_meter_range;
} }
return retval; return retval;
} }
@ -697,14 +705,7 @@ void peak_meter_draw(int x, int y, int width, int height) {
/* read the volume info from MAS */ /* read the volume info from MAS */
left = peak_meter_read_l(); left = peak_meter_read_l();
right = peak_meter_read_r(); right = peak_meter_read_r();
peak_meter_peek(); /*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);
/* scale the samples dBfs */ /* scale the samples dBfs */
left = peak_meter_scale_value(left, meterwidth); 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 (!db_scale_valid){
if (peak_meter_use_dbfs) { 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++){ for (i = 0; i < db_scale_count; i++){
/* find the real x-coords for predefined interesting /* find the real x-coords for predefined interesting
dBfs values. These only are recalculated when the 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 */ /* when scaling linear we simly make 10% steps */
else { else {
int range = peak_meter_range_max - peak_meter_range_min;
db_scale_count = 10; db_scale_count = 10;
for (i = 0; i < db_scale_count; i++) { for (i = 0; i < db_scale_count; i++) {
db_scale_lcd_coord[i] = db_scale_lcd_coord[i] =
(i * (MAX_PEAK / 10) - peak_meter_range_min) * (i * (MAX_PEAK / 10) - peak_meter_range_min) *
meterwidth / range; meterwidth / peak_meter_range;
} }
} }

View file

@ -21,7 +21,7 @@
/*#define PM_DEBUG */ /*#define PM_DEBUG */
#ifdef PM_DEBUG #ifdef PM_DEBUG
extern bool peak_meter_histogramm(void); extern bool peak_meter_histogram(void);
#endif #endif

View file

@ -524,6 +524,8 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
char buf[MAX_PATH]; char buf[MAX_PATH];
unsigned char flags; unsigned char flags;
int i; int i;
int h = font_get(FONT_UI)->height;
bool update_line;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* to find out wether the peak meter is enabled we /* to find out wether the peak meter is enabled we
assume it wasn't until we find a line that contains 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++) for (i = 0; i < MAX_LINES; i++)
{ {
update_line = false;
if ( !format_lines[i] ) if ( !format_lines[i] )
break; break;
@ -559,24 +562,21 @@ bool wps_refresh(struct mp3entry* id3, int ffwd_offset, unsigned char refresh_mo
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
draw_player_progress(id3, ff_rewind_count); draw_player_progress(id3, ff_rewind_count);
#else #else
int w,h;
int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0; int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
lcd_getstringsize("M",&w,&h);
slidebar(0, i*h + offset + 1, LCD_WIDTH, 6, slidebar(0, i*h + offset + 1, LCD_WIDTH, 6,
(id3->elapsed + ff_rewind_count) * 100 / id3->length, (id3->elapsed + ff_rewind_count) * 100 / id3->length,
Grow_Right); Grow_Right);
continue;
#endif #endif
} update_line = true;
} else
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* peak meter */ /* peak meter */
if (flags & refresh_mode & WPS_REFRESH_PEAK_METER) { if (flags & refresh_mode & WPS_REFRESH_PEAK_METER) {
int peak_meter_y; int peak_meter_y;
struct font *fnt = font_get(FONT_UI);
int h = fnt->height;
int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0; int offset = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;
update_line = true;
peak_meter_y = i * h + offset; peak_meter_y = i * h + offset;
/* The user might decide to have the peak meter in the last /* 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, peak_meter_draw(0, peak_meter_y, LCD_WIDTH,
MIN(h, LCD_HEIGHT - peak_meter_y)); MIN(h, LCD_HEIGHT - peak_meter_y));
} }
continue; } else
}
#endif #endif
/* static line */ /* scroll line */
if (flags & WPS_REFRESH_SCROLL) if (flags & WPS_REFRESH_SCROLL)
{ {
if (refresh_mode & WPS_REFRESH_SCROLL) { if (refresh_mode & WPS_REFRESH_SCROLL)
{
lcd_puts_scroll(0, i, buf); 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); lcd_puts(0, i, buf);
} }
} }
if (update_line) {
lcd_update_rect(0, i * h, LCD_WIDTH, h);
}
} }
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
/* Now we know wether the peak meter is used. /* Now we know wether the peak meter is used.
So we can enable / disable the peak meter thread */ So we can enable / disable the peak meter thread */
peak_meter_enabled = enable_pm; peak_meter_enabled = enable_pm;
#endif #endif
lcd_update();
return true; return true;
} }

View file

@ -687,7 +687,7 @@ int wps_show(void)
break; break;
} }
peak_meter_peek(); peak_meter_peek();
yield(); sleep(1);
if (TIME_AFTER(current_tick, next_refresh)) { if (TIME_AFTER(current_tick, next_refresh)) {
wps_refresh(id3, 0, WPS_REFRESH_PEAK_METER); wps_refresh(id3, 0, WPS_REFRESH_PEAK_METER);

View file

@ -823,7 +823,6 @@ static void scroll_thread(void)
int index; int index;
int w, h; int w, h;
int xpos, ypos; int xpos, ypos;
bool update;
/* initialize scroll struct array */ /* initialize scroll struct array */
for (index = 0; index < SCROLLABLE_LINES; index++) { for (index = 0; index < SCROLLABLE_LINES; index++) {
@ -834,15 +833,12 @@ static void scroll_thread(void)
while ( 1 ) { while ( 1 ) {
update = false;
/* wait 0.5s before starting scroll */ /* wait 0.5s before starting scroll */
if ( TIME_AFTER(current_tick, scroll_start_tick) ) { if ( TIME_AFTER(current_tick, scroll_start_tick) ) {
for ( index = 0; index < SCROLLABLE_LINES; index++ ) { for ( index = 0; index < SCROLLABLE_LINES; index++ ) {
s = &scroll[index]; s = &scroll[index];
if ( s->mode == SCROLL_MODE_RUN ) { if ( s->mode == SCROLL_MODE_RUN ) {
update = true;
s->offset += scroll_step; s->offset += scroll_step;
@ -855,12 +851,9 @@ static void scroll_thread(void)
lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h); lcd_clearrect(xpos, ypos, LCD_WIDTH - xmargin, h);
lcd_putsxyofs(xpos, ypos, s->offset, s->line); 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); sleep(HZ/scroll_speed);