63 const int16_t *consts,
77 t1[i >> 1] += in[hop + i] * consts[hop + i];
83 memset(t1, 0,
sizeof(t1));
86 for (i = 0; i < subbands/2; i++)
88 t1[j>>1] += t2[i * 2 + (j&1)] * consts[10*subbands + i*2*subbands + j];
95 const int16_t *consts)
101 const int16_t *consts)
166 int nsamples,
int nchannels)
171 if (position < nsamples) {
172 for (c = 0; c < nchannels; c++)
173 memcpy(&
X[c][SBC_X_BUFFER_SIZE - 40], &
X[c][position],
174 36 *
sizeof(int16_t));
175 position = SBC_X_BUFFER_SIZE - 40;
179 for (; nsamples >= 8; nsamples -= 8, pcm += 16 * nchannels) {
181 for (c = 0; c < nchannels; c++) {
182 int16_t *x = &
X[
c][position];
183 x[0] =
AV_RN16(pcm + 14*nchannels + 2*c);
184 x[1] =
AV_RN16(pcm + 6*nchannels + 2*c);
185 x[2] =
AV_RN16(pcm + 12*nchannels + 2*c);
186 x[3] =
AV_RN16(pcm + 8*nchannels + 2*c);
187 x[4] =
AV_RN16(pcm + 0*nchannels + 2*c);
188 x[5] =
AV_RN16(pcm + 4*nchannels + 2*c);
189 x[6] =
AV_RN16(pcm + 2*nchannels + 2*c);
190 x[7] =
AV_RN16(pcm + 10*nchannels + 2*c);
199 int nsamples,
int nchannels)
204 if (position < nsamples) {
205 for (c = 0; c < nchannels; c++)
206 memcpy(&
X[c][SBC_X_BUFFER_SIZE - 72], &
X[c][position],
207 72 *
sizeof(int16_t));
208 position = SBC_X_BUFFER_SIZE - 72;
211 if (position % 16 == 8) {
214 for (c = 0; c < nchannels; c++) {
215 int16_t *x = &
X[
c][position];
216 x[0] =
AV_RN16(pcm + 14*nchannels + 2*c);
217 x[2] =
AV_RN16(pcm + 12*nchannels + 2*c);
218 x[3] =
AV_RN16(pcm + 0*nchannels + 2*c);
219 x[4] =
AV_RN16(pcm + 10*nchannels + 2*c);
220 x[5] =
AV_RN16(pcm + 2*nchannels + 2*c);
221 x[6] =
AV_RN16(pcm + 8*nchannels + 2*c);
222 x[7] =
AV_RN16(pcm + 4*nchannels + 2*c);
223 x[8] =
AV_RN16(pcm + 6*nchannels + 2*c);
225 pcm += 16 * nchannels;
229 for (; nsamples >= 16; nsamples -= 16, pcm += 32 * nchannels) {
231 for (c = 0; c < nchannels; c++) {
232 int16_t *x = &
X[
c][position];
233 x[0] =
AV_RN16(pcm + 30*nchannels + 2*c);
234 x[1] =
AV_RN16(pcm + 14*nchannels + 2*c);
235 x[2] =
AV_RN16(pcm + 28*nchannels + 2*c);
236 x[3] =
AV_RN16(pcm + 16*nchannels + 2*c);
237 x[4] =
AV_RN16(pcm + 26*nchannels + 2*c);
238 x[5] =
AV_RN16(pcm + 18*nchannels + 2*c);
239 x[6] =
AV_RN16(pcm + 24*nchannels + 2*c);
240 x[7] =
AV_RN16(pcm + 20*nchannels + 2*c);
241 x[8] =
AV_RN16(pcm + 22*nchannels + 2*c);
242 x[9] =
AV_RN16(pcm + 6*nchannels + 2*c);
243 x[10] =
AV_RN16(pcm + 12*nchannels + 2*c);
244 x[11] =
AV_RN16(pcm + 0*nchannels + 2*c);
245 x[12] =
AV_RN16(pcm + 10*nchannels + 2*c);
246 x[13] =
AV_RN16(pcm + 2*nchannels + 2*c);
247 x[14] =
AV_RN16(pcm + 8*nchannels + 2*c);
248 x[15] =
AV_RN16(pcm + 4*nchannels + 2*c);
254 for (c = 0; c < nchannels; c++) {
255 int16_t *x = &
X[
c][position];
256 x[-7] =
AV_RN16(pcm + 14*nchannels + 2*c);
257 x[1] =
AV_RN16(pcm + 6*nchannels + 2*c);
258 x[2] =
AV_RN16(pcm + 12*nchannels + 2*c);
259 x[3] =
AV_RN16(pcm + 0*nchannels + 2*c);
260 x[4] =
AV_RN16(pcm + 10*nchannels + 2*c);
261 x[5] =
AV_RN16(pcm + 2*nchannels + 2*c);
262 x[6] =
AV_RN16(pcm + 8*nchannels + 2*c);
263 x[7] =
AV_RN16(pcm + 4*nchannels + 2*c);
271 uint32_t scale_factor[2][8],
278 for (blk = 0; blk < blocks; blk++) {
289 uint32_t scale_factor[2][8],
297 int sb = subbands - 1;
300 for (blk = 0; blk < blocks; blk++) {
301 tmp0 =
FFABS(sb_sample_f[blk][0][sb]);
302 tmp1 =
FFABS(sb_sample_f[blk][1][sb]);
316 for (blk = 0; blk < blocks; blk++) {
317 tmp0 = sb_sample_f[
blk][0][sb];
318 tmp1 = sb_sample_f[
blk][1][sb];
319 sb_sample_j[
blk][0] = (tmp0 >> 1) + (tmp1 >> 1);
320 sb_sample_j[
blk][1] = (tmp0 >> 1) - (tmp1 >> 1);
334 for (blk = 0; blk < blocks; blk++) {
335 tmp0 =
FFABS(sb_sample_j[blk][0]);
336 tmp1 =
FFABS(sb_sample_j[blk][1]);
346 if ((scale_factor[0][sb] + scale_factor[1][sb]) > x + y) {
347 joint |= 1 << (subbands - 1 - sb);
348 scale_factor[0][sb] = x;
349 scale_factor[1][sb] = y;
350 for (blk = 0; blk < blocks; blk++) {
351 sb_sample_f[
blk][0][sb] = sb_sample_j[
blk][0];
352 sb_sample_f[
blk][1][sb] = sb_sample_j[
blk][1];
370 if (s->increment == 1)
const int16_t ff_sbcdsp_analysis_consts_fixed4_simd_odd[40+16]
#define SBC_COS_TABLE_FIXED_SCALE
#define SBC_X_BUFFER_SIZE
static void sbc_analyze_8_simd(const int16_t *in, int32_t *out, const int16_t *consts)
static int sbc_enc_process_input_4s(int position, const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE], int nsamples, int nchannels)
const int16_t ff_sbcdsp_analysis_consts_fixed8_simd_even[80+64]
static void sbc_analyze_4b_4s_simd(SBCDSPContext *s, int16_t *x, int32_t *out, int out_stride)
SBC basic "building bricks".
static void sbc_analyze_4b_8s_simd(SBCDSPContext *s, int16_t *x, int32_t *out, int out_stride)
static void sbc_analyze_1b_8s_simd_odd(SBCDSPContext *s, int16_t *x, int32_t *out, int out_stride)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define SBC_PROTO_FIXED_SCALE
void ff_sbcdsp_init_x86(SBCDSPContext *s)
static void sbc_analyze_4_simd(const int16_t *in, int32_t *out, const int16_t *consts)
av_cold void ff_sbcdsp_init_arm(SBCDSPContext *s)
av_cold void ff_sbcdsp_init(SBCDSPContext *s)
static int sbc_calc_scalefactors_j(int32_t sb_sample_f[16][2][8], uint32_t scale_factor[2][8], int blocks, int subbands)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
const int16_t ff_sbcdsp_analysis_consts_fixed4_simd_even[40+16]
static av_always_inline void sbc_analyze_simd(const int16_t *in, int32_t *out, const int16_t *consts, unsigned subbands)
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(const uint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(const int16_t *) pi >> 8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(const int32_t *) pi >> 24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31))))#define SET_CONV_FUNC_GROUP(ofmt, ifmt) static void set_generic_function(AudioConvert *ac){}void ff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, int sample_rate, int apply_map){AudioConvert *ac;int in_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) return NULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt) > 2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);return NULL;}return ac;}in_planar=ff_sample_fmt_is_planar(in_fmt, channels);out_planar=ff_sample_fmt_is_planar(out_fmt, channels);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}else if(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;else ac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_AARCH64) ff_audio_convert_init_aarch64(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);return ac;}int ff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){int use_generic=1;int len=in->nb_samples;int p;if(ac->dc){av_log(ac->avr, AV_LOG_TRACE,"%d samples - audio_convert: %s to %s (dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));return ff_convert_dither(ac-> in
static void sbc_analyze_1b_8s_simd_even(SBCDSPContext *s, int16_t *x, int32_t *out, int out_stride)
const int16_t ff_sbcdsp_analysis_consts_fixed8_simd_odd[80+64]
common internal and external API header
SBC common definitions for the encoder and decoder.
static void sbc_calc_scalefactors(int32_t sb_sample_f[16][2][8], uint32_t scale_factor[2][8], int blocks, int channels, int subbands)
static int sbc_enc_process_input_8s(int position, const uint8_t *pcm, int16_t X[2][SBC_X_BUFFER_SIZE], int nsamples, int nchannels)