79 for(ch= 0; ch<ch_count; ch++)
131 out[
i]= in +
i*plane_size;
138static int cmp(
const void *
a,
const void *
b){
139 return *(
const int *)
a - *(
const int *)
b;
143 int channels,
int sample_rate,
int nb_samples)
146 double v,
f,
a, ampa;
152#define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v);
153#define uint_rand(x) ((x) = (x) * 1664525 + 1013904223)
154#define dbl_rand(x) (uint_rand(x)*2.0 / (double)UINT_MAX - 1)
159 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
163 a +=
M_PI * 1000.0 * 2.0 / sample_rate;
168 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
172 f = 100.0 + (((10000.0 - 100.0) *
i) / sample_rate);
173 a +=
M_PI *
f * 2.0 / sample_rate;
177 for (
i = 0;
i < sample_rate / 2 && k < nb_samples;
i++, k++) {
184 for (
i = 0;
i < sample_rate / 2 && k < nb_samples;
i++, k++) {
196 for (
i = 0;
i < 1 * sample_rate && k < nb_samples;
i++, k++) {
198 v = sin(taba[ch]) * 0.30;
200 f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) *
i) / sample_rate);
201 taba[ch] +=
M_PI *
f * 2.0 / sample_rate;
208 for (
i = 0;
i < 2 * sample_rate && k < nb_samples;
i++, k++) {
210 double amp = (1.0 + sin(ampa)) * 0.15;
215 a +=
M_PI * 500.0 * 2.0 / sample_rate;
216 ampa +=
M_PI * 2.0 / sample_rate;
221int main(
int argc,
char **argv){
222 int in_sample_rate, out_sample_rate, ch ,
i, flush_count;
226 uint8_t array_mid[
SAMPLES*8*8*3];
227 uint8_t array_out[
SAMPLES*8*8+100];
233 int num_tests = 10000;
235 uint32_t rand_seed = 0;
239 int specific_test= -1;
245 if (!strcmp(argv[1],
"-h") || !strcmp(argv[1],
"--help")) {
247 "num_tests Default is %d\n", num_tests);
250 num_tests = strtol(argv[1],
NULL, 0);
252 num_tests = -num_tests;
255 if(num_tests<= 0 || num_tests>max_tests)
256 num_tests = max_tests;
258 specific_test = strtol(argv[1],
NULL, 0);
262 for(
i=0;
i<max_tests;
i++)
263 remaining_tests[
i] =
i;
268 r = (
seed * (uint64_t)(max_tests -
test)) >>32;
269 FFSWAP(
int, remaining_tests[
r], remaining_tests[max_tests -
test - 1]);
271 qsort(remaining_tests + max_tests - num_tests, num_tests,
sizeof(remaining_tests[0]),
cmp);
274 char in_layout_string[256];
275 char out_layout_string[256];
276 unsigned vector= remaining_tests[max_tests -
test - 1];
278 int out_count, mid_count, out_ch_count;
287 if(specific_test == 0){
296 fprintf(stderr,
"TEST: %s->%s, rate:%5d->%5d, fmt:%s->%s\n",
297 in_layout_string, out_layout_string,
303 fprintf(stderr,
"Failed to init forw_cts\n");
309 fprintf(stderr,
"Failed to init backw_ctx\n");
314 fprintf(stderr,
"swr_init(->) failed\n");
316 fprintf(stderr,
"swr_init(<-) failed\n");
322 for(ch=0; ch<in_ch_count; ch++){
337 mid_count=
swr_convert(forw_ctx, amid, 0, (
const uint8_t **)ain, 1);
342 mid_count+=
swr_convert(forw_ctx, amid, 2, (
const uint8_t **)ain, 2);
353 for(ch=0; ch<in_ch_count; ch++){
354 double sse, maxdiff=0;
358 for(
i=0;
i<out_count;
i++){
366 sse= sum_aa + sum_bb - 2*sum_ab;
369 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);
374 flush_count =
swr_convert(backw_ctx,aout, flush_i, 0, 0);
379 for(ch=0; ch<in_ch_count; ch++){
380 double sse, maxdiff=0;
384 for(
i=0;
i<flush_count;
i++){
392 sse= sum_aa + sum_bb - 2*sum_ab;
395 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);
400 fprintf(stderr,
"\n");
static const char *const format[]
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
common internal and external API header
static __device__ float fabs(float a)
#define AV_CHANNEL_LAYOUT_4POINT0
#define AV_CHANNEL_LAYOUT_5POINT1_BACK
#define AV_CHANNEL_LAYOUT_7POINT1_WIDE
#define AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_STEREO
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
#define AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_5POINT0_BACK
#define AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_7POINT0
#define AV_CHANNEL_LAYOUT_SURROUND
#define AV_CHANNEL_LAYOUT_2_1
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_7POINT1
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
#define AV_CHANNEL_LAYOUT_QUAD
#define AV_LOG_INFO
Standard information.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
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...
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.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_FLTP
float, planar
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
@ AV_SAMPLE_FMT_U8P
unsigned 8 bits, planar
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_U8
unsigned 8 bits
@ AV_SAMPLE_FMT_DBLP
double, planar
@ AV_SAMPLE_FMT_DBL
double
@ AV_SAMPLE_FMT_S16
signed 16 bits
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.
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.
av_cold int swr_init(struct SwrContext *s)
Initialize context after user parameters have been set.
#define FFSWAP(type, a, b)
static av_always_inline int cmp(MPVEncContext *const s, const int x, const int y, const int subx, const int suby, const int size, const int h, int ref_index, int src_index, me_cmp_func cmp_func, me_cmp_func chroma_cmp_func, const int flags)
compares a block (either a full macroblock or a partition thereof) against a proposed motion-compensa...
enum MovChannelLayoutTag * layouts
static int sse(const MPVEncContext *const s, const uint8_t *src1, const uint8_t *src2, int w, int h, int stride)
#define FF_ARRAY_ELEMS(a)
An AVChannelLayout holds information about the channel layout of audio data.
int nb_channels
Number of channels in this layout.
The libswresample context.
int out_sample_rate
output sample rate
int in_sample_rate
input sample rate
AVChannelLayout out_ch_layout
output channel layout
enum AVSampleFormat in_sample_fmt
input sample format
AVChannelLayout in_ch_layout
input channel layout
enum AVSampleFormat out_sample_fmt
output sample format
libswresample public header
static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples)
static void audiogen(void *data, enum AVSampleFormat sample_fmt, int channels, int sample_rate, int nb_samples)
static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f)
static int cmp(const void *a, const void *b)
static void shift(uint8_t *a[], int index, int ch_count, enum AVSampleFormat f)
static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v)