flacdec.library 1.1
===================
A shared library that decodes FLAC (Free Lossless Audio Codec) to
16-bit PCM for AmigaOS 3, bit for bit what the reference decoder
gives. Inside is dr_flac by David Reid, with its decoding loops
(LPC prediction, Rice residuals, stereo output) rewritten in 68020
assembler and tuned for the Apollo 68080.
Programs that use it: AmiPlexAmp (Plex client), and yours: the
interface is five functions (see Developer/).
Three builds
------------
Libs/flacdec.library any 68020 or better. On a 68060 use the
68060 build: the 24-bit prediction here
needs an instruction that 68060.library
has to emulate
Libs/flacdec.library.060 68060 only (and 68080, for testing); the
same prediction from 16-bit multiplies.
Checked on a 68080 only: it has not run
on a real 68060 yet
Libs/flacdec.library.080 Apollo 68080 (Vampire) only; refuses to
open on another CPU. With the FPU on, the
prediction of 24-bit files runs on it,
bit for bit the same
Copy one of them to LIBS:flacdec.library.
Speed on a Vampire V4 (68080, 99 MHz), CPU time in % of real time,
decoding only:
68080 build 68020 build
44.1 kHz / 16-bit stereo 4.9 % 4.9 %
96 kHz / 24-bit stereo 12.6 % 13.9 %
88.2 kHz / 24-bit, verbatim 2.3 % 2.4 %
Formats: 4 to 32 bits per sample (16-bit output), 1 to 8 channels,
any sample rate, native FLAC (not Ogg FLAC). CRCs are not checked.
Not decoded: 32-bit stereo frames with a side channel, which has 33
bits. Decoding stops at the first such frame.
Seeking is supported. Input comes from a file or from your own I/O
hook (for example a file that is still being downloaded). Several
programs and tasks can decode at the same time. The 68020 build does
not use the FPU; the 68080 build uses it when it is on (checked for
every subframe: the V4 can switch it off). The 68060 build does not
use the FPU either.
For programmers
---------------
Developer/doc/flacdec.doc the autodoc
Developer/include/libraries/flacdec.h structures and constants
Developer/include/clib, proto, inline prototypes, GCC inlines
Developer/fd/flacdec_lib.fd
struct FLACDecInfo info;
APTR dec = FLACDecOpenFile("song.flac", &info);
LONG n;
while ((n = FLACDecRead(dec, buffer, 4096)) > 0)
... n frames of info.fdi_Channels interleaved WORDs ...
FLACDecClose(dec);
The functions use up to about 4.6 KB of the caller's stack: call them
with at least 8 KB free.
Tested
------
Against ffmpeg's decoder: 23 files (CD and 96 kHz/24-bit music,
ffmpeg compression levels 0 to 12, LPC orders up to 32, mono, 48 kHz,
every stereo mode, wasted bits), whole decodes and seeks at 7
positions each, both builds; the read hook; the stack use. The FPU
prediction against the integer one on 1152 cases and under constant
interrupts. Since 1.1 also synthetic files against their known samples:
verbatim subframes from 4 to 32 bits, residuals mixing Rice and unencoded
partitions. All three builds gave the same results on a 68080, the
68060 prediction also against a model on 13772 cases.
License
-------
flacdec.library is free to use and to redistribute in this unchanged
archive. (C) 2026 Renaud Schweingruber. dr_flac by David Reid is
public domain (or MIT-0), https://github.com/mackron/dr_libs.
History
-------
1.1 Verbatim subframes in assembler, 7 times faster. The prediction
runs once per subframe instead of once per partition, the library
is 5 KB smaller. 16-bit files that do not need the 64-bit
prediction no longer use it, and its loops are 2 to 3 cycles per
sample shorter (68020 build: up to 11 % faster on 16-bit files, 5 %
on 96 kHz/24-bit; 68080 build: up to 5 %). New 68060 build. 32-bit files from libFLAC 1.4 now decode (they gave no
samples). The output is unchanged for everything that decoded before.
1.0 First release.
|