28 float *synth_buf_ptr,
int *synth_buf_offset,
29 float synth_buf2[32],
const float window[512],
30 float out[32],
const float in[32],
float scale)
32 float *synth_buf = synth_buf_ptr + *synth_buf_offset;
37 for (i = 0; i < 16; i++) {
38 float a = synth_buf2[
i ];
39 float b = synth_buf2[i + 16];
42 for (j = 0; j < 512 - *synth_buf_offset; j += 64) {
43 a += window[i + j ] * (-synth_buf[15 - i + j ]);
44 b += window[i + j + 16] * ( synth_buf[ i + j ]);
45 c += window[i + j + 32] * ( synth_buf[16 + i + j ]);
46 d += window[i + j + 48] * ( synth_buf[31 - i + j ]);
48 for ( ; j < 512; j += 64) {
49 a += window[i + j ] * (-synth_buf[15 - i + j - 512]);
50 b += window[i + j + 16] * ( synth_buf[ i + j - 512]);
51 c += window[i + j + 32] * ( synth_buf[16 + i + j - 512]);
52 d += window[i + j + 48] * ( synth_buf[31 - i + j - 512]);
55 out[i + 16] = b * scale;
57 synth_buf2[i + 16] = d;
60 *synth_buf_offset = (*synth_buf_offset - 32) & 511;
64 float *synth_buf_ptr,
int *synth_buf_offset,
65 float synth_buf2[64],
const float window[1024],
66 float out[64],
const float in[64],
float scale)
68 float *synth_buf = synth_buf_ptr + *synth_buf_offset;
73 for (i = 0; i < 32; i++) {
74 float a = synth_buf2[
i ];
75 float b = synth_buf2[i + 32];
78 for (j = 0; j < 1024 - *synth_buf_offset; j += 128) {
79 a += window[i + j ] * (-synth_buf[31 - i + j ]);
80 b += window[i + j + 32] * ( synth_buf[ i + j ]);
81 c += window[i + j + 64] * ( synth_buf[32 + i + j ]);
82 d += window[i + j + 96] * ( synth_buf[63 - i + j ]);
84 for ( ; j < 1024; j += 128) {
85 a += window[i + j ] * (-synth_buf[31 - i + j - 1024]);
86 b += window[i + j + 32] * ( synth_buf[ i + j - 1024]);
87 c += window[i + j + 64] * ( synth_buf[32 + i + j - 1024]);
88 d += window[i + j + 96] * ( synth_buf[63 - i + j - 1024]);
91 out[i + 32] = b * scale;
93 synth_buf2[i + 32] = d;
96 *synth_buf_offset = (*synth_buf_offset - 64) & 1023;
100 int32_t *synth_buf_ptr,
int *synth_buf_offset,
104 int32_t *synth_buf = synth_buf_ptr + *synth_buf_offset;
109 for (i = 0; i < 16; i++) {
110 int64_t
a = synth_buf2[
i ] * (INT64_C(1) << 21);
111 int64_t
b = synth_buf2[i + 16] * (INT64_C(1) << 21);
114 for (j = 0; j < 512 - *synth_buf_offset; j += 64) {
115 a += (int64_t)window[i + j ] * synth_buf[ i + j ];
116 b += (int64_t)window[i + j + 16] * synth_buf[15 - i + j ];
117 c += (int64_t)window[i + j + 32] * synth_buf[16 + i + j ];
118 d += (int64_t)window[i + j + 48] * synth_buf[31 - i + j ];
120 for ( ; j < 512; j += 64) {
121 a += (int64_t)window[i + j ] * synth_buf[ i + j - 512];
122 b += (int64_t)window[i + j + 16] * synth_buf[15 - i + j - 512];
123 c += (int64_t)window[i + j + 32] * synth_buf[16 + i + j - 512];
124 d += (int64_t)window[i + j + 48] * synth_buf[31 - i + j - 512];
129 synth_buf2[i + 16] =
norm21(d);
132 *synth_buf_offset = (*synth_buf_offset - 32) & 511;
136 int32_t *synth_buf_ptr,
int *synth_buf_offset,
140 int32_t *synth_buf = synth_buf_ptr + *synth_buf_offset;
145 for (i = 0; i < 32; i++) {
146 int64_t
a = synth_buf2[
i ] * (INT64_C(1) << 20);
147 int64_t
b = synth_buf2[i + 32] * (INT64_C(1) << 20);
150 for (j = 0; j < 1024 - *synth_buf_offset; j += 128) {
151 a += (int64_t)window[i + j ] * synth_buf[ i + j ];
152 b += (int64_t)window[i + j + 32] * synth_buf[31 - i + j ];
153 c += (int64_t)window[i + j + 64] * synth_buf[32 + i + j ];
154 d += (int64_t)window[i + j + 96] * synth_buf[63 - i + j ];
156 for ( ; j < 1024; j += 128) {
157 a += (int64_t)window[i + j ] * synth_buf[ i + j - 1024];
158 b += (int64_t)window[i + j + 32] * synth_buf[31 - i + j - 1024];
159 c += (int64_t)window[i + j + 64] * synth_buf[32 + i + j - 1024];
160 d += (int64_t)window[i + j + 96] * synth_buf[63 - i + j - 1024];
165 synth_buf2[i + 32] =
norm20(d);
168 *synth_buf_offset = (*synth_buf_offset - 64) & 1023;
void ff_synth_filter_init_x86(SynthFilterContext *c)
static void synth_filter_float_64(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[64], const float window[1024], float out[64], const float in[64], float scale)
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
av_cold void ff_synth_filter_init(SynthFilterContext *c)
static void synth_filter_fixed_64(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[64], const int32_t window[1024], int32_t out[64], const int32_t in[64])
void(* synth_filter_float)(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[32], const float window[512], float out[32], const float in[32], float scale)
static int32_t clip23(int32_t a)
static int32_t norm20(int64_t a)
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
av_cold void ff_synth_filter_init_arm(SynthFilterContext *s)
static void synth_filter_float(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[32], const float window[512], float out[32], const float in[32], float scale)
static SDL_Window * window
void(* synth_filter_fixed_64)(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[64], const int32_t window[1024], int32_t out[64], const int32_t in[64])
void(* synth_filter_fixed)(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[32], const int32_t window[512], int32_t out[32], const int32_t in[32])
static int32_t norm21(int64_t a)
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
void(* synth_filter_float_64)(FFTContext *imdct, float *synth_buf_ptr, int *synth_buf_offset, float synth_buf2[64], const float window[1024], float out[64], const float in[64], float scale)
av_cold void ff_synth_filter_init_aarch64(SynthFilterContext *s)
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
static void synth_filter_fixed(DCADCTContext *imdct, int32_t *synth_buf_ptr, int *synth_buf_offset, int32_t synth_buf2[32], const int32_t window[512], int32_t out[32], const int32_t in[32])
void(* imdct_half[2])(int32_t *output, const int32_t *input)