Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions claxon/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ claxon <input.flac> <output.raw>
The output is what `flac -d --force-raw-format --endian=little --sign=signed` writes:
interleaved, signed, little-endian samples at the stream's own bit depth (8, 16 or 24 bits;
another depth is refused). The stream's parameters go to stderr. Exit status 0 on success, 1 on
any error. Claxon predates RFC 9639: it reads frame-header depth codes for 8, 12, 16, 20 and 24
any error, a stream that ends before the frame count its STREAMINFO declares included. Claxon predates RFC 9639: it reads frame-header depth codes for 8, 12, 16, 20 and 24
bits, refuses the 32-bit code as reserved, and refuses a header that leaves the depth to the
stream info, so a 32-bit stream, or one of a depth without a code of its own, does not decode.

- `src/main.rs` is the program around the crate, this repository's own.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16 and 24 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1.
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error.

## Licence

Expand Down
13 changes: 12 additions & 1 deletion claxon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,24 @@ fn run(input: &str, output: &str) -> Result<(), String> {
);

let mut out = BufWriter::new(File::create(output).map_err(|e| format!("{output}: {e}"))?);
let mut written: u64 = 0;
for sample in reader.samples() {
let sample = sample.map_err(|e| format!("{input}: {e}"))?;
// The low bytes of the two's complement are the sample at its depth.
out.write_all(&sample.to_le_bytes()[..width])
.map_err(|e| format!("{output}: {e}"))?;
written += 1;
}
out.flush().map_err(|e| format!("{output}: {e}"))?;
// Claxon ends without an error where the input does, at a frame boundary.
let channels = u64::from(info.channels);
match info.samples {
Some(declared) if declared > 0 && written != declared * channels => Err(format!(
"{input}: decoded {} frames, the stream declares {declared}",
written / channels
)),
_ => Ok(()),
}
out.flush().map_err(|e| format!("{output}: {e}"))
}

fn main() -> ExitCode {
Expand Down
3 changes: 2 additions & 1 deletion cscoreflac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ does not let a program catch; the process dies, with a nonzero exit status.
`just cscoreflac-lock` rewrites it.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16 and 24 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1.
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error.

## Licence

Expand Down
3 changes: 2 additions & 1 deletion drflac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ any error.
- `build.sh` compiles it for one zig target.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16, 24 and 32 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1.
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error.

## Licence

Expand Down
5 changes: 3 additions & 2 deletions foxenflac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ libfoxenflac reads the frame-header depth codes for 8, 12, 16, 20 and 24 bits an
32-bit stream does not decode; 12 and 20 bits decode but have no whole-byte raw form and are
refused. libfoxenflac left-justifies every depth in 32 bits; the program shifts each sample back.
The stream's parameters go to stderr. Exit status 0 on success, 1 on any error, a stream that
ends before the frame count its STREAMINFO declares included.
ends before its stream info or before the frame count its STREAMINFO declares included.

- `main.c` is the program around the library, this repository's own.
- `build.sh` compiles it and `src/foxen-flac.c` for one zig target.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16 and 24 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1.
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error.

## Licence

Expand Down
3 changes: 3 additions & 0 deletions foxenflac/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ int main(int argc, char **argv) {
if (have == sizeof(buf)) return fail(input, "the decoder makes no progress");
}
}
/* libfoxenflac is fed bytes and never told they ended: only here is it
* known that the stream info never came. */
if (width == 0) return fail(input, "the input ends before the stream info");
if (channels > 0 && declared > 0 && written != (unsigned long long)(declared * channels)) {
fprintf(stderr, "foxenflac: %s: decoded %llu frames, the stream declares %lld\n", input,
written / (unsigned long long)channels, declared);
Expand Down
7 changes: 4 additions & 3 deletions microflac/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ The output is what `flac -d --force-raw-format --endian=little --sign=signed` wr
interleaved, signed, little-endian samples at the stream's own bit depth (8, 16, 24 or 32 bits;
another depth is refused), which is microFLAC's own byte-packed output on every host. Frame CRCs
are checked (microFLAC's default). The stream's parameters go to stderr. Exit status 0 on
success, 1 on any error, a stream that ends before the frame count its STREAMINFO declares
included.
success, 1 on any error, a stream that ends before its stream info or before the frame count its
STREAMINFO declares included.

- `main.cpp` is the program around the library, this repository's own.
- `build.sh` compiles it and microFLAC's decoder sources (`cmake/sources.cmake`'s) for one zig
target.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16, 24 and 32 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1.
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error.

