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;
147 int channels,
int sample_rate,
int nb_samples)
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)
163 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
167 a +=
M_PI * 1000.0 * 2.0 / sample_rate;
172 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
176 f = 100.0 + (((10000.0 - 100.0) *
i) / sample_rate);
177 a +=
M_PI *
f * 2.0 / sample_rate;
181 for (
i = 0;
i < sample_rate / 2 && k < nb_samples;
i++, k++) {
188 for (
i = 0;
i < sample_rate / 2 && k < nb_samples;
i++, k++) {
200 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
202 v = sin(taba[ch]) * 0.30;
204 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) *
i) / sample_rate);
205 taba[ch] +=
M_PI *
f * 2.0 / sample_rate;
212 for (
i = 0;
i < 2 * sample_rate && k < nb_samples;
i++, k++) {
214 double amp = (1.0 + sin(ampa)) * 0.15;
219 a +=
M_PI * 500.0 * 2.0 / sample_rate;
220 ampa +=
M_PI * 2.0 / sample_rate;
225 int main(
int argc,
char **argv){
230 uint8_t array_mid[
SAMPLES*8*8*3];
231 uint8_t array_out[
SAMPLES*8*8+100];
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,
307 fprintf(stderr,
"Failed to init forw_cts\n");
313 fprintf(stderr,
"Failed to init backw_ctx\n");
318 fprintf(stderr,
"swr_init(->) failed\n");
320 fprintf(stderr,
"swr_init(<-) failed\n");
326 for(ch=0; ch<in_ch_count; ch++){
341 mid_count=
swr_convert(forw_ctx, amid, 0, (
const uint8_t **)ain, 1);
346 mid_count+=
swr_convert(forw_ctx, amid, 2, (
const uint8_t **)ain, 2);
357 for(ch=0; ch<in_ch_count; ch++){
358 double sse, maxdiff=0;
362 for(
i=0;
i<out_count;
i++){
370 sse= sum_aa + sum_bb - 2*sum_ab;
371 if(sse < 0 && sse > -0.00001)
sse=0;
373 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);
378 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
383 for(ch=0; ch<in_ch_count; ch++){
384 double sse, maxdiff=0;
388 for(
i=0;
i<flush_count;
i++){
396 sse= sum_aa + sum_bb - 2*sum_ab;
397 if(sse < 0 && sse > -0.00001)
sse=0;
399 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);
404 fprintf(stderr,
"\n");
@ AV_SAMPLE_FMT_FLTP
float, planar
#define AV_CHANNEL_LAYOUT_STEREO
int in_sample_rate
input sample rate
#define AV_CHANNEL_LAYOUT_2_2
int out_sample_rate
output sample rate
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
AVChannelLayout out_ch_layout
output channel layout
int nb_channels
Number of channels in this layout.
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)
#define AV_CHANNEL_LAYOUT_7POINT1_WIDE
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_CHANNEL_LAYOUT_SURROUND
int attribute_align_arg swr_convert(struct SwrContext *s, uint8_t *const *out_arg, int out_count, const uint8_t *const *in_arg, int in_count)
Convert audio.
#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.
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
#define AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_7POINT1
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
#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.
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.
AVChannelLayout in_ch_layout
input channel layout
static __device__ float fabs(float a)
int main(int argc, char **argv)
static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f)
int swr_alloc_set_opts2(struct SwrContext **ps, const AVChannelLayout *out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, const AVChannelLayout *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.
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
An AVChannelLayout holds information about the channel layout of audio data.
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_SAMPLE_FMT_S16P
signed 16 bits, planar
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
#define AV_LOG_INFO
Standard information.
#define av_assert2(cond)
assert() equivalent, that does lie in speed critical code.
#define i(width, name, range_min, range_max)
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
#define AV_CHANNEL_LAYOUT_QUAD
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S16
signed 16 bits
#define FFSWAP(type, a, b)
enum AVSampleFormat in_sample_fmt
input sample format
#define AV_CHANNEL_LAYOUT_7POINT0
#define AV_CHANNEL_LAYOUT_2_1
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f)
static void test(const char *pattern, const char *host)
static const AVChannelLayout layouts[]
@ AV_SAMPLE_FMT_DBLP
double, planar
Filter the word “frame” indicates either a video frame or a group of audio samples
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
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...
#define AV_CHANNEL_LAYOUT_MONO
AudioData in
input audio data
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
static int sse(MpegEncContext *s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
#define AV_CHANNEL_LAYOUT_5POINT0
@ AV_SAMPLE_FMT_DBL
double
#define AV_CHANNEL_LAYOUT_5POINT1
@ AV_SAMPLE_FMT_S32
signed 32 bits