initial import

This commit is contained in:
Josh Coalson 2002-12-10 06:41:27 +00:00
parent 8f0c71b877
commit 463d0f80de
3 changed files with 410 additions and 0 deletions

130
src/flac/utils.c Normal file
View File

@ -0,0 +1,130 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#if HAVE_CONFIG_H
# include <config.h>
#endif
#include "utils.h"
#include "FLAC/assert.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>
static FLAC__bool local__parse_uint64_(const char *s, FLAC__uint64 *value)
{
FLAC__uint64 ret = 0;
char c;
if(*s == '\0')
return false;
while('\0' != (c = *s++))
if(c >= '0' && c <= '9')
ret = ret * 10 + (c - '0');
else
return false;
*value = ret;
return true;
}
static FLAC__bool local__parse_timecode_(const char *s, double *value)
{
double ret;
unsigned i;
char c;
/* parse [0-9][0-9]*: */
c = *s++;
if(c >= '0' && c <= '9')
i = (c - '0');
else
return false;
while(':' != (c = *s++)) {
if(c >= '0' && c <= '9')
i = i * 10 + (c - '0');
else
return false;
}
ret = (double)i * 60.;
/* parse [0-9]*[.]?[0-9]* i.e. a sign-less rational number */
if(strspn(s, "1234567890.") != strlen(s))
return false;
{
const char *p = strchr(s, '.');
if(p && 0 != strchr(++p, '.'))
return false;
}
ret += atof(s);
*value = ret;
return true;
}
FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec)
{
FLAC__uint64 val;
FLAC__bool is_negative = false;
FLAC__ASSERT(0 != spec);
spec->is_relative = false;
spec->value_is_samples = true;
spec->value.samples = 0;
if(0 != s) {
if(s[0] == '-') {
is_negative = true;
spec->is_relative = true;
s++;
}
else if(s[0] == '+') {
spec->is_relative = true;
s++;
}
if(local__parse_uint64_(s, &val)) {
spec->value_is_samples = true;
spec->value.samples = (FLAC__int64)val;
if(is_negative)
spec->value.samples = -(spec->value.samples);
}
else {
double d;
if(!local__parse_timecode_(s, &d))
return false;
spec->value_is_samples = false;
spec->value.seconds = d;
if(is_negative)
spec->value.seconds = -(spec->value.seconds);
}
}
return true;
}
void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, unsigned sample_rate)
{
FLAC__ASSERT(0 != spec);
if(!spec->value_is_samples) {
spec->value.samples = (FLAC__int64)(spec->value.seconds * (double)sample_rate);
spec->value_is_samples = true;
}
}

36
src/flac/utils.h Normal file
View File

@ -0,0 +1,36 @@
/* flac - Command-line FLAC encoder/decoder
* Copyright (C) 2002 Josh Coalson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef flac__utils_h
#define flac__utils_h
#include "FLAC/ordinals.h"
typedef struct {
FLAC__bool is_relative; /* i.e. specification string started with + or - */
FLAC__bool value_is_samples;
union {
double seconds;
FLAC__int64 samples;
} value;
} utils__SkipUntilSpecification;
FLAC__bool flac__utils_parse_skip_until_specification(const char *s, utils__SkipUntilSpecification *spec);
void flac__utils_canonicalize_skip_until_specification(utils__SkipUntilSpecification *spec, unsigned sample_rate);
#endif

244
test/test_flac.sh Executable file
View File

