# HG changeset patch # User arpi # Date 1011229881 0 # Node ID c92c23a42e91e065b819da89af54734a29f18e3d # Parent 1427d0f1f2d6e10c137de9b0ae0a9f92d249a29a libmad memcpy optimization by Jeroen Dobbelaere <jeroen.dobbelaere@acunia.com> diff -r 1427d0f1f2d6 -r c92c23a42e91 dec_audio.c --- a/dec_audio.c Thu Jan 17 01:02:41 2002 +0000 +++ b/dec_audio.c Thu Jan 17 01:11:21 2002 +0000 @@ -101,9 +101,14 @@ #ifdef USE_LIBMAD #include <mad.h> + +#define MAD_SINGLE_BUFFER_SIZE 8192 +#define MAD_TOTAL_BUFFER_SIZE ((MAD_SINGLE_BUFFER_SIZE)*3) + static struct mad_stream mad_stream; static struct mad_frame mad_frame; static struct mad_synth mad_synth; +static char* mad_in_buffer = 0; /* base pointer of buffer */ // ensure buffer is filled with some data static void mad_prepare_buffer(sh_audio_t* sh_audio, struct mad_stream* ms, int length) @@ -117,14 +122,19 @@ static void mad_postprocess_buffer(sh_audio_t* sh_audio, struct mad_stream* ms) { + /* rotate buffer while possible, in order to reduce the overhead of endless memcpy */ int delta = (unsigned char*)ms->next_frame - (unsigned char *)sh_audio->a_in_buffer; - if(delta != 0) { + if((unsigned long)(sh_audio->a_in_buffer) - (unsigned long)mad_in_buffer < + (MAD_TOTAL_BUFFER_SIZE - MAD_SINGLE_BUFFER_SIZE - delta)) { + sh_audio->a_in_buffer += delta; + sh_audio->a_in_buffer_len -= delta; + } else { + sh_audio->a_in_buffer = mad_in_buffer; sh_audio->a_in_buffer_len -= delta; memcpy(sh_audio->a_in_buffer, ms->next_frame, sh_audio->a_in_buffer_len); } } - static inline signed short mad_scale(mad_fixed_t sample) { @@ -449,9 +459,9 @@ case AFM_MAD: printf(__FILE__ ":%d:mad: setting minimum outputsize\n", __LINE__); sh_audio->audio_out_minsize=4608; - if(sh_audio->audio_in_minsize<8192) sh_audio->audio_in_minsize=8192; + if(sh_audio->audio_in_minsize<MAD_SINGLE_BUFFER_SIZE) sh_audio->audio_in_minsize=MAD_SINGLE_BUFFER_SIZE; sh_audio->a_in_buffer_size=sh_audio->audio_in_minsize; - sh_audio->a_in_buffer=malloc(sh_audio->a_in_buffer_size); + mad_in_buffer = sh_audio->a_in_buffer = malloc(MAD_TOTAL_BUFFER_SIZE); sh_audio->a_in_buffer_len=0; break; #endif