## Licence

Expand Down
3 changes: 3 additions & 0 deletions microflac/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ int main(int argc, char **argv) {
}
if (std::fclose(out) != 0) return fail(output, "write error");

// microFLAC is fed bytes and never told they ended: only here is it known
// that the stream info never came.
if (channels == 0) return fail(input, "the input ends before the stream info");
const uint64_t declared = decoder.get_stream_info().total_samples_per_channel();
if (channels > 0 && declared > 0 && written != declared * channels) {
std::fprintf(stderr, "microflac: %s: decoded %llu frames, the stream declares %llu\n", input,
Expand Down
26 changes: 23 additions & 3 deletions scripts/decoder-smoke.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
# What each FLAC decoder program here is held to: its own part, the program
# around someone else's decoder. The bytes flac encoded come back, in the raw
# form its README names, at every depth given; the stream's parameters go to
# stderr; and without arguments it prints its usage and exits 1. What the
# library under it does with a stream it gets wrong or cannot read is the
# library's, and is not tested here.
# stderr; without arguments it prints its usage and exits 1; and an input that
# ends before its stream does is an error, which only the program can know:
# the libraries are fed bytes and never told they ended. What the library
# under it does with a stream it gets wrong or cannot read is the library's,
# and is not tested here.
# decoder-smoke.sh <name> <directory holding it> <directory holding flac> <depths>
# The depths are one argument ("8 16 24").
set -euo pipefail
Expand Down Expand Up @@ -46,3 +48,21 @@ for bps in "${depths[@]}"; do
{ cat "${work}/stderr" >&2; echo "${name}: ${bps}-bit: the stream's parameters are not on stderr" >&2; exit 1; }
echo "${name}: ${bps}-bit round trip through flac identical"
done

# An input that ends early is an error, as it is to `flac -d`: inside the
# stream marker, and at a frame boundary, where a library sees nothing wrong.
# The second is the whole stream cut to the length of a stream of its first
# blocks: without a seek table the two differ in their stream info alone.
head -c 3 "${work}/a-16.flac" > "${work}/marker.flac"
part=$((bytes / 2 / 16384 * 16384))
head -c "${part}" "${work}/in.raw" > "${work}/part.raw"
for stream in in part; do
"${flac}" -s "${raw[@]}" --no-seektable --channels=2 --bps=16 --sample-rate=44100 -o "${work}/${stream}.flac" "${work}/${stream}.raw"
done
head -c "$(wc -c < "${work}/part.flac" | tr -d ' ')" "${work}/in.flac" > "${work}/boundary.flac"
for cut in marker boundary; do
status=0
"${decoder}" "${work}/${cut}.flac" "${work}/${cut}.raw" 2> "${work}/stderr" || status=$?
[ "${status}" -ne 0 ] || { echo "${name}: an input cut short (${cut}): exit status 0" >&2; exit 1; }
echo "${name}: an input cut short (${cut}) is an error"
done
3 changes: 2 additions & 1 deletion symphonia/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ success, 1 on any error, a frame Symphonia cannot decode included.
- `src/main.rs` is the program around the crates, this repository's own.
- `smoke.sh` runs `scripts/decoder-smoke.sh`, the test every decoder program here is held to: PCM
encoded by the `flac` build at 8, 16 and 24 bits comes back byte for byte, with the stream's
parameters on stderr, and without arguments the program prints its usage and exits 1. Not at 32
parameters on stderr, without arguments the program prints its usage and exits 1, and an input cut short is an
error. Not at 32
bits, for the reason above.

## Licence
Expand Down
Loading