diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2012-04-20 22:18:26 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2012-04-20 22:18:26 +0200 |
commit | 3194ab78a6c4ea0a4c60c91c4d0ea34028ca408f (patch) | |
tree | 13f41910a7e4feec8d64182bf3b6772d88236098 /tests/audiogen.c | |
parent | 9b1f776d751472e8a376b412d02a96a35044e2a0 (diff) | |
parent | b0e9edc44f1722787adacbff9aa60343206a58c0 (diff) | |
download | ffmpeg-3194ab78a6c4ea0a4c60c91c4d0ea34028ca408f.tar.gz |
Merge remote-tracking branch 'qatar/master'
* qatar/master:
avcodec: add a cook parser to get subpacket duration
FATE: allow lavf tests to alter input parameters
FATE: replace the acodec-pcm_s24daud test with an enc_dec_pcm checksum test
FATE: replace the acodec-g726 test with 4 new encode/decode tests
FATE: replace current g722 encoding tests with an encode/decode test
FATE: add a pattern rule for generating asynth wav files
FATE: optionally write a WAVE header in audiogen
avutil: add audio fifo buffer
Conflicts:
doc/APIchanges
libavcodec/version.h
libavutil/avutil.h
tests/Makefile
tests/codec-regression.sh
tests/fate/voice.mak
tests/lavf-regression.sh
tests/ref/acodec/g722
tests/ref/acodec/g726
tests/ref/acodec/pcm_s24daud
tests/ref/lavf/dv_fmt
tests/ref/lavf/gxf
tests/ref/lavf/mxf
tests/ref/lavf/mxf_d10
tests/ref/seek/lavf_dv
Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'tests/audiogen.c')
-rw-r--r-- | tests/audiogen.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/tests/audiogen.c b/tests/audiogen.c index 776fdf9316..5818797a65 100644 --- a/tests/audiogen.c +++ b/tests/audiogen.c @@ -22,7 +22,9 @@ */ #include <stdlib.h> +#include <stdint.h> #include <stdio.h> +#include <string.h> #define MAX_CHANNELS 8 @@ -93,12 +95,45 @@ static int int_cos(int a) FILE *outfile; -static void put_sample(int v) +static void put16(int16_t v) { - fputc(v & 0xff, outfile); + fputc( v & 0xff, outfile); fputc((v >> 8) & 0xff, outfile); } +static void put32(uint32_t v) +{ + fputc( v & 0xff, outfile); + fputc((v >> 8) & 0xff, outfile); + fputc((v >> 16) & 0xff, outfile); + fputc((v >> 24) & 0xff, outfile); +} + +#define HEADER_SIZE 46 +#define FMT_SIZE 18 +#define SAMPLE_SIZE 2 +#define WFORMAT_PCM 0x0001 + +static void put_wav_header(int sample_rate, int channels, int nb_samples) +{ + int block_align = SAMPLE_SIZE * channels; + int data_size = block_align * nb_samples; + + fputs("RIFF", outfile); + put32(HEADER_SIZE + data_size); + fputs("WAVEfmt ", outfile); + put32(FMT_SIZE); + put16(WFORMAT_PCM); + put16(channels); + put32(sample_rate); + put32(block_align * sample_rate); + put16(block_align); + put16(SAMPLE_SIZE * 8); + put16(0); + fputs("data", outfile); + put32(data_size); +} + int main(int argc, char **argv) { int i, a, v, j, f, amp, ampa; @@ -107,10 +142,12 @@ int main(int argc, char **argv) int taba[MAX_CHANNELS]; int sample_rate = 44100; int nb_channels = 2; + char *ext; if (argc < 2 || argc > 4) { printf("usage: %s file [<sample rate> [<channels>]]\n" "generate a test raw 16 bit audio stream\n" + "If the file extension is .wav a WAVE header will be added.\n" "default: 44100 Hz stereo\n", argv[0]); exit(1); } @@ -137,12 +174,15 @@ int main(int argc, char **argv) return 1; } + if ((ext = strrchr(argv[1], '.')) != NULL && !strcmp(ext, ".wav")) + put_wav_header(sample_rate, nb_channels, 6 * sample_rate); + /* 1 second of single freq sinus at 1000 Hz */ a = 0; for (i = 0; i < 1 * sample_rate; i++) { v = (int_cos(a) * 10000) >> FRAC_BITS; for (j = 0; j < nb_channels; j++) - put_sample(v); + put16(v); a += (1000 * FRAC_ONE) / sample_rate; } @@ -151,7 +191,7 @@ int main(int argc, char **argv) for (i = 0; i < 1 * sample_rate; i++) { v = (int_cos(a) * 10000) >> FRAC_BITS; for (j = 0; j < nb_channels; j++) - put_sample(v); + put16(v); f = 100 + (((10000 - 100) * i) / sample_rate); a += (f * FRAC_ONE) / sample_rate; } @@ -160,14 +200,14 @@ int main(int argc, char **argv) for (i = 0; i < sample_rate / 2; i++) { v = myrnd(&seed, 20000) - 10000; for (j = 0; j < nb_channels; j++) - put_sample(v); + put16(v); } /* 0.5 second of high amplitude white noise */ for (i = 0; i < sample_rate / 2; i++) { v = myrnd(&seed, 65535) - 32768; for (j = 0; j < nb_channels; j++) - put_sample(v); + put16(v); } /* 1 second of unrelated ramps for each channel */ @@ -179,7 +219,7 @@ int main(int argc, char **argv) for (i = 0; i < 1 * sample_rate; i++) { for (j = 0; j < nb_channels; j++) { v = (int_cos(taba[j]) * 10000) >> FRAC_BITS; - put_sample(v); + put16(v); f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); taba[j] += (f * FRAC_ONE) / sample_rate; } @@ -194,7 +234,7 @@ int main(int argc, char **argv) if (j & 1) amp = 10000 - amp; v = (int_cos(a) * amp) >> FRAC_BITS; - put_sample(v); + put16(v); a += (500 * FRAC_ONE) / sample_rate; ampa += (2 * FRAC_ONE) / sample_rate; } |