#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <tests.h>
int main(int argc, char **argv)
{
FILE* file;
int length = 100 * 1000;
double framesPerSec = FRAME_RATE_NUM/(double)FRAME_RATE_DEN;
int sampleRate = SAMPLE_RATE;
int debuglevel = 1;
char *filename = "output.raw";
int total = 0;
if (argc > 1) {
filename = argv[1];
if (argc > 2) {
sscanf(argv[2], "%i", &sampleRate);
}
if (argc > 3) {
sscanf(argv[3], "%lf", &framesPerSec);
}
if (argc > 4) {
sscanf(argv[4], "%i", &length);
}
} else {
printf("Usage: %s <filename> [sample rate [frame rate [duration in ms]]]\n", argv[0]);
printf("The encoder creates " SAMPLE_TYPE " native endian raw audio at currently %i Hz sampling rate.\n", sampleRate);
return -1;
}
#ifdef ENABLE_DATE
int i = 0;
char timezone[6] = "+0100";
#endif
#if 0
#else
#endif
if (debuglevel > 1)
printf("writing to: %s\n", filename);
file = fopen(filename, "wb");
if (debuglevel > 0)
{
printf("samples are %s native endian\n", SAMPLE_TYPE);
printf("sample rate = %i\n", sampleRate);
printf("frames/sec = %.2lf\n", framesPerSec);
}
int current_time = start_time;
int max_time = current_time + length;
#ifdef TRACK_SAMPLES_PER_FRAME
int samples_per_frame;
#endif
int this_second_end = current_time + 1000;
while (current_time < max_time)
{
int byteCnt;
#ifdef TRACK_SAMPLES_PER_FRAME
samples_per_frame = 0;
#endif
for (byteCnt = 0 ; byteCnt < 10 ; byteCnt++)
{
if (len > 0)
{
fwrite(buf,
sizeof(
sample_t), len, file);
}
if (debuglevel > 4)
{
printf(
"DEBUG: wrote %lu bytes.\n", (
unsigned long)len*
sizeof(
sample_t));
}
#ifdef TRACK_SAMPLES_PER_FRAME
samples_per_frame += len;
#endif
}
#ifdef TRACK_SAMPLES_PER_FRAME
printf("DEBUG: current frame length: %i samples.\n", samples_per_frame);
#endif
if (current_time >= this_second_end)
{
if (debuglevel > 3)
{
}
this_second_end += 1000;
}
}
if (debuglevel > 0)
{
printf("DONE: wrote %.4f seconds == %i samples\n", (current_time-start_time)/1000.0, total);
}
fclose(file);
return 0;
}