diff -u -r rockbox-orig/apps/codecs/mpa.c rockbox/apps/codecs/mpa.c --- rockbox-orig/apps/codecs/mpa.c 2011-01-10 16:35:44.000000000 +0100 +++ rockbox/apps/codecs/mpa.c 2011-01-18 16:02:02.409287750 +0100 @@ -25,6 +25,8 @@ CODEC_HEADER +#define GAP_SKIP_THRESH 5000000 + #if NUM_CORES > 1 && !defined(MPEGPLAYER) #define MPA_SYNTH_ON_COP #endif @@ -449,7 +451,34 @@ mad_synth_thread_wait_pcm(); if (framelength > 0) { - + + /* if this was the first frame and we are doing gap skipping, + find the first non-gap sample, and adjust samples_to_skip + accordingly */ + + /* this should catch cases where lead_trim was not set by way of the + id3 tag. There is a small chance it would happen to match, in + which case we might chop off up to 1 frame that was not intended + to be chopped off. If this is unacceptable, we could use another + variable to detect this case. */ + + if ( samples_to_skip == mpeg_latency[ci->id3->layer] && + ci->global_settings->gap_skip ) { + int ss_tmp; + ss_tmp = samples_to_skip; + while (synth.pcm.samples[0][samples_to_skip] < GAP_SKIP_THRESH && + synth.pcm.samples[0][samples_to_skip] > -GAP_SKIP_THRESH && + synth.pcm.samples[1][samples_to_skip] < GAP_SKIP_THRESH && + synth.pcm.samples[1][samples_to_skip] > -GAP_SKIP_THRESH && + samples_to_skip < mpeg_framesize[ci->id3->layer]) + { + samples_to_skip++; + } + /* adjust the frame length by the samples we skipped */ + framelength -= (samples_to_skip - ss_tmp); + } + + /* In case of a mono file, the second array will be ignored. */ ci->pcmbuf_insert(&synth.pcm.samples[0][samples_to_skip], &synth.pcm.samples[1][samples_to_skip], @@ -500,7 +529,26 @@ /* Finish the remaining decoded frame. Cut the required samples from the end. */ + + /* If we have enabled gap skipping and the LAME header + didn't already tell us to skip the end of the last frame, + search backward from the end to find non-zero samples */ + if (framelength > stop_skip){ + if ( ! stop_skip && ci->global_settings->gap_skip ) { + while ( synth.pcm.samples[0][framelength-stop_skip-1] < + GAP_SKIP_THRESH && + synth.pcm.samples[0][framelength-stop_skip-1] > + -GAP_SKIP_THRESH && + synth.pcm.samples[1][framelength-stop_skip-1] < + GAP_SKIP_THRESH && + synth.pcm.samples[1][framelength-stop_skip-1] > + -GAP_SKIP_THRESH && + stop_skip < framelength ) + { + stop_skip++; + } + } ci->pcmbuf_insert(synth.pcm.samples[0], synth.pcm.samples[1], framelength - stop_skip); } diff -u -r rockbox-orig/apps/lang/english.lang rockbox/apps/lang/english.lang --- rockbox-orig/apps/lang/english.lang 2011-01-10 16:35:25.000000000 +0100 +++ rockbox/apps/lang/english.lang 2011-01-14 21:11:33.730514352 +0100 @@ -12713,3 +12713,17 @@ *: "Yes (requires initialized database)" + + id: LANG_GAP_SKIP + desc: gap skip playback menu + user: core + + *: "MP3 gap skip" + + + *: "MP3 gap skip" + + + *: "MP3 gap skip" + + diff -u -r rockbox-orig/apps/menus/playback_menu.c rockbox/apps/menus/playback_menu.c --- rockbox-orig/apps/menus/playback_menu.c 2011-01-10 16:35:27.000000000 +0100 +++ rockbox/apps/menus/playback_menu.c 2011-01-18 15:08:56.766444751 +0100 @@ -60,6 +60,7 @@ static int playback_callback(int action,const struct menu_item_ex *this_item); MENUITEM_SETTING(shuffle_item, &global_settings.playlist_shuffle, playback_callback); +MENUITEM_SETTING(gap_skip, &global_settings.gap_skip, playback_callback); MENUITEM_SETTING(repeat_mode, &global_settings.repeat_mode, playback_callback); MENUITEM_SETTING(play_selected, &global_settings.play_selected, NULL); @@ -183,7 +184,7 @@ MAKE_MENU(playback_settings,ID2P(LANG_PLAYBACK),0, Icon_Playback_menu, - &shuffle_item, &repeat_mode, &play_selected, + &shuffle_item, &gap_skip, &repeat_mode, &play_selected, &ff_rewind_settings_menu, #ifdef HAVE_DISK_STORAGE &buffer_margin, diff -u -r rockbox-orig/apps/settings.h rockbox/apps/settings.h --- rockbox-orig/apps/settings.h 2011-01-10 16:35:46.000000000 +0100 +++ rockbox/apps/settings.h 2011-01-18 15:09:25.657482970 +0100 @@ -595,6 +595,7 @@ /* playlist/playback settings */ int repeat_mode; /* 0=off 1=repeat all 2=repeat one 3=shuffle 4=ab */ + bool gap_skip; /* try to skip extra gaps at begin/end of mp3 tracks */ int next_folder; /* move to next folder */ int recursive_dir_insert; /* should directories be inserted recursively */ bool fade_on_stop; /* fade on pause/unpause/stop */ diff -u -r rockbox-orig/apps/settings_list.c rockbox/apps/settings_list.c --- rockbox-orig/apps/settings_list.c 2011-01-10 16:35:46.000000000 +0100 +++ rockbox/apps/settings_list.c 2011-01-12 21:31:49.000000000 +0100 @@ -654,6 +654,7 @@ OFFON_SETTING(0, playlist_shuffle, LANG_SHUFFLE, false, "shuffle", NULL), SYSTEM_SETTING(NVRAM(4), resume_index, -1), SYSTEM_SETTING(NVRAM(4), resume_offset, -1), + OFFON_SETTING(0, gap_skip, LANG_GAP_SKIP, false, "gap skip", NULL), CHOICE_SETTING(0, repeat_mode, LANG_REPEAT, REPEAT_OFF, "repeat", "off,all,one,shuffle" #ifdef AB_REPEAT_ENABLE