Index: apps/misc.h =================================================================== --- apps/misc.h (revision 14672) +++ apps/misc.h (working copy) @@ -92,13 +92,11 @@ void car_adapter_mode_init(void); extern int show_logo(void); -#if CONFIG_CODEC == SWCODEC /* Return current ReplayGain mode a file should have (REPLAYGAIN_TRACK or * REPLAYGAIN_ALBUM) if ReplayGain processing is enabled, or -1 if no * information present. */ int get_replaygain_mode(bool have_track_gain, bool have_album_gain); -#endif #ifdef BOOTFILE #if !defined(USB_NONE) && !defined(USB_IPODSTYLE) Index: apps/screens.c =================================================================== --- apps/screens.c (revision 14672) +++ apps/screens.c (working copy) @@ -706,6 +706,17 @@ { #if CONFIG_CODEC == SWCODEC dsp_set_replaygain(); +#else + /* Determine Replaygain type and set it */ + sound_set_replaygain_type( + (((global_settings.replaygain_type==REPLAYGAIN_SHUFFLE) && + (global_settings.playlist_shuffle)) || + (global_settings.replaygain_type==REPLAYGAIN_TRACK) + ) ? REPLAYGAIN_TRACK : REPLAYGAIN_ALBUM + ); + /* If replaygain is disabled set special code for that */ + if (!global_settings.replaygain) sound_set_replaygain_type(3); + sound_set_replaygain(); #endif if (global_settings.playlist_shuffle) playlist_randomise(NULL, current_tick, true); @@ -1162,10 +1173,8 @@ LANG_ID3_PLAYLIST, LANG_ID3_BITRATE, LANG_ID3_FREQUENCY, -#if CONFIG_CODEC == SWCODEC LANG_ID3_TRACK_GAIN, LANG_ID3_ALBUM_GAIN, -#endif LANG_ID3_PATH, }; @@ -1249,7 +1258,6 @@ snprintf(buffer, MAX_PATH, "%ld Hz", id3->frequency); info=buffer; break; -#if CONFIG_CODEC == SWCODEC case 14:/*LANG_ID3_TRACK_GAIN*/ info=id3->track_gain_string; break; @@ -1257,9 +1265,6 @@ info=id3->album_gain_string; break; case 16:/*LANG_ID3_PATH*/ -#else - case 14:/*LANG_ID3_PATH*/ -#endif info=id3->path; break; } Index: apps/lang/svenska.lang =================================================================== --- apps/lang/svenska.lang (revision 14672) +++ apps/lang/svenska.lang (working copy) @@ -1804,16 +1804,13 @@ desc: in replaygain user: - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" - *: none - swcodec: "Förhindra klippning" + *: "Förhindra klippning" - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" Index: apps/lang/nederlands.lang =================================================================== --- apps/lang/nederlands.lang (revision 14672) +++ apps/lang/nederlands.lang (working copy) @@ -2817,16 +2817,13 @@ desc: in replaygain user: - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" - *: none - swcodec: "Voorkom clippen" + *: "Voorkom clippen" - *: none - swcodec: "Voorkom clippen" + *: "Voorkom clippen" Index: apps/lang/japanese.lang =================================================================== --- apps/lang/japanese.lang (revision 14672) +++ apps/lang/japanese.lang (working copy) @@ -1804,16 +1804,13 @@ desc: in replaygain user: - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" - *: none - swcodec: "クリッピング防止" + *: "クリッピング防止" - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" Index: apps/lang/english.lang =================================================================== --- apps/lang/english.lang (revision 14672) +++ apps/lang/english.lang (working copy) @@ -1871,16 +1871,13 @@ desc: in replaygain user: - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" - *: none - swcodec: "Prevent Clipping" + *: "Prevent Clipping" Index: apps/settings.c =================================================================== --- apps/settings.c (revision 14672) +++ apps/settings.c (working copy) @@ -635,6 +635,18 @@ { #if CONFIG_CODEC == SWCODEC sound_set_dsp_callback(dsp_callback); +#else + sound_set_replaygain_noclip(global_settings.replaygain_noclip); + sound_set_replaygain_type( + (((global_settings.replaygain_type==REPLAYGAIN_SHUFFLE) && + (global_settings.playlist_shuffle)) || + (global_settings.replaygain_type==REPLAYGAIN_TRACK) + ) ? REPLAYGAIN_TRACK : REPLAYGAIN_ALBUM + ); + /* If replaygain is disabled set special code for that */ + if (!global_settings.replaygain) sound_set_replaygain_type(3); + sound_set_replaygain_preamp(global_settings.replaygain_preamp); + sound_set_replaygain(); #endif sound_set(SOUND_BASS, global_settings.bass); sound_set(SOUND_TREBLE, global_settings.treble); Index: apps/gui/gwps-common.c =================================================================== --- apps/gui/gwps-common.c (revision 14672) +++ apps/gui/gwps-common.c (working copy) @@ -1259,6 +1259,7 @@ *intval = global_settings.crossfade + 1; snprintf(buf, buf_size, "%d", global_settings.crossfade); return buf; +#endif /* (CONFIG_CODEC == SWCODEC) */ case WPS_TOKEN_REPLAYGAIN: { @@ -1300,7 +1301,6 @@ } return buf; } -#endif /* (CONFIG_CODEC == SWCODEC) */ #if (CONFIG_CODEC != MAS3507D) case WPS_TOKEN_SOUND_PITCH: Index: apps/gui/wps_debug.c =================================================================== --- apps/gui/wps_debug.c (revision 14672) +++ apps/gui/wps_debug.c (working copy) @@ -208,11 +208,11 @@ case WPS_TOKEN_CROSSFADE: snprintf(buf, sizeof(buf), "crossfade"); break; +#endif case WPS_TOKEN_REPLAYGAIN: snprintf(buf, sizeof(buf), "replaygain"); break; -#endif #ifdef HAVE_LCD_BITMAP case WPS_TOKEN_IMAGE_BACKDROP: Index: apps/gui/gwps.h =================================================================== --- apps/gui/gwps.h (revision 14672) +++ apps/gui/gwps.h (working copy) @@ -123,8 +123,8 @@ #if (CONFIG_CODEC != MAS3507D) WPS_TOKEN_SOUND_PITCH, #endif + WPS_TOKEN_REPLAYGAIN, #if (CONFIG_CODEC == SWCODEC) - WPS_TOKEN_REPLAYGAIN, WPS_TOKEN_CROSSFADE, #endif Index: apps/gui/wps_parser.c =================================================================== --- apps/gui/wps_parser.c (revision 14672) +++ apps/gui/wps_parser.c (working copy) @@ -264,8 +264,8 @@ { WPS_TOKEN_DATABASE_PLAYCOUNT, "rp", WPS_REFRESH_DYNAMIC, NULL }, { WPS_TOKEN_DATABASE_RATING, "rr", WPS_REFRESH_DYNAMIC, NULL }, { WPS_TOKEN_DATABASE_AUTOSCORE, "ra", WPS_REFRESH_DYNAMIC, NULL }, + { WPS_TOKEN_REPLAYGAIN, "rg", WPS_REFRESH_STATIC, NULL }, #if CONFIG_CODEC == SWCODEC - { WPS_TOKEN_REPLAYGAIN, "rg", WPS_REFRESH_STATIC, NULL }, { WPS_TOKEN_CROSSFADE, "xf", WPS_REFRESH_DYNAMIC, NULL }, #endif Index: apps/settings.h =================================================================== --- apps/settings.h (revision 14672) +++ apps/settings.h (working copy) @@ -566,12 +566,12 @@ int next_folder; /* move to next folder */ bool runtimedb; /* runtime database active? */ -#if CONFIG_CODEC == SWCODEC bool replaygain; /* enable replaygain */ bool replaygain_noclip; /* scale to prevent clips */ int replaygain_type; /* 0=track gain, 1=album gain, 2=track gain if shuffle is on, album gain otherwise */ int replaygain_preamp; /* scale replaygained tracks by this */ +#if CONFIG_CODEC == SWCODEC int beep; /* system beep volume when changing tracks etc. */ /* Crossfeed settings */ Index: apps/menus/playback_menu.c =================================================================== --- apps/menus/playback_menu.c (revision 14672) +++ apps/menus/playback_menu.c (working copy) @@ -35,6 +35,8 @@ #include "audio.h" #include "cuesheet.h" +#include "sound.h" + #if CONFIG_CODEC == SWCODEC int setcrossfadeonexit_callback(int action,const struct menu_item_ex *this_item) { @@ -101,6 +103,7 @@ &crossfade, &crossfade_fade_in_delay, &crossfade_fade_in_duration, &crossfade_fade_out_delay, &crossfade_fade_out_duration, &crossfade_fade_out_mixmode); +#endif /* CONFIG_CODEC == SWCODEC*/ /* replay gain submenu */ @@ -110,7 +113,21 @@ switch (action) { case ACTION_EXIT_MENUITEM: /* on exit */ +#if CONFIG_CODEC == SWCODEC dsp_set_replaygain(); +#else + sound_set_replaygain_noclip(global_settings.replaygain_noclip); + sound_set_replaygain_type( + (((global_settings.replaygain_type==REPLAYGAIN_SHUFFLE) && + (global_settings.playlist_shuffle)) || + (global_settings.replaygain_type==REPLAYGAIN_TRACK) + ) ? REPLAYGAIN_TRACK : REPLAYGAIN_ALBUM + ); + /* If replaygain is disabled set special code for that */ + if (!global_settings.replaygain) sound_set_replaygain_type(3); + sound_set_replaygain_preamp(global_settings.replaygain_preamp); + sound_set_replaygain(); +#endif /* CONFIG_CODEC == SWCODEC */ break; } return action; @@ -123,6 +140,7 @@ &replaygain,&replaygain_noclip, &replaygain_type,&replaygain_preamp); +#if CONFIG_CODEC == SWCODEC MENUITEM_SETTING(beep, &global_settings.beep ,NULL); #endif /* CONFIG_CODEC == SWCODEC */ @@ -181,9 +199,15 @@ &fade_on_stop, &party_mode, #if CONFIG_CODEC == SWCODEC - &crossfade_settings_menu, &replaygain_settings_menu, &beep, + &crossfade_settings_menu, #endif + &replaygain_settings_menu, + +#if CONFIG_CODEC == SWCODEC + &beep, +#endif + #ifdef HAVE_SPDIF_POWER &spdif_enable, #endif @@ -213,6 +237,17 @@ { #if CONFIG_CODEC == SWCODEC dsp_set_replaygain(); +#else + /* Determine Replaygain type and set it */ + sound_set_replaygain_type( + (((global_settings.replaygain_type==REPLAYGAIN_SHUFFLE) && + (global_settings.playlist_shuffle)) || + (global_settings.replaygain_type==REPLAYGAIN_TRACK) + ) ? REPLAYGAIN_TRACK : REPLAYGAIN_ALBUM + ); + /* If replaygain is disabled set special code for that */ + if (!global_settings.replaygain) sound_set_replaygain_type(3); + sound_set_replaygain(); #endif if (global_settings.playlist_shuffle) { Index: apps/settings_list.c =================================================================== --- apps/settings_list.c (revision 14672) +++ apps/settings_list.c (working copy) @@ -307,6 +307,7 @@ global_settings.crossfeed_hf_attenuation, global_settings.crossfeed_hf_cutoff); } +#endif static void replaygain_preamp_format(char* buffer, size_t buffer_size, int value, const char* unit) @@ -317,7 +318,6 @@ v / 10, v % 10, unit); } -#endif #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) static void set_mdb_enable(bool value) { @@ -895,7 +895,6 @@ ID2P(LANG_SET_BOOL_NO), ID2P(LANG_SET_BOOL_YES), ID2P(LANG_RANDOM)), OFFON_SETTING(0,runtimedb,LANG_RUNTIMEDB_ACTIVE,false,"gather runtime data",NULL), -#if CONFIG_CODEC == SWCODEC /* replay gain */ OFFON_SETTING(0, replaygain, LANG_REPLAYGAIN_ENABLE, false, "replaygain", NULL), CHOICE_SETTING(0, replaygain_type, LANG_REPLAYGAIN_MODE, REPLAYGAIN_ALBUM, @@ -906,6 +905,7 @@ INT_SETTING(0, replaygain_preamp, LANG_REPLAYGAIN_PREAMP, 0, "replaygain preamp", UNIT_DB, -120, 120, 5, replaygain_preamp_format, NULL, NULL), +#if CONFIG_CODEC == SWCODEC CHOICE_SETTING(0, beep, LANG_BEEP, 0, "beep", "off,weak,moderate,strong", NULL, 4, ID2P(LANG_OFF), ID2P(LANG_WEAK), ID2P(LANG_MODERATE), ID2P(LANG_STRONG)), Index: apps/main.c =================================================================== --- apps/main.c (revision 14672) +++ apps/main.c (working copy) @@ -536,21 +536,8 @@ #if CONFIG_CODEC != SWCODEC /* No buffer allocation (see buffer.c) may take place after the call to audio_init() since the mpeg thread takes the rest of the buffer space */ - mp3_init( global_settings.volume, - global_settings.bass, - global_settings.treble, - global_settings.balance, - global_settings.loudness, - global_settings.avc, - global_settings.channel_config, - global_settings.stereo_width, - global_settings.mdb_strength, - global_settings.mdb_harmonics, - global_settings.mdb_center, - global_settings.mdb_shape, - global_settings.mdb_enable, - global_settings.superbass); - + mp3_init(); + sound_settings_apply(); /* audio_init must to know the size of voice buffer so init voice first */ talk_init(); #endif /* CONFIG_CODEC != SWCODEC */ Index: apps/misc.c =================================================================== --- apps/misc.c (revision 14672) +++ apps/misc.c (working copy) @@ -952,7 +952,6 @@ return 0; } -#if CONFIG_CODEC == SWCODEC int get_replaygain_mode(bool have_track_gain, bool have_album_gain) { int type; @@ -966,7 +965,6 @@ return type; } -#endif #ifdef BOOTFILE #if !defined(USB_NONE) && !defined(USB_IPODSTYLE) Index: firmware/export/id3.h =================================================================== --- firmware/export/id3.h (revision 14672) +++ firmware/export/id3.h (working copy) @@ -214,14 +214,12 @@ /* replaygain support */ -#if CONFIG_CODEC == SWCODEC char* track_gain_string; char* album_gain_string; long track_gain; /* 7.24 signed fixed point. 0 for no gain. */ long album_gain; long track_peak; /* 7.24 signed fixed point. 0 for no peak. */ long album_peak; -#endif /* Cuesheet support */ int cuesheet_type; /* 0: none, 1: external, 2: embedded */ Index: firmware/export/mp3_playback.h =================================================================== --- firmware/export/mp3_playback.h (revision 14672) +++ firmware/export/mp3_playback.h (working copy) @@ -25,11 +25,7 @@ #include /* functions formerly in mpeg.c */ -void mp3_init(int volume, int bass, int treble, int balance, int loudness, - int avc, int channel_config, int stereo_width, - int mdb_strength, int mdb_harmonics, - int mdb_center, int mdb_shape, bool mdb_enable, - bool superbass); +void mp3_init(void); /* exported just for mpeg.c, to keep the recording there */ #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) Index: firmware/export/sound.h =================================================================== --- firmware/export/sound.h (revision 14672) +++ firmware/export/sound.h (working copy) @@ -41,6 +41,15 @@ void sound_set_treble(int value); void sound_set_channels(int value); void sound_set_stereo_width(int value); +void sound_set_replaygain(void); +void sound_set_replaygain_noclip(bool value); +void sound_set_replaygain_type(int value); +void sound_set_replaygain_preamp(int value); +void sound_set_replaygain_trackgain(long value); +void sound_set_replaygain_trackpeak(long value); +void sound_set_replaygain_albumgain(long value); +void sound_set_replaygain_albumpeak(long value); + #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) void sound_set_loudness(int value); void sound_set_avc(int value); Index: firmware/mp3_playback.c =================================================================== --- firmware/mp3_playback.c (revision 14672) +++ firmware/mp3_playback.c (working copy) @@ -327,38 +327,11 @@ #endif /* #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) */ #endif /* SIMULATOR */ -void mp3_init(int volume, int bass, int treble, int balance, int loudness, - int avc, int channel_config, int stereo_width, - int mdb_strength, int mdb_harmonics, - int mdb_center, int mdb_shape, bool mdb_enable, - bool superbass) +void mp3_init(void) { -#ifdef SIMULATOR - (void)volume; - (void)bass; - (void)treble; - (void)balance; - (void)loudness; - (void)avc; - (void)channel_config; - (void)stereo_width; - (void)mdb_strength; - (void)mdb_harmonics; - (void)mdb_center; - (void)mdb_shape; - (void)mdb_enable; - (void)superbass; -#else +#ifndef SIMULATOR #if CONFIG_CODEC == MAS3507D unsigned long val; - (void)loudness; - (void)avc; - (void)mdb_strength; - (void)mdb_harmonics; - (void)mdb_center; - (void)mdb_shape; - (void)mdb_enable; - (void)superbass; #endif setup_sci0(); @@ -448,23 +421,6 @@ /* Must be done before calling sound_set() */ audio_is_initialized = true; - sound_set(SOUND_BASS, bass); - sound_set(SOUND_TREBLE, treble); - sound_set(SOUND_BALANCE, balance); - sound_set(SOUND_VOLUME, volume); - sound_set(SOUND_CHANNELS, channel_config); - sound_set(SOUND_STEREO_WIDTH, stereo_width); - -#if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) - sound_set(SOUND_LOUDNESS, loudness); - sound_set(SOUND_AVC, avc); - sound_set(SOUND_MDB_STRENGTH, mdb_strength); - sound_set(SOUND_MDB_HARMONICS, mdb_harmonics); - sound_set(SOUND_MDB_CENTER, mdb_center); - sound_set(SOUND_MDB_SHAPE, mdb_shape); - sound_set(SOUND_MDB_ENABLE, mdb_enable); - sound_set(SOUND_SUPERBASS, superbass); -#endif #endif /* !SIMULATOR */ playing = false; Index: firmware/id3.c =================================================================== --- firmware/id3.c (revision 14672) +++ firmware/id3.c (working copy) @@ -392,7 +392,6 @@ } } -#if CONFIG_CODEC == SWCODEC /* parse user defined text, looking for replaygain information. */ static int parseuser( struct mp3entry* entry, char* tag, int bufferpos ) { @@ -473,7 +472,6 @@ return tag - entry->id3v2buf + value_len; } -#endif static const struct tag_resolver taglist[] = { { "TPE1", 4, offsetof(struct mp3entry, artist), NULL, false }, @@ -496,10 +494,8 @@ { "COMM", 4, offsetof(struct mp3entry, comment), NULL, false }, { "TCON", 4, offsetof(struct mp3entry, genre_string), &parsegenre, false }, { "TCO", 3, offsetof(struct mp3entry, genre_string), &parsegenre, false }, -#if CONFIG_CODEC == SWCODEC { "TXXX", 4, 0, &parseuser, false }, { "RVA2", 4, 0, &parserva2, true }, -#endif }; #define TAGLIST_SIZE ((int)(sizeof(taglist) / sizeof(taglist[0]))) @@ -1255,12 +1251,10 @@ entry->albumartist += offset; if (entry->grouping) entry->grouping += offset; -#if CONFIG_CODEC == SWCODEC if (entry->track_gain_string) entry->track_gain_string += offset; if (entry->album_gain_string) entry->album_gain_string += offset; -#endif } void copy_mp3entry(struct mp3entry *dest, struct mp3entry *orig) Index: firmware/sound.c =================================================================== --- firmware/sound.c (revision 14672) +++ firmware/sound.c (working copy) @@ -32,6 +32,8 @@ #include "system.h" #if CONFIG_CODEC == SWCODEC #include "pcm_playback.h" +#else +#include "replaygain.h" #endif #endif @@ -363,6 +365,19 @@ #if CONFIG_CODEC != SWCODEC int channel_configuration = SOUND_CHAN_STEREO; int stereo_width = 100; + +bool replaygain_noclip=false; /* scale to prevent clips */ +int replaygain_type=3; /* 0=track gain, 1=album gain, (2=track gain if shuffle), 3=disable replaygain*/ +long replaygain_preamp=0; /* -120cB to +120cB */ +long replaygain_trackgain=0; /* 7.24 signed fixed point. 0 for no gain/peak */ +long replaygain_trackpeak=0; +long replaygain_albumgain=0; +long replaygain_albumpeak=0; +/* copied from dsp.c */ +#define DEFAULT_GAIN 0x01000000 +/* copied from settings.h */ +enum { REPLAYGAIN_TRACK = 0, REPLAYGAIN_ALBUM, REPLAYGAIN_SHUFFLE }; + #endif #ifndef SIMULATOR @@ -370,21 +385,86 @@ #if CONFIG_CODEC != SWCODEC static void set_channel_config(void) { - /* default values: stereo */ - unsigned long val_ll = 0x80000; - unsigned long val_lr = 0; - unsigned long val_rl = 0; - unsigned long val_rr = 0x80000; + /* So that noclip can work even with no gain information. */ + unsigned long gain = DEFAULT_GAIN; + + /* default value, used while replaygain is deactivated */ + long mas_gain =0x80000; + + if (replaygain_type!=3) + { + /* + * REPLAYGAIN_SHUFFLE should never be set, because if it was, + * 'playlist_shuffle' would need to be checked here, too. + * Instead just set REPLAYGAIN_TRACK as Parameter to + * sound_set_replaygain_type() if 'playlist_shuffle' is also set + */ + + if ((replaygain_type==REPLAYGAIN_TRACK) || !replaygain_albumgain) + { + gain = (replaygain_trackgain) ? replaygain_trackgain : DEFAULT_GAIN; + } else { + gain = replaygain_albumgain; + } + + if (replaygain_preamp) + { + long preamp = get_replaygain_int( + replaygain_preamp * 10); + + gain = (((int64_t) gain * preamp) >> 24); + } + + /* divide by 8 to get into [0.0 .. 1.0] scale*/ + gain >>=3; + + /* If overall gain was more than about +18dB, I put a lid on it, + * because gain >1 results in lower volume again */ + if (gain>DEFAULT_GAIN) + { + gain=DEFAULT_GAIN; + } + + /* calculate the value for the MAS register*/ + mas_gain=((0xFFFFFFFFFFF80000ll * (int64_t)gain)>>24)&0xFFFFF; + + } + +/* Since the MAS is only used for attenuation, "noclip" doesn't make much sense.*/ +/* long peak = ((replaygain_type==REPLAYGAIN_TRACK) || !replaygain_albumpeak) + ? replaygain_trackpeak : replaygain_albumpeak; + if (replaygain_noclip && (peak != 0) + && ((((int64_t) gain * peak) >> 24) >= DEFAULT_GAIN)) + { + gain = (((int64_t) DEFAULT_GAIN << 24) / peak); + } +*/ + + /* default case SOUND_CHAN_STEREO */ + long val_ll = mas_gain; + long val_lr = 0; + long val_rl = 0; + long val_rr = mas_gain; + + switch(channel_configuration) { /* case SOUND_CHAN_STEREO unnecessary */ case SOUND_CHAN_MONO: - val_ll = 0xc0000; - val_lr = 0xc0000; - val_rl = 0xc0000; - val_rr = 0xc0000; + /* calculate the value for the MAS register - Probably could be done by bit-wise operations... */ + if (gain!=DEFAULT_GAIN) + { + mas_gain=((0xFFFFFFFFFFFC0000ll * (int64_t)gain)>>24)&0xFFFFF; + } else { + mas_gain=0xC0000; + } + + val_ll = mas_gain; + val_lr = mas_gain; + val_rl = mas_gain; + val_rr = mas_gain; break; case SOUND_CHAN_CUSTOM: @@ -406,14 +486,15 @@ fp_straight = - ((((1<<19) + fp_width) / (fp_width >> 9)) << 9); fp_cross = (1<<19) + fp_straight; } - val_ll = val_rr = fp_straight & 0xfffff; - val_lr = val_rl = fp_cross & 0xfffff; + /* no use for if-then-else since calculations take place anyway */ + val_ll = val_rr = (((int64_t)fp_straight*gain)>>24) & 0xfffff; + val_lr = val_rl = (((int64_t)fp_cross*gain)>>24) & 0xfffff; } break; case SOUND_CHAN_MONO_LEFT: - val_ll = 0x80000; - val_lr = 0x80000; + val_ll = mas_gain; + val_lr = mas_gain; val_rl = 0; val_rr = 0; break; @@ -421,15 +502,29 @@ case SOUND_CHAN_MONO_RIGHT: val_ll = 0; val_lr = 0; - val_rl = 0x80000; - val_rr = 0x80000; + val_rl = mas_gain; + val_rr = mas_gain; break; case SOUND_CHAN_KARAOKE: - val_ll = 0xc0000; - val_lr = 0x40000; - val_rl = 0x40000; - val_rr = 0xc0000; + /* calculate the value for the MAS register - Probably could be done by bit-wise operations... */ + if (gain!=DEFAULT_GAIN) + { + mas_gain=((0xFFFFFFFFFFFC0000ll * (int64_t)gain)>>24)&0xFFFFF; + } else { + mas_gain=0xC0000; + } + val_ll = mas_gain; + val_rr = mas_gain; + /* calculate the value for the MAS register - Probably could be done by bit-wise operations... */ + if (gain!=DEFAULT_GAIN) + { + mas_gain=((0xFFFFFFFFFFF40000ll * (int64_t)gain)>>24)&0xFFFFF; + } else { + mas_gain=0x40000; + } + val_lr = mas_gain; + val_rl = mas_gain; break; } @@ -576,6 +671,105 @@ #endif } +void sound_set_replaygain(void) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + set_channel_config(); +#endif +} + +/* Remember to call sound_set_replaygain() after changing some values + * with the following functions. Since usually there are 3 to 4 of them + * called one after the other, it would be redundant to call + * set_channel_config() from within them. + */ + +void sound_set_replaygain_noclip(bool value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_noclip = value; +#endif +} + +/* This should only be used to set + * REPLAYGAIN_TRACKGAIN or REPLAYGAIN_ALBUMGAIN + * To allow setting REPLAYGAIN_SHUFFLE, 'playlist_shuffle' + * would also need to be relayed here. + * 3 is an allowed value to turn off Replaygain. + */ +void sound_set_replaygain_type(int value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_type = value; +#endif +} + +void sound_set_replaygain_preamp(int value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_preamp = value; +#endif +} + +void sound_set_replaygain_trackgain(long value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_trackgain = value; +#endif +} + +void sound_set_replaygain_trackpeak(long value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_trackpeak = value; +#endif +} + +void sound_set_replaygain_albumgain(long value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_albumgain = value; +#endif +} + +void sound_set_replaygain_albumpeak(long value) +{ +#if CONFIG_CODEC == SWCODEC +#else + if(!audio_is_initialized) + return; + + replaygain_albumpeak = value; +#endif +} + #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) void sound_set_loudness(int value) { @@ -694,6 +888,46 @@ (void)value; } +void sound_set_replaygain(void) +{ + (void)value; +} + +void sound_set_replaygain_noclip(bool value) +{ + (void)value; +} + +void sound_set_replaygain_type(int value) +{ + (void)value; +} + +void sound_set_replaygain_preamp(int value) +{ + (void)value; +} + +void sound_set_replaygain_trackgain(long value) +{ + (void)value; +} + +void sound_set_replaygain_trackpeak(long value) +{ + (void)value; +} + +void sound_set_replaygain_albumgain(long value) +{ + (void)value; +} + +void sound_set_replaygain_albumpeak(long value) +{ + (void)value; +} + #if (CONFIG_CODEC == MAS3587F) || (CONFIG_CODEC == MAS3539F) void sound_set_loudness(int value) { Index: firmware/SOURCES =================================================================== --- firmware/SOURCES (revision 14672) +++ firmware/SOURCES (working copy) @@ -173,12 +173,12 @@ mp3data.c sound.c +replaygain.c #if CONFIG_CODEC == SWCODEC #ifndef BOOTLOADER general.c pcm_sampr.c -replaygain.c #ifndef SIMULATOR pcm_playback.c #endif /* SIMULATOR */ Index: firmware/mpeg.c =================================================================== --- firmware/mpeg.c (revision 14672) +++ firmware/mpeg.c (working copy) @@ -946,6 +946,18 @@ return track; } +static void update_replaygain(void) +{ + struct mp3entry* id3 = &get_trackdata(0)->id3; + + sound_set_replaygain_trackgain(id3->track_gain); + sound_set_replaygain_trackpeak(id3->track_peak); + sound_set_replaygain_albumgain(id3->album_gain); + sound_set_replaygain_albumpeak(id3->album_peak); + sound_set_replaygain(); +} + + static int new_file(int steps) { int max_steps = playlist_amount(); @@ -1092,6 +1104,7 @@ check_playlist_end(1); } + update_replaygain(); playlist_update_resume_info(audio_current_track()); }