mirror of
https://gitee.com/openharmony/third_party_ffmpeg
synced 2024-11-23 11:19:55 +00:00
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
This commit is contained in:
parent
6858ce2ffc
commit
b1078e9fe6
@ -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
|
||||
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -424,16 +424,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)
|
||||
*
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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.);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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++;
|
||||
|
@ -144,6 +144,17 @@ static inline av_const int16_t av_clip_int16(int a)
|
||||
else return 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
|
||||
|
Loading…
Reference in New Issue
Block a user