MorphOS Developer
Posts: 1107 from 2003/6/11
From: Białystok...
Time for some update. As I've reported before, demuxer has been already finished. Now all activity concentrates on decoder. Decoding FLAC frame header is now complete. Then there are 4 types of subframes. Subframe header decoder is done as well. Then what is left to do is decoding subframes contents:
1. Constant subframe is the easiest. It is usually used to encode silence at the start or end of music (or inside). Decoding it is a piece of cake, and I've already done it.
2. LPC subframe. It is the most compilicated one, but as it is the most common one, I'm currently working on it. Decoding of LPC subframes may be accelerated with AltiVec.
3. Fixed predictor subframe. It may be easily reduced to a special case of LPC. AltiVec accelerations apply as well.
4. Verbatim frame. In rare cases there is no point to compress a signal, as no compression can be achieved using FLAC algorithms. Then samples are just stored as is. While relatively easy to decode it is rarely found in real streams, so I've left it for the end. AV accelerations are possible here as well, but since verbatim frames are rather rare, overall gain would be not big.
There is also another optimization, which may be significant. I will go technical jargon here, so beware

. The residual signal of predictor in FLAC is encoded with so called Rice encoding. In Rice encoding every audio sample consists of two parts. The first one uses unary encoding. Unary encoding is just some "0" bits followed by "1" bit. Count of these "0" bits is the encoded number. Usually these "0" bits are counted by shifting and masking, but PowerPC has a special instruction named
cntlzw, which counts those "0" bits in hardware. This can mean serious speedup of decoding if bitstream reader is specifically designed to use the instruction. Note that it is a PowerPC core instruction, not AltiVec one, so even Efika (as well as G3 and Sam460) processor has it. As far as I was able to check, it is not used by libflac. I will keep you informed about results.
[ Edited by Krashan 20.12.2012 - 17:08 ]