From c80e0c19e1b192a384dd8670424bc7dea2831553 Mon Sep 17 00:00:00 2001 From: Jens Arnold Date: Sat, 17 Dec 2005 21:13:30 +0000 Subject: [PATCH] Fixed several plugins for dB volume. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8258 a1c6a512-1295-4272-9138-f99709370657 --- apps/plugin.c | 3 +++ apps/plugin.h | 5 ++++- apps/plugins/alpine_cdc.c | 2 +- apps/plugins/metronome.c | 7 +++++-- apps/plugins/oscilloscope.c | 4 ++-- apps/plugins/video.c | 8 +++++--- apps/plugins/vu_meter.c | 8 +++++--- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/apps/plugin.c b/apps/plugin.c index c993bb1f8a..9a20827e26 100644 --- a/apps/plugin.c +++ b/apps/plugin.c @@ -367,6 +367,9 @@ static const struct plugin_api rockbox_api = { utf16BEdecode, utf8encode, utf8length, + + sound_min, + sound_max, }; int plugin_load(const char* plugin, void* parameter) diff --git a/apps/plugin.h b/apps/plugin.h index 7f86d54c93..f935809949 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -91,7 +91,7 @@ #endif /* increase this every time the api struct changes */ -#define PLUGIN_API_VERSION 53 +#define PLUGIN_API_VERSION 54 /* update this to latest version if a change to the api struct breaks backwards compatibility (and please take the opportunity to sort in any @@ -448,6 +448,9 @@ struct plugin_api { unsigned char* (*utf16BEdecode)(const unsigned char *utf16, unsigned char *utf8, unsigned int count); unsigned char* (*utf8encode)(unsigned long ucs, unsigned char *utf8); unsigned long (*utf8length)(const unsigned char *utf8); + + int (*sound_min)(int setting); + int (*sound_max)(int setting); }; int plugin_load(const char* plugin, void* parameter); diff --git a/apps/plugins/alpine_cdc.c b/apps/plugins/alpine_cdc.c index be13775216..874f72265e 100644 --- a/apps/plugins/alpine_cdc.c +++ b/apps/plugins/alpine_cdc.c @@ -1044,7 +1044,7 @@ void sound_neutral(void) rb->sound_set(SOUND_BASS, 0); rb->sound_set(SOUND_TREBLE, 0); rb->sound_set(SOUND_BALANCE, 0); - rb->sound_set(SOUND_VOLUME, 92); /* 0 dB */ + rb->sound_set(SOUND_VOLUME, 0); #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) rb->sound_set(SOUND_LOUDNESS, 0); rb->sound_set(SOUND_SUPERBASS, 0); diff --git a/apps/plugins/metronome.c b/apps/plugins/metronome.c index fa5520b635..861eebf3aa 100644 --- a/apps/plugins/metronome.c +++ b/apps/plugins/metronome.c @@ -196,10 +196,13 @@ void draw_display(void){ /* helper function to change the volume by a certain amount, +/- ripped from video.c */ void change_volume(int delta){ + int minvol = rb->sound_min(SOUND_VOLUME); + int maxvol = rb->sound_max(SOUND_VOLUME); int vol = rb->global_settings->volume + delta; char buffer[30]; - if (vol > 100) vol = 100; - else if (vol < 0) vol = 0; + + if (vol > maxvol) vol = maxvol; + else if (vol < minvol) vol = minvol; if (vol != rb->global_settings->volume) { rb->sound_set(SOUND_VOLUME, vol); rb->global_settings->volume = vol; diff --git a/apps/plugins/oscilloscope.c b/apps/plugins/oscilloscope.c index b3b081d861..916e55018c 100644 --- a/apps/plugins/oscilloscope.c +++ b/apps/plugins/oscilloscope.c @@ -241,7 +241,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) case OSCILLOSCOPE_VOL_UP: case OSCILLOSCOPE_VOL_UP | BUTTON_REPEAT: vol = rb->global_settings->volume; - if (vol < 100) + if (vol < rb->sound_max(SOUND_VOLUME)) { vol++; rb->sound_set(SOUND_VOLUME, vol); @@ -252,7 +252,7 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter) case OSCILLOSCOPE_VOL_DOWN: case OSCILLOSCOPE_VOL_DOWN | BUTTON_REPEAT: vol = rb->global_settings->volume; - if (vol > 0) + if (vol > rb->sound_min(SOUND_VOLUME)) { vol--; rb->sound_set(SOUND_VOLUME, vol); diff --git a/apps/plugins/video.c b/apps/plugins/video.c index 1a288eec84..91d47a52d1 100644 --- a/apps/plugins/video.c +++ b/apps/plugins/video.c @@ -272,15 +272,17 @@ void DrawPosition(int pos, int total) // helper function to change the volume by a certain amount, +/- void ChangeVolume(int delta) { + int minvol = rb->sound_min(SOUND_VOLUME); + int maxvol = rb->sound_max(SOUND_VOLUME); int vol = rb->global_settings->volume + delta; - if (vol > 100) vol = 100; - else if (vol < 0) vol = 0; + if (vol > maxvol) vol = maxvol; + else if (vol < minvol) vol = minvol; if (vol != rb->global_settings->volume) { rb->sound_set(SOUND_VOLUME, vol); rb->global_settings->volume = vol; - rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d", vol); + rb->snprintf(gPrint, sizeof(gPrint), "Vol: %d dB", vol); rb->lcd_puts(0, 7, gPrint); if (gPlay.state == paused) // we have to draw ourselves rb->lcd_update_rect(0, LCD_HEIGHT-8, LCD_WIDTH, 8); diff --git a/apps/plugins/vu_meter.c b/apps/plugins/vu_meter.c index 80621d2fd3..6a55a1af1a 100644 --- a/apps/plugins/vu_meter.c +++ b/apps/plugins/vu_meter.c @@ -133,11 +133,13 @@ void save_settings(void) { } void change_volume(int delta) { - char curr_vol[4]; + char curr_vol[5]; + int minvol = rb->sound_min(SOUND_VOLUME); + int maxvol = rb->sound_max(SOUND_VOLUME); int vol = rb->global_settings->volume + delta; - if (vol>100) vol = 100; - else if (vol < 0) vol = 0; + if (vol > maxvol) vol = maxvol; + else if (vol < minvol) vol = minvol; if (vol != rb->global_settings->volume) { rb->sound_set(SOUND_VOLUME, vol); rb->global_settings->volume = vol;