mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
add more tests and with more variety
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/time.h>
|
||||
#include "FLAC/ordinals.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
@@ -184,7 +185,7 @@ foo:
|
||||
}
|
||||
|
||||
/* a mono sine-wave 16bps stream */
|
||||
static bool generate_sine16(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
|
||||
static bool generate_sine16_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
|
||||
{
|
||||
const signed short full_scale = 32767;
|
||||
const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
|
||||
@@ -211,6 +212,67 @@ foo:
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a stereo sine-wave 16bps stream */
|
||||
static bool generate_sine16_2(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2, double fmult)
|
||||
{
|
||||
const signed short full_scale = 32767;
|
||||
const double delta1 = 2.0 * M_PI / ( sample_rate / f1);
|
||||
const double delta2 = 2.0 * M_PI / ( sample_rate / f2);
|
||||
FILE *f;
|
||||
double theta1, theta2;
|
||||
unsigned i;
|
||||
|
||||
if(0 == (f = fopen(fn, mode)))
|
||||
return false;
|
||||
|
||||
for(i = 0, theta1 = theta2 = 0.0; i < samples; i++, theta1 += delta1, theta2 += delta2) {
|
||||
double val = (a1*sin(theta1) + a2*sin(theta2))*(double)full_scale;
|
||||
int16 v = (int16)(val + 0.5);
|
||||
swap16(&v);
|
||||
if(fwrite(&v, sizeof(v), 1, f) < 1)
|
||||
goto foo;
|
||||
val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
|
||||
v = (int16)(val + 0.5);
|
||||
swap16(&v);
|
||||
if(fwrite(&v, sizeof(v), 1, f) < 1)
|
||||
goto foo;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
foo:
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool generate_noise(const char *fn, unsigned bytes)
|
||||
{
|
||||
FILE *f;
|
||||
struct timeval tv;
|
||||
unsigned b;
|
||||
|
||||
if(gettimeofday(&tv, 0) < 0) {
|
||||
fprintf(stderr, "WARNING: couldn't seed RNG with time\n");
|
||||
tv.tv_usec = 4321;
|
||||
}
|
||||
srandom(tv.tv_usec);
|
||||
|
||||
if(0 == (f = fopen(fn, mode)))
|
||||
return false;
|
||||
|
||||
for(b = 0; b < bytes; b++) {
|
||||
byte x = (byte)(((unsigned)random()) & 0xff);
|
||||
if(fwrite(&x, sizeof(x), 1, f) < 1)
|
||||
goto foo;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
foo:
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
uint32 test = 1;
|
||||
@@ -248,11 +310,24 @@ int main(int argc, char *argv[])
|
||||
if(!generate_fsd16("fsd16-06.raw", pattern06, 100)) return 1;
|
||||
if(!generate_fsd16("fsd16-07.raw", pattern07, 100)) return 1;
|
||||
|
||||
if(!generate_sine16("sine-01.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1;
|
||||
if(!generate_sine16("sine-02.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1;
|
||||
if(!generate_sine16("sine-03.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1;
|
||||
if(!generate_sine16("sine-04.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1;
|
||||
if(!generate_sine16("sine-05.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
|
||||
if(!generate_sine16_1("sine-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1;
|
||||
if(!generate_sine16_1("sine-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
|
||||
|
||||
if(!generate_sine16_2("sine-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
|
||||
if(!generate_sine16_2("sine-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
|
||||
if(!generate_sine16_2("sine-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
|
||||
if(!generate_sine16_2("sine-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
|
||||
if(!generate_sine16_2("sine-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
|
||||
|
||||
if(!generate_noise("noise.raw", 65536 * 2)) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user