diff options
author | Ronald S. Bultje <rsbultje@gmail.com> | 2010-04-21 17:57:48 +0000 |
---|---|---|
committer | Ronald S. Bultje <rsbultje@gmail.com> | 2010-04-21 17:57:48 +0000 |
commit | b1078e9fe6b5d8f034d15a6ab91430fd41921fe2 (patch) | |
tree | 5d16af4805e9567267f3f3daa96e015523f4216c | |
parent | 6858ce2ffc4c57a279b22ab6d8eb56ac3884796e (diff) | |
download | ffmpeg-b1078e9fe6b5d8f034d15a6ab91430fd41921fe2.tar.gz |
Move clipping of audio samples (for those codecs outputting float) from decoder
to the audio conversion routines.
Originally committed as revision 22937 to svn://svn.ffmpeg.org/ffmpeg/trunk
-rw-r--r-- | libavcodec/amrnbdec.c | 12 | ||||
-rw-r--r-- | libavcodec/atrac1.c | 13 | ||||
-rw-r--r-- | libavcodec/audioconvert.c | 14 | ||||
-rw-r--r-- | libavcodec/qcelpdata.h | 10 | ||||
-rw-r--r-- | libavcodec/qcelpdec.c | 4 | ||||
-rw-r--r-- | libavcodec/ra288.c | 4 | ||||
-rw-r--r-- | libavcodec/sipr.c | 3 | ||||
-rw-r--r-- | libavcodec/sipr16k.c | 3 | ||||
-rw-r--r-- | libavcodec/twinvq.c | 3 | ||||
-rw-r--r-- | libavcodec/wmaprodec.c | 3 | ||||
-rw-r--r-- | libavcodec/wmavoice.c | 3 | ||||
-rw-r--r-- | libavutil/common.h | 11 |
12 files changed, 28 insertions, 55 deletions
diff --git a/libavcodec/amrnbdec.c b/libavcodec/amrnbdec.c index 40cd91d110..cd2d95b11b 100644 --- a/libavcodec/amrnbdec.c +++ b/libavcodec/amrnbdec.c @@ -796,7 +796,7 @@ static int synthesis(AMRContext *p, float *lpc, float fixed_gain, const float *fixed_vector, float *samples, uint8_t overflow) { - int i, overflow_temp = 0; + int i; float excitation[AMR_SUBFRAME_SIZE]; // if an overflow has been detected, the pitch vector is scaled down by a @@ -831,12 +831,10 @@ static int synthesis(AMRContext *p, float *lpc, // detect overflow for (i = 0; i < AMR_SUBFRAME_SIZE; i++) if (fabsf(samples[i]) > AMR_SAMPLE_BOUND) { - overflow_temp = 1; - samples[i] = av_clipf(samples[i], -AMR_SAMPLE_BOUND, - AMR_SAMPLE_BOUND); + return 1; } - return overflow_temp; + return 0; } /// @} @@ -1048,10 +1046,6 @@ static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, highpass_poles, highpass_gain, p->high_pass_mem, AMR_BLOCK_SIZE); - for (i = 0; i < AMR_BLOCK_SIZE; i++) - buf_out[i] = av_clipf(buf_out[i] * AMR_SAMPLE_SCALE, - -1.0, 32767.0 / 32768.0); - /* Update averaged lsf vector (used for fixed gain smoothing). * * Note that lsf_avg should not incorporate the current frame's LSFs diff --git a/libavcodec/atrac1.c b/libavcodec/atrac1.c index 6159954966..5ff8816476 100644 --- a/libavcodec/atrac1.c +++ b/libavcodec/atrac1.c @@ -305,20 +305,15 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data, at1_subband_synthesis(q, su, q->out_samples[ch]); } - /* round, convert to 16bit and interleave */ + /* interleave; FIXME, should create/use a DSP function */ if (q->channels == 1) { /* mono */ - q->dsp.vector_clipf(samples, q->out_samples[0], -32700.0 / (1 << 15), - 32700.0 / (1 << 15), AT1_SU_SAMPLES); + memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4); } else { /* stereo */ for (i = 0; i < AT1_SU_SAMPLES; i++) { - samples[i * 2] = av_clipf(q->out_samples[0][i], - -32700.0 / (1 << 15), - 32700.0 / (1 << 15)); - samples[i * 2 + 1] = av_clipf(q->out_samples[1][i], - -32700.0 / (1 << 15), - 32700.0 / (1 << 15)); + samples[i * 2] = q->out_samples[0][i]; + samples[i * 2 + 1] = q->out_samples[1][i]; } } diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c index 8ea7158ce4..a38d87351f 100644 --- a/libavcodec/audioconvert.c +++ b/libavcodec/audioconvert.c @@ -209,7 +209,7 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\ } //FIXME put things below under ifdefs so we do not waste space for cases no codec will need -//FIXME rounding and clipping ? +//FIXME rounding ? CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_U8 , *(const uint8_t*)pi) else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8) @@ -226,14 +226,14 @@ if(ctx->fmt_pair == ofmt + SAMPLE_FMT_NB*ifmt){\ else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_S32, *(const int32_t*)pi) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) - else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<7)) + 0x80) - else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<15))) - else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, lrintf(*(const float*)pi * (1<<31))) + else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) + else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) + else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_FLT, *(const float*)pi) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_FLT, *(const float*)pi) - else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<7)) + 0x80) - else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<15))) - else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, lrint(*(const double*)pi * (1<<31))) + else CONV(SAMPLE_FMT_U8 , uint8_t, SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80)) + else CONV(SAMPLE_FMT_S16, int16_t, SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15)))) + else CONV(SAMPLE_FMT_S32, int32_t, SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31)))) else CONV(SAMPLE_FMT_FLT, float , SAMPLE_FMT_DBL, *(const double*)pi) else CONV(SAMPLE_FMT_DBL, double , SAMPLE_FMT_DBL, *(const double*)pi) else return -1; diff --git a/libavcodec/qcelpdata.h b/libavcodec/qcelpdata.h index 52be252d1c..d79cea9f6c 100644 --- a/libavcodec/qcelpdata.h +++ b/libavcodec/qcelpdata.h @@ -425,16 +425,6 @@ static const qcelp_vector * const qcelp_lspvq[5] = { #define QCELP_SCALE 8192. /** - * the upper boundary of the clipping, depends on QCELP_SCALE - */ -#define QCELP_CLIP_UPPER_BOUND (8191.75/8192.) - -/** - * the lower boundary of the clipping, depends on QCELP_SCALE - */ -#define QCELP_CLIP_LOWER_BOUND -1. - -/** * table for computing Ga (decoded linear codebook gain magnitude) * * @note The table could fit in int16_t in x*8 form, but it seems diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c index 25ef324475..97785adb96 100644 --- a/libavcodec/qcelpdec.c +++ b/libavcodec/qcelpdec.c @@ -834,10 +834,6 @@ erasure: memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float)); - for(i=0; i<160; i++) - outbuffer[i] = av_clipf(outbuffer[i], QCELP_CLIP_LOWER_BOUND, - QCELP_CLIP_UPPER_BOUND); - memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); q->prev_bitrate = q->bitrate; diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c index c74b5f78df..20a21f5dc7 100644 --- a/libavcodec/ra288.c +++ b/libavcodec/ra288.c @@ -102,10 +102,6 @@ static void decode(RA288Context *ractx, float gain, int cb_coef) gain_block[9] = 10 * log10(sum) - 32; ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36); - - /* output */ - for (i=0; i < 5; i++) - block[i] = av_clipf(block[i], -4095./4096., 4095./4096.); } /** diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c index d409484b61..b76e89100f 100644 --- a/libavcodec/sipr.c +++ b/libavcodec/sipr.c @@ -496,9 +496,6 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params, 0.939805806, ctx->highpass_filt_mem, frame_size); - - ctx->dsp.vector_clipf(out_data, out_data, -1, 32767./(1<<15), frame_size); - } static av_cold int sipr_decoder_init(AVCodecContext * avctx) diff --git a/libavcodec/sipr16k.c b/libavcodec/sipr16k.c index f6859b166a..7fb9252927 100644 --- a/libavcodec/sipr16k.c +++ b/libavcodec/sipr16k.c @@ -264,9 +264,6 @@ void ff_sipr_decode_frame_16k(SiprContext *ctx, SiprParameters *params, postfilter(out_data, synth, ctx->iir_mem, ctx->filt_mem, ctx->mem_preemph); memcpy(ctx->iir_mem, Az[1], LP_FILTER_ORDER_16k * sizeof(float)); - - ctx->dsp.vector_clipf(out_data, out_data, -1, 32767./(1<<15), frame_size); - } void ff_sipr_init_16k(SiprContext *ctx) diff --git a/libavcodec/twinvq.c b/libavcodec/twinvq.c index 1aa66661d6..6ab3a465d9 100644 --- a/libavcodec/twinvq.c +++ b/libavcodec/twinvq.c @@ -850,9 +850,6 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data, return buf_size; } - tctx->dsp.vector_clipf(out, out, -32700./(1<<15), 32700./(1<<15), - avctx->channels * mtab->size); - *data_size = mtab->size*avctx->channels*4; return buf_size; diff --git a/libavcodec/wmaprodec.c b/libavcodec/wmaprodec.c index 71bf0f72b3..3eca10150a 100644 --- a/libavcodec/wmaprodec.c +++ b/libavcodec/wmaprodec.c @@ -1351,8 +1351,9 @@ static int decode_frame(WMAProDecodeCtx *s) float* iptr = s->channel[i].out; float* iend = iptr + s->samples_per_frame; + // FIXME should create/use a DSP function here while (iptr < iend) { - *ptr = av_clipf(*iptr++, -1.0, 32767.0 / 32768.0); + *ptr = *iptr++; ptr += incr; } diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c index 0d81d58bd4..97dabd2526 100644 --- a/libavcodec/wmavoice.c +++ b/libavcodec/wmavoice.c @@ -1117,8 +1117,7 @@ static int synth_frame(AVCodecContext *ctx, GetBitContext *gb, av_log_missing_feature(ctx, "APF", 0); s->do_apf = 0; } //else - for (n = 0; n < 160; n++) - samples[n] = av_clipf(synth[n], -1.0, 1.0); + memcpy(samples, synth, 160 * sizeof(synth[0])); /* Cache values for next frame */ s->frame_cntr++; diff --git a/libavutil/common.h b/libavutil/common.h index 11ae368826..8d7cc10012 100644 --- a/libavutil/common.h +++ b/libavutil/common.h @@ -145,6 +145,17 @@ static inline av_const int16_t av_clip_int16(int a) } /** + * Clips a signed 64-bit integer value into the -2147483648,2147483647 range. + * @param a value to clip + * @return clipped value + */ +static inline av_const int32_t av_clipl_int32(int64_t a) +{ + if ((a+2147483648) & ~2147483647) return (a>>63) ^ 2147483647; + else return a; +} + +/** * Clips a float value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range |