mirror of
https://github.com/claunia/flac.git
synced 2025-12-16 18:54:26 +00:00
add support for new 24-bit streams
This commit is contained in:
@@ -41,6 +41,20 @@ static void swap16(int16 *i)
|
||||
}
|
||||
}
|
||||
|
||||
static void swap24(byte *x)
|
||||
{
|
||||
if(is_big_endian_host) {
|
||||
x[0] = x[1];
|
||||
x[1] = x[2];
|
||||
x[2] = x[3];
|
||||
}
|
||||
else {
|
||||
byte b = x[0];
|
||||
x[0] = x[2];
|
||||
x[2] = b;
|
||||
}
|
||||
}
|
||||
|
||||
/* a mono one-sample 16bps stream */
|
||||
static bool generate_01()
|
||||
{
|
||||
@@ -184,10 +198,38 @@ foo:
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a mono full-scale deflection 24bps stream */
|
||||
static bool generate_fsd24(const char *fn, const int pattern[], unsigned reps)
|
||||
{
|
||||
FILE *f;
|
||||
unsigned rep, p;
|
||||
|
||||
assert(pattern != 0);
|
||||
|
||||
if(0 == (f = fopen(fn, mode)))
|
||||
return false;
|
||||
|
||||
for(rep = 0; rep < reps; rep++) {
|
||||
for(p = 0; pattern[p]; p++) {
|
||||
int32 x = pattern[p] > 0? 8388607 : -8388608;
|
||||
byte *b = (byte*)(&x);
|
||||
swap24(b);
|
||||
if(fwrite(b, 3, 1, f) < 1)
|
||||
goto foo;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
foo:
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a mono sine-wave 16bps stream */
|
||||
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 int16 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;
|
||||
@@ -215,7 +257,7 @@ foo:
|
||||
/* 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 int16 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;
|
||||
@@ -245,6 +287,69 @@ foo:
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a mono sine-wave 24bps stream */
|
||||
static bool generate_sine24_1(const char *fn, const double sample_rate, const unsigned samples, const double f1, const double a1, const double f2, const double a2)
|
||||
{
|
||||
const int32 full_scale = 0x7fffff;
|
||||
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;
|
||||
int32 v = (int32)(val + 0.5);
|
||||
byte *b = (byte*)(&v);
|
||||
swap24(b);
|
||||
if(fwrite(b, 3, 1, f) < 1)
|
||||
goto foo;
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
return true;
|
||||
foo:
|
||||
fclose(f);
|
||||
return false;
|
||||
}
|
||||
|
||||
/* a stereo sine-wave 24bps stream */
|
||||
static bool generate_sine24_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 int32 full_scale = 0x7fffff;
|
||||
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;
|
||||
int32 v = (int32)(val + 0.5);
|
||||
byte *b = (byte*)(&v);
|
||||
swap24(b);
|
||||
if(fwrite(b, 3, 1, f) < 1)
|
||||
goto foo;
|
||||
val = -(a1*sin(theta1*fmult) + a2*sin(theta2*fmult))*(double)full_scale;
|
||||
v = (int32)(val + 0.5);
|
||||
swap24(b);
|
||||
if(fwrite(b, 3, 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;
|
||||
@@ -310,24 +415,49 @@ 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_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_fsd24("fsd24-01.raw", pattern01, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-02.raw", pattern02, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-03.raw", pattern03, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-04.raw", pattern04, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-05.raw", pattern05, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-06.raw", pattern06, 100)) return 1;
|
||||
if(!generate_fsd24("fsd24-07.raw", pattern07, 100)) 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_sine16_1("sine16-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine16-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1;
|
||||
if(!generate_sine16_1("sine16-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine16-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1;
|
||||
if(!generate_sine16_1("sine16-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
|
||||
|
||||
if(!generate_noise("noise.raw", 65536 * 2)) return 1;
|
||||
if(!generate_sine16_2("sine16-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
|
||||
if(!generate_sine16_2("sine16-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
|
||||
if(!generate_sine16_2("sine16-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
|
||||
if(!generate_sine16_2("sine16-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
|
||||
if(!generate_sine16_2("sine16-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
|
||||
|
||||
if(!generate_sine24_1("sine24-00.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49)) return 1;
|
||||
if(!generate_sine24_1("sine24-01.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37)) return 1;
|
||||
if(!generate_sine24_1("sine24-02.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49)) return 1;
|
||||
if(!generate_sine24_1("sine24-03.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49)) return 1;
|
||||
if(!generate_sine24_1("sine24-04.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29)) return 1;
|
||||
|
||||
if(!generate_sine24_2("sine24-10.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-11.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 1.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-12.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-13.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-14.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 1.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-15.raw", 44100.0, 80000, 441.0, 0.50, 441.0, 0.49, 0.5)) return 1;
|
||||
if(!generate_sine24_2("sine24-16.raw", 44100.0, 80000, 441.0, 0.61, 661.5, 0.37, 2.0)) return 1;
|
||||
if(!generate_sine24_2("sine24-17.raw", 44100.0, 80000, 441.0, 0.50, 882.0, 0.49, 0.7)) return 1;
|
||||
if(!generate_sine24_2("sine24-18.raw", 44100.0, 80000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
|
||||
if(!generate_sine24_2("sine24-19.raw", 44100.0, 50000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
|
||||
|
||||
if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user