Commit b903670f authored by Erik de Castro Lopo's avatar Erik de Castro Lopo
Browse files

replaygain test: Use C code to generate test files.

parent a0277fc6
......@@ -1043,6 +1043,41 @@ foo:
return false;
}
static FLAC__bool generate_replaygain_tone (unsigned samplerate)
{
FILE *f;
char fname [256] ;
double pi, tone, sample, samplerange;
int k;
snprintf(fname, sizeof(fname), "rpg-tone-%u.wav", samplerate);
if(0 == (f = flac_fopen(fname, "wb")))
return false;
if(!write_simple_wavex_header (f, samplerate, 1, 3, 220500))
goto foo;
samplerange = 0x7fffff; /* Largest sample value allowed for a 24 bit PCM file. */
tone = 1000.0; /* 1 kHz */
pi = 4 * atan2(1,1);
for (k = 0 ; k < 5 * 44100 ; k++) {
sample = sin(2 * pi * tone * k / samplerate);
sample *= samplerange;
if (!write_little_endian_uint24(f, (FLAC__int32) sample))
goto foo;
};
fclose(f);
return true;
foo:
fclose(f);
return false;
}
int main(int argc, char *argv[])
{
FLAC__uint32 test = 1;
......@@ -1156,6 +1191,22 @@ int main(int argc, char *argv[])
if(!generate_sine24_2("sine24-18.raw", 44100.0, 200000, 441.0, 0.50, 4410.0, 0.49, 1.3)) return 1;
if(!generate_sine24_2("sine24-19.raw", 44100.0, 200000, 8820.0, 0.70, 4410.0, 0.29, 0.1)) return 1;
if(!generate_replaygain_tone(8000)) return 1;
if(!generate_replaygain_tone(11025)) return 1;
if(!generate_replaygain_tone(12000)) return 1;
if(!generate_replaygain_tone(16000)) return 1;
if(!generate_replaygain_tone(18900)) return 1;
if(!generate_replaygain_tone(22050)) return 1;
if(!generate_replaygain_tone(24000)) return 1;
if(!generate_replaygain_tone(28000)) return 1;
if(!generate_replaygain_tone(32000)) return 1;
if(!generate_replaygain_tone(36000)) return 1;
if(!generate_replaygain_tone(37800)) return 1;
if(!generate_replaygain_tone(44100)) return 1;
if(!generate_replaygain_tone(48000)) return 1;
if(!generate_replaygain_tone(96000)) return 1;
if(!generate_replaygain_tone(192000)) return 1;
/* WATCHOUT: the size of noise.raw is hardcoded into test/test_flac.sh */
if(!generate_noise("noise.raw", 65536 * 8 * 3)) return 1;
if(!generate_noise("noise8m32.raw", 32)) return 1;
......
......@@ -81,66 +81,22 @@ fi
check_flac
if mawk ; then
AWK=mawk
else
# Really hope awk is not gawk, because the following AWK script doesn't
# work correctly with gawk 4.0.1 but did with earlier versions.
AWK=awk
fi
# Replay gain tests - Test the rates which have specific filter table entries
# and verify that harmonics can be processed correctly.
tonegenerator ()
{
# When using GAWK, use --lint=posix to identify non-POSIX awk usages.
$AWK -- '
BEGIN {
samplerate = '$1';
tone = 1000;
duration = 1;
bitspersample = 24;
samplemidpoint = 1;
for (sps = 0 ; sps < bitspersample - 1 ; sps++) {
samplemidpoint *= 2;
}
samplerange = samplemidpoint - 1;
pi = 4 * atan2(1,1);
for (ix = 0; ix < duration * samplerate; ++ix) {
sample = sin(2 * pi * tone * ix / samplerate);
sample *= samplerange;
sample += samplemidpoint;
sample = int(sample);
for (bx = 0; bx < bitspersample/8; ++bx) {
byte[bx] = sample % 256;
sample /= 256;
}
while (bx--) {
printf("%c", byte[bx]);
}
}
}' /dev/null |
flac${EXE} --force --output-name=$2 \
--silent --no-seektable --no-error-on-compression-fail --force-raw-format \
--endian=big --channels=1 --bps=24 --sample-rate=$1 --sign=unsigned -
flac${EXE} --force --output-name=$2 --silent --no-seektable --no-error-on-compression-fail rpg-tone-$1.wav
}
REPLAYGAIN_FREQ=
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.76"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.93"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-13.00"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.29"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.43"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 8000/-12.73"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 11025/-12.91"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 12000/-12.98"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 16000/-13.27"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 18900/-13.41"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 22050/-13.77"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.83"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 24000/-13.82"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 28000/-14.06"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 32000/-14.08"
REPLAYGAIN_FREQ="$REPLAYGAIN_FREQ 36000/-14.12"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment