|
|
|
@ -1,5 +1,6 @@ |
|
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) |
|
|
|
|
* Copyright (c) 2002 Fabrice Bellard |
|
|
|
|
* |
|
|
|
|
* This file is part of libswresample |
|
|
|
|
* |
|
|
|
@ -136,6 +137,84 @@ static int cmp(const int *a, const int *b){ |
|
|
|
|
return *a - *b; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static void audiogen(void *data, enum AVSampleFormat sample_fmt, |
|
|
|
|
int channels, int sample_rate, int nb_samples) |
|
|
|
|
{ |
|
|
|
|
int i, ch, k; |
|
|
|
|
double v, f, a, ampa; |
|
|
|
|
double tabf1[SWR_CH_MAX]; |
|
|
|
|
double tabf2[SWR_CH_MAX]; |
|
|
|
|
double taba[SWR_CH_MAX]; |
|
|
|
|
unsigned static seed; |
|
|
|
|
|
|
|
|
|
#define PUT_SAMPLE set(data, ch, k, channels, sample_fmt, v); |
|
|
|
|
#define dbl_rand(x) ((seed = seed * 1664525 + 1013904223)*2.0 / (double)UINT_MAX - 1) |
|
|
|
|
k = 0; |
|
|
|
|
|
|
|
|
|
/* 1 second of single freq sinus at 1000 Hz */ |
|
|
|
|
a = 0; |
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { |
|
|
|
|
v = sin(a) * 0.30; |
|
|
|
|
for (ch = 0; ch < channels; ch++) |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
a += M_PI * 1000.0 * 2.0 / sample_rate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 1 second of varing frequency between 100 and 10000 Hz */ |
|
|
|
|
a = 0; |
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { |
|
|
|
|
v = sin(a) * 0.30; |
|
|
|
|
for (ch = 0; ch < channels; ch++) |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
f = 100.0 + (((10000.0 - 100.0) * i) / sample_rate); |
|
|
|
|
a += M_PI * f * 2.0 / sample_rate; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 0.5 second of low amplitude white noise */ |
|
|
|
|
for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { |
|
|
|
|
v = dbl_rand(rnd) * 0.30; |
|
|
|
|
for (ch = 0; ch < channels; ch++) |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 0.5 second of high amplitude white noise */ |
|
|
|
|
for (i = 0; i < sample_rate / 2 && k < nb_samples; i++, k++) { |
|
|
|
|
v = dbl_rand(rnd); |
|
|
|
|
for (ch = 0; ch < channels; ch++) |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 1 second of unrelated ramps for each channel */ |
|
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
|
taba[ch] = 0; |
|
|
|
|
tabf1[ch] = 100 + (seed = seed * 1664525 + 1013904223) % 5000; |
|
|
|
|
tabf2[ch] = 100 + (seed = seed * 1664525 + 1013904223) % 5000; |
|
|
|
|
} |
|
|
|
|
for (i = 0; i < 1 * sample_rate && k < nb_samples; i++, k++) { |
|
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
|
v = sin(taba[ch]) * 0.30; |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
f = tabf1[ch] + (((tabf2[ch] - tabf1[ch]) * i) / sample_rate); |
|
|
|
|
taba[ch] += M_PI * f * 2.0 / sample_rate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* 2 seconds of 500 Hz with varying volume */ |
|
|
|
|
a = 0; |
|
|
|
|
ampa = 0; |
|
|
|
|
for (i = 0; i < 2 * sample_rate && k < nb_samples; i++, k++) { |
|
|
|
|
for (ch = 0; ch < channels; ch++) { |
|
|
|
|
double amp = (1.0 + sin(ampa)) * 0.15; |
|
|
|
|
if (ch & 1) |
|
|
|
|
amp = 0.30 - amp; |
|
|
|
|
v = sin(a) * amp; |
|
|
|
|
PUT_SAMPLE |
|
|
|
|
a += M_PI * 500.0 * 2.0 / sample_rate; |
|
|
|
|
ampa += M_PI * 2.0 / sample_rate; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv){ |
|
|
|
|
int in_sample_rate, out_sample_rate, ch ,i, in_ch_layout_index, out_ch_layout_index, osr, flush_count; |
|
|
|
|
int in_sample_fmt_index, out_sample_fmt_index; |
|
|
|
@ -220,10 +299,14 @@ int main(int argc, char **argv){ |
|
|
|
|
setup_array(ain , array_in , in_sample_fmt, SAMPLES); |
|
|
|
|
setup_array(amid, array_mid, out_sample_fmt, 3*SAMPLES); |
|
|
|
|
setup_array(aout, array_out, in_sample_fmt , SAMPLES); |
|
|
|
|
#if 0 |
|
|
|
|
for(ch=0; ch<in_ch_count; ch++){ |
|
|
|
|
for(i=0; i<SAMPLES; i++) |
|
|
|
|
set(ain, ch, i, in_ch_count, in_sample_fmt, sin(i*i*3/SAMPLES)); |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
audiogen(ain, in_sample_fmt, in_ch_count, SAMPLES/6+1, SAMPLES); |
|
|
|
|
#endif |
|
|
|
|
mode++; |
|
|
|
|
mode%=3; |
|
|
|
|
if(mode==0 /*|| out_sample_rate == in_sample_rate*/) { |
|
|
|
|