Go to the documentation of this file.
37 #define ASSERT_LEVEL 2
83 for(ch= 0; ch<ch_count; ch++)
142 static int cmp(
const void *
a,
const void *
b){
143 return *(
const int *)
a - *(
const int *)
b;
150 double v,
f,
a, ampa;
156 #define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
157 #define uint_rand(x) ((x) = (x) * 1664525 + 1013904223)
158 #define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
202 v = sin(taba[ch]) * 0.30;
204 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) *
i) /
sample_rate);
214 double amp = (1.0 + sin(ampa)) * 0.15;
225 int main(
int argc,
char **argv){
237 int num_tests = 10000;
239 uint32_t rand_seed = 0;
243 int specific_test= -1;
249 if (!strcmp(argv[1],
"-h") || !strcmp(argv[1],
"--help")) {
251 "num_tests Default is %d\n", num_tests);
254 num_tests = strtol(argv[1],
NULL, 0);
256 num_tests = -num_tests;
259 if(num_tests<= 0 || num_tests>max_tests)
260 num_tests = max_tests;
262 specific_test = strtol(argv[1],
NULL, 0);
266 for(
i=0;
i<max_tests;
i++)
267 remaining_tests[
i] =
i;
272 r = (
seed * (uint64_t)(max_tests -
test)) >>32;
273 FFSWAP(
int, remaining_tests[
r], remaining_tests[max_tests -
test - 1]);
275 qsort(remaining_tests + max_tests - num_tests, num_tests,
sizeof(remaining_tests[0]),
cmp);
278 char in_layout_string[256];
279 char out_layout_string[256];
280 unsigned vector= remaining_tests[max_tests -
test - 1];
282 int out_count, mid_count, out_ch_count;
291 if(specific_test == 0){
300 fprintf(stderr,
"TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
301 in_layout_string, out_layout_string,
311 fprintf(stderr,
"Failed to init forw_cts\n");
315 fprintf(stderr,
"Failed to init backw_ctx\n");
324 fprintf(stderr,
"swr_init(->) failed\n");
326 fprintf(stderr,
"swr_init(<-) failed\n");
332 for(ch=0; ch<in_ch_count; ch++){
363 for(ch=0; ch<in_ch_count; ch++){
364 double sse, maxdiff=0;
370 for(
i=0;
i<out_count;
i++){
380 sse= sum_aa + sum_bb - 2*sum_ab;
381 if(sse < 0 && sse > -0.00001)
sse=0;
383 fprintf(stderr,
"[e:%f c:%f max:%f] len:%5d\n", out_count ? sqrt(
sse/out_count) : 0, sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, out_count);
388 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
393 for(ch=0; ch<in_ch_count; ch++){
394 double sse, maxdiff=0;
400 for(
i=0;
i<flush_count;
i++){
410 sse= sum_aa + sum_bb - 2*sum_ab;
411 if(sse < 0 && sse > -0.00001)
sse=0;
413 fprintf(stderr,
"[e:%f c:%f max:%f] len:%5d F:%3d\n", sqrt(
sse/flush_count), sum_ab/(sqrt(sum_aa*sum_bb)), maxdiff, flush_count, flush_i);
418 fprintf(stderr,
"\n");
static void sum_a(const int *input, int *output, int len)
#define AV_CH_LAYOUT_7POINT0
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_CH_LAYOUT_5POINT0_BACK
int64_t out_ch_layout
output channel layout
int in_sample_rate
input sample rate
#define FFSWAP(type, a, b)
#define AV_CH_LAYOUT_MONO
void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout)
Return a description of a channel layout.
int out_sample_rate
output sample rate
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
static int cmp(const void *a, const void *b)
static void audiogen(void *data, enum AVSampleFormat sample_fmt, int channels, int sample_rate, int nb_samples)
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples)
enum AVSampleFormat out_sample_fmt
output sample format
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_QUAD
#define FF_ARRAY_ELEMS(a)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, const uint8_t *in_arg[SWR_CH_MAX], int in_count)
static void sum_b(const int *input, int *output, int len)
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
The libswresample context.
struct SwrContext * swr_alloc_set_opts(struct SwrContext *s, int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, int log_offset, void *log_ctx)
Allocate SwrContext if needed and set/reset common parameters.
static __device__ float fabs(float a)
#define AV_CH_LAYOUT_5POINT1
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags)
int main(int argc, char **argv)
static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f)
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
static const uint64_t layouts[]
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
#define AV_CH_LAYOUT_5POINT1_BACK
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
#define AV_LOG_INFO
Standard information.
#define AV_CH_LAYOUT_5POINT0
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
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
AVSampleFormat
Audio sample formats.
#define AV_CH_LAYOUT_7POINT1
#define AV_CH_LAYOUT_7POINT1_WIDE
@ AV_SAMPLE_FMT_S16
signed 16 bits
enum AVSampleFormat in_sample_fmt
input sample format
#define AV_CH_LAYOUT_SURROUND
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f)
static void test(const char *pattern, const char *host)
@ AV_SAMPLE_FMT_DBLP
double, planar
Filter the word “frame” indicates either a video frame or a group of audio samples
enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar)
Return the planar<->packed alternative form of the given sample format, or AV_SAMPLE_FMT_NONE on erro...
int64_t in_ch_layout
input channel layout
#define AV_CH_LAYOUT_4POINT0
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S32
signed 32 bits