From 6271b2b9104e060f8e25c780f3cbb010cbcba827 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 9 Jun 2005 09:47:00 +0000 Subject: [PATCH] Added Crossfade setting for iRiver git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6636 a1c6a512-1295-4272-9138-f99709370657 --- apps/lang/english.lang | 6 ++++++ apps/settings.c | 12 +++++++++++- apps/settings.h | 4 ++++ apps/settings_menu.c | 18 ++++++++++++++++++ firmware/export/pcm_playback.h | 1 + firmware/pcm_playback.c | 33 ++++++++++++++++++++------------- 6 files changed, 60 insertions(+), 14 deletions(-) diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 423215c830..2c54a9c77b 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang @@ -3087,3 +3087,9 @@ desc: in info menu; name for external disk with multivolume (Ondio; keep short! eng: "MMC:" voice: "Multimedia card" new: + +id: LANG_CROSSFADE +desc: in playback settings +eng: "Crossfade" +voice: "Crossfade" +new: diff --git a/apps/settings.c b/apps/settings.c index 03b2dc5113..312a40e9f9 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -72,7 +72,9 @@ struct user_settings global_settings; #ifdef HAVE_RECORDING const char rec_base_directory[] = REC_BASE_DIR; #endif - +#if CONFIG_HWCODEC == MASNONE +#include "pcm_playback.h" +#endif #define CONFIG_BLOCK_VERSION 21 #define CONFIG_BLOCK_SIZE 512 @@ -382,6 +384,10 @@ static const struct bit_entry hd_bits[] = {4, S_O(rec_trigger_mode ), 1, "trigger mode", "off,no rearm,rearm"}, #endif +#if CONFIG_HWCODEC == MASNONE + {1, S_O(crossfade), false, "crossfade", off_on}, +#endif + /* new stuff to be added at the end */ /* Sum of all bit sizes must not grow beyond 0xB8*8 = 1472 */ @@ -812,6 +818,10 @@ void settings_apply(void) lang_load(buf); talk_init(); /* use voice of same language */ } + +#if CONFIG_HWCODEC == MASNONE && !defined(SIMULATOR) + pcm_crossfade_enable(global_settings.crossfade); +#endif } diff --git a/apps/settings.h b/apps/settings.h index 853dc41628..325009eddb 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -152,6 +152,10 @@ struct user_settings bool mdb_enable; /* true/false */ bool superbass; /* true/false */ +#if CONFIG_HWCODEC == MASNONE + bool crossfade; +#endif + int rec_quality; /* 0-7 */ int rec_source; /* 0=mic, 1=line, 2=S/PDIF */ int rec_frequency; /* 0 = 44.1kHz diff --git a/apps/settings_menu.c b/apps/settings_menu.c index e4002615dd..9826058202 100644 --- a/apps/settings_menu.c +++ b/apps/settings_menu.c @@ -60,6 +60,10 @@ void dac_line_in(bool enable); #include "lcd-remote.h" #endif +#if CONFIG_HWCODEC == MASNONE +#include "pcm_playback.h" +#endif + #ifdef HAVE_CHARGING static bool car_adapter_mode(void) { @@ -1055,6 +1059,17 @@ static bool id3_order(void) mpeg_id3_options); } +#if CONFIG_HWCODEC == MASNONE +static bool crossfade(void) +{ + bool rc = set_bool( str(LANG_CROSSFADE), &global_settings.crossfade ); +#ifndef SIMULATOR + pcm_crossfade_enable(global_settings.crossfade); +#endif + return rc; +} +#endif + static bool playback_settings_menu(void) { int m; @@ -1068,6 +1083,9 @@ static bool playback_settings_menu(void) { ID2P(LANG_WIND_MENU), ff_rewind_settings_menu }, { ID2P(LANG_MP3BUFFER_MARGIN), buffer_margin }, { ID2P(LANG_FADE_ON_STOP), set_fade_on_stop }, +#if CONFIG_HWCODEC == MASNONE + { ID2P(LANG_CROSSFADE), crossfade }, +#endif { ID2P(LANG_ID3_ORDER), id3_order }, }; diff --git a/firmware/export/pcm_playback.h b/firmware/export/pcm_playback.h index d101c823ba..0f2de83224 100644 --- a/firmware/export/pcm_playback.h +++ b/firmware/export/pcm_playback.h @@ -45,5 +45,6 @@ bool pcm_is_lowdata(void); void pcm_crossfade_start(void); unsigned int audiobuffer_get_latency(void); bool audiobuffer_insert(char *buf, size_t length); +void pcm_crossfade_enable(bool on_off); #endif diff --git a/firmware/pcm_playback.c b/firmware/pcm_playback.c index ab4f0c0375..e5d6f4218b 100644 --- a/firmware/pcm_playback.c +++ b/firmware/pcm_playback.c @@ -56,6 +56,7 @@ static volatile size_t audiobuffer_free; static size_t audiobuffer_fillpos; static bool boost_mode; +static bool crossfade_enabled; static bool crossfade_active; static int crossfade_pos; static int crossfade_amount; @@ -432,18 +433,7 @@ bool audiobuffer_insert(char *buf, size_t length) } while (length > 0) { - if (!crossfade_active) { - copy_n = MIN(length, PCMBUF_SIZE - audiobuffer_pos - - audiobuffer_fillpos); - copy_n = MIN(CHUNK_SIZE, copy_n); - - memcpy(&audiobuffer[audiobuffer_pos+audiobuffer_fillpos], - buf, copy_n); - buf += copy_n; - audiobuffer_free -= copy_n; - length -= copy_n; - - } else { + if (crossfade_enabled && crossfade_active) { copy_n = MIN(length, PCMBUF_SIZE - (unsigned int)crossfade_pos); crossfade((short *)&audiobuffer[crossfade_pos], @@ -453,7 +443,17 @@ bool audiobuffer_insert(char *buf, size_t length) crossfade_pos += copy_n; if (crossfade_pos >= PCMBUF_SIZE) crossfade_pos -= PCMBUF_SIZE; - continue ; + continue ; + } else { + copy_n = MIN(length, PCMBUF_SIZE - audiobuffer_pos - + audiobuffer_fillpos); + copy_n = MIN(CHUNK_SIZE, copy_n); + + memcpy(&audiobuffer[audiobuffer_pos+audiobuffer_fillpos], + buf, copy_n); + buf += copy_n; + audiobuffer_free -= copy_n; + length -= copy_n; } /* Pre-buffer to meet CHUNK_SIZE requirement */ @@ -501,6 +501,13 @@ void pcm_play_init(void) memset(&audiobuffer[0], 0, audiobuffer_pos); pcm_play_add_chunk(&audiobuffer[0], audiobuffer_pos, NULL); pcm_play_start(); + + crossfade_enabled = false; +} + +void pcm_crossfade_enable(bool on_off) +{ + crossfade_enabled = on_off; } void pcm_play_start(void)