From: Stefan L. <lu...@us...> - 2003-09-23 04:50:27
|
Update of /cvsroot/libdv/libdv/libdv In directory sc8-pr-cvs1:/tmp/cvs-serv22858/libdv Modified Files: audio.c audio.h dv.c dv_types.h Log Message: keep deemphasis filter state Index: audio.c =================================================================== RCS file: /cvsroot/libdv/libdv/libdv/audio.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** audio.c 7 Jul 2003 20:33:26 -0000 1.17 --- audio.c 23 Sep 2003 04:50:16 -0000 1.18 *************** *** 90,95 **** }; ! static int frequency[3] = { ! 48000, 44100, 32000 }; --- 90,95 ---- }; ! static int frequency[8] = { ! 48000, 44100, 32000, -3, -4, -5, -6, -7 }; *************** *** 524,558 **** to Arne Schirmacher <ar...@sc...>. */ void ! dv_audio_deemphasis(dv_audio_t *audio, int16_t *outbuf) { ! int i; ! /* this implements an attenuation treble shelving filter ! to undo the effect of pre-emphasis. The filter is of ! a recursive first order */ ! /* static */ short lastin[2] = { 0, 0 }; ! /* static */ double lastout[2] = { 0.0, 0.0 }; ! short *pmm; ! /* See deemphasis.gnuplot */ ! double V0 = 0.3365; ! double OMEGAG = (1./19e-6); ! double T = (1./audio->frequency); ! double H0 = (V0-1.); ! double B = (V0*tan((OMEGAG * T)/2.0)); ! double a1 = ((B - 1.)/(B + 1.)); ! double b0 = (1.0 + (1.0 - a1) * H0/2.0); ! double b1 = (a1 + (a1 - 1.0) * H0/2.0); ! ! /* For 48Khz: a1= -0.659065 b0= 0.449605 b1= -0.108670 ! * For 44.1Khz: a1=-0.62786881719628784282 b0= 0.45995451989513153057 b1=-0.08782333709141937339 ! * For 32kHZ ? */ ! ! for (pmm = (short *)outbuf, i=0; ! i < audio->raw_samples_this_frame [0]; /* TODO: check for second channel */ ! i++) { ! lastout[0] = *pmm * b0 + lastin[0] * b1 - lastout[0] * a1; ! lastin[0] = *pmm; ! *pmm++ = lastout[0] > 0.0 ? lastout[0] + 0.5 : lastout[0] - 0.5; ! } /* for */ ! } /* dv_audio_deemphasis */ --- 524,570 ---- to Arne Schirmacher <ar...@sc...>. */ void ! dv_audio_deemphasis(dv_audio_t *audio, int16_t **outbuf) { ! int i, ch; ! /* this implements an attenuation treble shelving filter ! to undo the effect of pre-emphasis. The filter is of ! a recursive first order */ ! short lastin; ! double lastout; ! short *pmm; ! /* See deemphasis.gnuplot */ ! double V0 = 0.3365; ! double OMEGAG = (1./19e-6); ! double T = (1./audio->frequency); ! double H0 = (V0-1.); ! double B = (V0*tan((OMEGAG * T)/2.0)); ! double a1 = ((B - 1.)/(B + 1.)); ! double b0 = (1.0 + (1.0 - a1) * H0/2.0); ! double b1 = (a1 + (a1 - 1.0) * H0/2.0); ! ! if (audio->emphasis) { ! for (ch=0; ch< audio->raw_num_channels; ch++) { ! /* --------------------------------------------------------------------- ! * For 48Khz: a1=-0.659065 ! * b0= 0.449605 ! * b1=-0.108670 ! * For 44.1Khz: a1=-0.62786881719628784282 ! * b0= 0.45995451989513153057 ! * b1=-0.08782333709141937339 ! * For 32kHZ ? ! */ ! lastin = audio->lastin [ch]; ! lastout = audio->lastout [ch]; ! for (pmm = (short *)outbuf [ch], i=0; ! i < audio->raw_samples_this_frame [0]; /* TODO: check for second channel */ ! i++) { ! lastout = *pmm * b0 + lastin * b1 - lastout * a1; ! lastin = *pmm; ! *pmm++ = (lastout > 0.0) ? lastout + 0.5 : lastout - 0.5; ! } /* for (pmn = .. */ ! audio->lastout [ch] = lastout; ! audio->lastin [ch] = lastin; ! } /* for (ch = .. */ ! } /* if (audio -> .. */ } /* dv_audio_deemphasis */ Index: audio.h =================================================================== RCS file: /cvsroot/libdv/libdv/libdv/audio.h,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -r1.6 -r1.7 *** audio.h 13 Jun 2003 17:03:31 -0000 1.6 --- audio.h 23 Sep 2003 04:50:17 -0000 1.7 *************** *** 1,3 **** ! /* * audio.h * --- 1,3 ---- ! /* * audio.h * *************** *** 38,42 **** extern int dv_update_num_samples(dv_audio_t *dv_audio, const uint8_t *inbuf); extern int dv_decode_audio_block(dv_audio_t *dv_audio, const uint8_t *buffer, int ds, int audio_dif, int16_t **outbufs); ! extern void dv_audio_deemphasis(dv_audio_t *dv_audio, int16_t *outbuf); extern void dv_dump_aaux_as(void *buffer, int ds, int audio_dif); extern void dv_audio_correct_errors (dv_audio_t *dv_audio, int16_t **outbufs); --- 38,42 ---- extern int dv_update_num_samples(dv_audio_t *dv_audio, const uint8_t *inbuf); extern int dv_decode_audio_block(dv_audio_t *dv_audio, const uint8_t *buffer, int ds, int audio_dif, int16_t **outbufs); ! extern void dv_audio_deemphasis(dv_audio_t *dv_audio, int16_t **outbuf); extern void dv_dump_aaux_as(void *buffer, int ds, int audio_dif); extern void dv_audio_correct_errors (dv_audio_t *dv_audio, int16_t **outbufs); Index: dv.c =================================================================== RCS file: /cvsroot/libdv/libdv/libdv/dv.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -r1.17 -r1.18 *** dv.c 7 Jul 2003 20:33:26 -0000 1.17 --- dv.c 23 Sep 2003 04:50:17 -0000 1.18 *************** *** 587,595 **** } ! if(dv->audio->emphasis) { ! for(ch=0; ch< dv->audio->raw_num_channels; ch++) { ! dv_audio_deemphasis(dv->audio, outbufs[ch]); ! } /* for */ ! } /* if */ dv_audio_mix4ch (dv -> audio, outbufs); --- 587,591 ---- } ! dv_audio_deemphasis (dv -> audio, outbufs); dv_audio_mix4ch (dv -> audio, outbufs); Index: dv_types.h =================================================================== RCS file: /cvsroot/libdv/libdv/libdv/dv_types.h,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -r1.19 -r1.20 *** dv_types.h 7 Jul 2003 20:33:26 -0000 1.19 --- dv_types.h 23 Sep 2003 04:50:17 -0000 1.20 *************** *** 421,424 **** --- 421,430 ---- real_samples_this_frame, fail_samples_this_frame; + /* ------------------------------------------------------------------------- + * memorize deemphasis values + */ + short lastin [4]; + double lastout [4]; + FILE *error_log; dv_decoder_tp dv_decoder; |