5
5
* Copyright (c) 2002 Fabrice Bellard
7
* This file is part of FFmpeg.
7
* This file is part of Libav.
9
* FFmpeg is free software; you can redistribute it and/or
9
* Libav is free software; you can redistribute it and/or
10
10
* modify it under the terms of the GNU Lesser General Public
11
11
* License as published by the Free Software Foundation; either
12
12
* version 2.1 of the License, or (at your option) any later version.
14
* FFmpeg is distributed in the hope that it will be useful,
14
* Libav is distributed in the hope that it will be useful,
15
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
17
* Lesser General Public License for more details.
19
19
* You should have received a copy of the GNU Lesser General Public
20
* License along with FFmpeg; if not, write to the Free Software
20
* License along with Libav; if not, write to the Free Software
21
21
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24
24
#include <stdlib.h>
27
#define MAX_CHANNELS 8
30
29
static unsigned int myrnd(unsigned int *seed_ptr, int n)
105
104
int i, a, v, j, f, amp, ampa;
106
105
unsigned int seed = 1;
107
int tabf1[NB_CHANNELS], tabf2[NB_CHANNELS];
108
int taba[NB_CHANNELS];
106
int tabf1[MAX_CHANNELS], tabf2[MAX_CHANNELS];
107
int taba[MAX_CHANNELS];
108
int sample_rate = 44100;
111
printf("usage: %s file\n"
112
"generate a test raw 16 bit stereo audio stream\n", argv[0]);
111
if (argc < 2 || argc > 4) {
112
printf("usage: %s file [<sample rate> [<channels>]]\n"
113
"generate a test raw 16 bit audio stream\n"
114
"default: 44100 Hz stereo\n", argv[0]);
119
sample_rate = atoi(argv[2]);
120
if (sample_rate <= 0) {
121
fprintf(stderr, "invalid sample rate: %d\n", sample_rate);
127
nb_channels = atoi(argv[3]);
128
if (nb_channels < 1 || nb_channels > MAX_CHANNELS) {
129
fprintf(stderr, "invalid number of channels: %d\n", nb_channels);
116
134
outfile = fopen(argv[1], "wb");
122
140
/* 1 second of single freq sinus at 1000 Hz */
124
for(i=0;i<1 * FE;i++) {
142
for(i=0;i<1 * sample_rate;i++) {
125
143
v = (int_cos(a) * 10000) >> FRAC_BITS;
126
for(j=0;j<NB_CHANNELS;j++)
144
for(j=0;j<nb_channels;j++)
128
a += (1000 * FRAC_ONE) / FE;
146
a += (1000 * FRAC_ONE) / sample_rate;
131
149
/* 1 second of varing frequency between 100 and 10000 Hz */
133
for(i=0;i<1 * FE;i++) {
151
for(i=0;i<1 * sample_rate;i++) {
134
152
v = (int_cos(a) * 10000) >> FRAC_BITS;
135
for(j=0;j<NB_CHANNELS;j++)
153
for(j=0;j<nb_channels;j++)
137
f = 100 + (((10000 - 100) * i) / FE);
138
a += (f * FRAC_ONE) / FE;
155
f = 100 + (((10000 - 100) * i) / sample_rate);
156
a += (f * FRAC_ONE) / sample_rate;
141
159
/* 0.5 second of low amplitude white noise */
142
for(i=0;i<FE / 2;i++) {
160
for(i=0;i<sample_rate / 2;i++) {
143
161
v = myrnd(&seed, 20000) - 10000;
144
for(j=0;j<NB_CHANNELS;j++)
162
for(j=0;j<nb_channels;j++)
148
166
/* 0.5 second of high amplitude white noise */
149
for(i=0;i<FE / 2;i++) {
167
for(i=0;i<sample_rate / 2;i++) {
150
168
v = myrnd(&seed, 65535) - 32768;
151
for(j=0;j<NB_CHANNELS;j++)
169
for(j=0;j<nb_channels;j++)
155
/* stereo : 2 unrelated ramps */
156
for(j=0;j<NB_CHANNELS;j++) {
173
/* 1 second of unrelated ramps for each channel */
174
for(j=0;j<nb_channels;j++) {
158
176
tabf1[j] = 100 + myrnd(&seed, 5000);
159
177
tabf2[j] = 100 + myrnd(&seed, 5000);
161
for(i=0;i<1 * FE;i++) {
162
for(j=0;j<NB_CHANNELS;j++) {
179
for(i=0;i<1 * sample_rate;i++) {
180
for(j=0;j<nb_channels;j++) {
163
181
v = (int_cos(taba[j]) * 10000) >> FRAC_BITS;
165
f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / FE);
166
taba[j] += (f * FRAC_ONE) / FE;
183
f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate);
184
taba[j] += (f * FRAC_ONE) / sample_rate;
170
/* stereo 500 Hz with varying volume */
188
/* 2 seconds of 500 Hz with varying volume */
173
for(i=0;i<2 * FE;i++) {
174
for(j=0;j<NB_CHANNELS;j++) {
191
for(i=0;i<2 * sample_rate;i++) {
192
for(j=0;j<nb_channels;j++) {
175
193
amp = ((FRAC_ONE + int_cos(ampa)) * 5000) >> FRAC_BITS;
177
195
amp = 10000 - amp;
178
196
v = (int_cos(a) * amp) >> FRAC_BITS;
180
a += (500 * FRAC_ONE) / FE;
181
ampa += (2 * FRAC_ONE) / FE;
198
a += (500 * FRAC_ONE) / sample_rate;
199
ampa += (2 * FRAC_ONE) / sample_rate;