From 6c834328b9bbf051473473f05f97dd2183fd336d Mon Sep 17 00:00:00 2001 From: Justin Ruggles Date: Wed, 15 Sep 2010 21:36:04 +0000 Subject: Allow audiogen to take commandline parameters for sample rate and number of channels. Originally committed as revision 25127 to svn://svn.ffmpeg.org/ffmpeg/trunk --- tests/audiogen.c | 78 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 30 deletions(-) (limited to 'tests/audiogen.c') diff --git a/tests/audiogen.c b/tests/audiogen.c index 38ca5dd22a..852e04268b 100644 --- a/tests/audiogen.c +++ b/tests/audiogen.c @@ -24,8 +24,7 @@ #include #include -#define NB_CHANNELS 2 -#define FE 44100 +#define MAX_CHANNELS 8 static unsigned int myrnd(unsigned int *seed_ptr, int n) { @@ -104,15 +103,34 @@ int main(int argc, char **argv) { int i, a, v, j, f, amp, ampa; unsigned int seed = 1; - int tabf1[NB_CHANNELS], tabf2[NB_CHANNELS]; - int taba[NB_CHANNELS]; - - if (argc != 2) { - printf("usage: %s file\n" - "generate a test raw 16 bit stereo audio stream\n", argv[0]); + int tabf1[MAX_CHANNELS], tabf2[MAX_CHANNELS]; + int taba[MAX_CHANNELS]; + int sample_rate = 44100; + int nb_channels = 2; + + if (argc < 2 || argc > 4) { + printf("usage: %s file [ []]\n" + "generate a test raw 16 bit audio stream\n" + "default: 44100 Hz stereo\n", argv[0]); exit(1); } + if (argc > 2) { + sample_rate = atoi(argv[2]); + if (sample_rate <= 0) { + fprintf(stderr, "invalid sample rate: %d\n", sample_rate); + return 1; + } + } + + if (argc > 3) { + nb_channels = atoi(argv[3]); + if (nb_channels < 1 || nb_channels > MAX_CHANNELS) { + fprintf(stderr, "invalid number of channels: %d\n", nb_channels); + return 1; + } + } + outfile = fopen(argv[1], "wb"); if (!outfile) { perror(argv[1]); @@ -121,64 +139,64 @@ int main(int argc, char **argv) /* 1 second of single freq sinus at 1000 Hz */ a = 0; - for(i=0;i<1 * FE;i++) { + for(i=0;i<1 * sample_rate;i++) { v = (int_cos(a) * 10000) >> FRAC_BITS; - for(j=0;j> FRAC_BITS; - for(j=0;j> FRAC_BITS; put_sample(v); - f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / FE); - taba[j] += (f * FRAC_ONE) / FE; + f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); + taba[j] += (f * FRAC_ONE) / sample_rate; } } - /* stereo 500 Hz with varying volume */ + /* 2 seconds of 500 Hz with varying volume */ a = 0; ampa = 0; - for(i=0;i<2 * FE;i++) { - for(j=0;j> FRAC_BITS; if (j & 1) amp = 10000 - amp; v = (int_cos(a) * amp) >> FRAC_BITS; put_sample(v); - a += (500 * FRAC_ONE) / FE; - ampa += (2 * FRAC_ONE) / FE; + a += (500 * FRAC_ONE) / sample_rate; + ampa += (2 * FRAC_ONE) / sample_rate; } } -- cgit v1.2.3