@ -0,0 +1,244 @@
#!/bin/sh
# FLAC - Free Lossless Audio Codec
# Copyright (C) 2001,2002 Josh Coalson
#
# This program is part of FLAC; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
LD_LIBRARY_PATH=../src/libFLAC/.libs:../obj/release/lib:../obj/debug/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
PATH=../src/flac:../src/test_streams:../obj/release/bin:../obj/debug/bin:$PATH
flac --help 1>/dev/null 2>/dev/null || (echo "ERROR can't find flac executable" 1>&2 && exit 1)
if [ $? != 0 ] ; then exit 1 ; fi
run_flac ()
{
if [ "$FLAC__VALGRIND" = yes ] ; then
valgrind --leak-check=yes --show-reachable=yes --num-callers=10 --logfile-fd=4 flac $* 4>>valgrind.log
else
flac $*
fi
}
echo "Checking for --ogg support in flac..."
if flac --ogg --silent --force-raw-format --endian=little --sign=signed --channels=1 --bps=8 --sample-rate=44100 -c $0 1>/dev/null 2>&1 ; then
has_ogg=yes;
echo "flac --ogg works"
else
has_ogg=no;
echo "flac --ogg doesn't work"
fi
#
# test --skip
#
echo "123456789012345678901234567890123456789" > 39c.raw
echo "012345678901234567890123456789012345678" > 39cu.raw
echo "0123456789012345678901234567890123456789" > 40c.raw
echo "01234567890123456789012345678901234567890123456789" > 50c.raw
# test encode --skip=#
echo "testing --skip=# (encode)"
if run_flac --silent --verify --lax --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1 --skip=10 -o 50c.skip10.flac 50c.raw ; then : ; else
echo "ERROR generating FLAC file" 1>&2
exit 1
fi
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed -o 50c.skip10.raw 50c.skip10.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 40c.raw 50c.skip10.raw ; then : ; else
echo "ERROR: file mismatch for --skip=10 (encode)" 1>&2
exit 1
fi
rm -f 50c.skip10.flac 50c.skip10.raw
echo OK
# test encode --skip=mm:ss
echo "testing --skip=mm:ss (encode)"
if run_flac --silent --verify --lax --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1 --skip=0:01 -o 50c.skip0:01.flac 50c.raw ; then : ; else
echo "ERROR generating FLAC file" 1>&2
exit 1
fi
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed -o 50c.skip0:01.raw 50c.skip0:01.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 40c.raw 50c.skip0:01.raw ; then : ; else
echo "ERROR: file mismatch for --skip=0:01 (encode)" 1>&2
exit 1
fi
rm -f 50c.skip0:01.flac 50c.skip0:01.raw
echo OK
# test encode --skip=mm:ss.sss
echo "testing --skip=mm:ss.sss (encode)"
if run_flac --silent --verify --lax --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1 --skip=0:01.1 -o 50c.skip0:01.1.flac 50c.raw ; then : ; else
echo "ERROR generating FLAC file" 1>&2
exit 1
fi
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed -o 50c.skip0:01.1.raw 50c.skip0:01.1.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 39c.raw 50c.skip0:01.1.raw ; then : ; else
echo "ERROR: file mismatch for --skip=0:01.1 (encode)" 1>&2
exit 1
fi
rm -f 50c.skip0:01.1.flac 50c.skip0:01.1.raw
echo OK
# test decode --skip=#
echo "testing --skip=# (decode)"
if run_flac --silent --verify --lax --force-raw-format --endian=big --sign=signed --sample-rate=10 --bps=8 --channels=1 -o 50c.flac 50c.raw ; then : ; else
echo "ERROR generating FLAC file" 1>&2
exit 1
fi
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed --skip=10 -o 50c.skip10.raw 50c.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 40c.raw 50c.skip10.raw ; then : ; else
echo "ERROR: file mismatch for --skip=10 (decode)" 1>&2
exit 1
fi
rm -f 50c.skip10.raw
echo OK
# test decode --skip=mm:ss
echo "testing --skip=mm:ss (decode)"
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed --skip=0:01 -o 50c.skip0:01.raw 50c.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 40c.raw 50c.skip0:01.raw ; then : ; else
echo "ERROR: file mismatch for --skip=0:01 (decode)" 1>&2
exit 1
fi
rm -f 50c.skip0:01.raw
echo OK
# test decode --skip=mm:ss.sss
echo "testing --skip=mm:ss.sss (decode)"
if run_flac --silent --decode --force-raw-format --endian=big --sign=signed --skip=0:01.1 -o 50c.skip0:01.1.raw 50c.flac ; then : ; else
echo "ERROR decoding FLAC file" 1>&2
exit 1
fi
if cmp 39c.raw 50c.skip0:01.1.raw ; then : ; else
echo "ERROR: file mismatch for --skip=0:01.1 (decode)" 1>&2
exit 1
fi
rm -f 50c.skip0:01.1.raw
echo OK
rm -f 50c.flac
#
# multi-file tests
#
echo "Generating streams..."
if [ ! -f wacky1.wav ] ; then
if test_streams ; then : ; else
echo "ERROR during test_streams" 1>&2
exit 1
fi
fi
echo "Generating multiple input files from noise..."
if run_flac --verify --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 noise.raw ; then : ; else
echo "ERROR generating FLAC file" 1>&2
exit 1
fi
if run_flac --decode --silent noise.flac ; then : ; else
echo "ERROR generating WAVE file" 1>&2
exit 1
fi
rm -f noise.flac
mv noise.wav file0.wav
cp file0.wav file1.wav
cp file1.wav file2.wav
test_multifile ()
{
streamtype=$1
sector_align=$2
encode_options="$3"
if [ $streamtype = ogg ] ; then
suffix=ogg
encode_options="$encode_options --ogg"
else
suffix=flac
fi
if [ $sector_align = sector_align ] ; then
encode_options="$encode_options --sector-align"
fi
if run_flac $encode_options file0.wav file1.wav file2.wav ; then : ; else
echo "ERROR" 1>&2
exit 1
fi
for n in 0 1 2 ; do
mv file$n.$suffix file${n}x.$suffix
done
if run_flac --decode file0x.$suffix file1x.$suffix file2x.$suffix ; then : ; else
echo "ERROR" 1>&2
exit 1
fi
if [ $sector_align != sector_align ] ; then
for n in 0 1 2 ; do
if cmp file$n.wav file${n}x.wav ; then : ; else
echo "ERROR: file mismatch on file #$n" 1>&2
exit 1
fi
done
fi
for n in 0 1 2 ; do
rm -f file${n}x.$suffix file${n}x.wav
done
}
echo "Testing multiple files without verify..."
test_multifile flac no_sector_align ""
echo "Testing multiple files with verify..."
test_multifile flac no_sector_align "--verify"
echo "Testing multiple files with --sector-align, without verify..."
test_multifile flac sector_align ""
echo "Testing multiple files with --sector-align, with verify..."
test_multifile flac sector_align "--verify"
if [ $has_ogg = "yes" ] ; then
echo "Testing multiple files with --ogg, without verify..."
test_multifile ogg no_sector_align ""
echo "Testing multiple files with --ogg, with verify..."
test_multifile ogg no_sector_align "--verify"
echo "Testing multiple files with --ogg and --sector-align, without verify..."
test_multifile ogg sector_align ""
echo "Testing multiple files with --ogg and --sector-align, with verify..."
test_multifile sector_align ogg "--verify"
echo "Testing multiple files with --ogg and --serial-number, with verify..."
test_multifile ogg no_sector_align "--serial-number=321 --verify"
fi