Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: FLAC Prediction stage (Read 8346 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

FLAC Prediction stage

I have my final work for my university, and it's about FLAC and losseless audio compression. 
I also build my own flac encoder, and a graphical interface to convert files from wav to flac.
I can't understand the prediction stage of the flac encoding. Can anyone explain me, so i can understand it better to continue building my encoder?
THANKS!!! 

FLAC Prediction stage: Click here!

FLAC Prediction stage

Reply #1
I've actually written a small doc with some details on FLAC encoding (scroll to page 22) during my attempt to build a FLAC encoder in Scheme based on looking at the reference encoder's source.  Although my encoder was far too slow to be practical, it generated valid FLAC files and I learned a lot in the process.  Hopefully you'll get some use out of my notes.

I'm no audio codec expert, though; I'm just a coder with curiosity and lots of free time.  So make sure to cross-check your results against the reference encoder to ensure accuracy in case I've made any mistakes.

FLAC Prediction stage

Reply #2
I've actually written a small doc with some details on FLAC encoding (scroll to page 22) during my attempt to build a FLAC encoder in Scheme based on looking at the reference encoder's source.  Although my encoder was far too slow to be practical, it generated valid FLAC files and I learned a lot in the process.  Hopefully you'll get some use out of my notes.

I'm no audio codec expert, though; I'm just a coder with curiosity and lots of free time.  So make sure to cross-check your results against the reference encoder to ensure accuracy in case I've made any mistakes.


Thanks a lot!!!        It's very helpfull for me. Me neighter i'm not audio codec expert. It's my first try.
Thanks again a lot!
And sorry for my bad english.

FLAC Prediction stage

Reply #3
Unfortunately the FLAC format page doesn't contain all the necessary infos you need to develop a decoder or an encoder. You need to check out the source code of other implementations (libFlac, libFlake, ffmpeg) as well. I'm sure Josh will appreciate patches regarding this format documentation. As far as I can tell it lacks
  • details on M/S mapping in terms of polarity of the S channel, scaling and quantization.
  • details on fixed prediction (well it references "shorten" but the document could easily mention how the order is linked to prediction coefficients. If I had to guess "order" is the number or zeros at -1.0)
  • details on FIR prediction ("shift" is a signed number. What does a positive shift correspond to? shifting in which direction? How's the prediction quantized? The latter one I can answer: There's no compensation for the bias towards negative infinity when shifting to the right)
  • details on residual coding (IIRC there's some interleaving involved that maps signed residual samples to positive numbers that are then RICE-coded. There's no word on the size of partitions in case the blocksize is not divisible by the number of partitions. Is this illegal or are there special rounding rules?)
  • examples for all the things above

Apart from that I suggest you do some research on what LPC is about.

Cheers,
SG

FLAC Prediction stage

Reply #4
I've actually written a small doc with some details on FLAC encoding (scroll to page 22)


Unfortunately the FLAC format page doesn't contain all the necessary infos you need to develop a decoder or an encoder.

But tuffy's document seems to cover all the points I addressed. Nice!

details on M/S mapping in terms of polarity of the S channel, scaling and quantization.

Simplification of what tiffy wrote:
LR->MS:  S = L - R,  M = R + floor(S * 0.5)
MS->LR:  R = M - floor(S * 0.5),  L = R + S

where floor(S*0.5) can be written as (S >> 1) in C or Java.

details on FIR prediction ("shift" is a signed number. What does a positive shift correspond to? shifting in which direction? How's the prediction quantized?

right shift

details on residual coding (IIRC there's some interleaving involved that maps signed residual samples to positive numbers that are then RICE-coded.

Unwrapping of positive numbers to signed residual samples:
inline signed u2s(unsigned x)
{ return (x >> 1) ^ (-(x & 1)); }

Cheers,
SG

FLAC Prediction stage

Reply #5
I've actually written a small doc with some details on FLAC encoding (scroll to page 22) during my attempt to build a FLAC encoder in Scheme based on looking at the reference encoder's source.  Although my encoder was far too slow to be practical, it generated valid FLAC files and I learned a lot in the process.  Hopefully you'll get some use out of my notes.

nice doc.  one correction, the 'f' in flac is for 'free' not 'fully'

FLAC Prediction stage

Reply #6
Whoops!  *fixed*

I've also added a few notes about the CRC-8 and CRC-16, which someone will hopefully find useful.

FLAC Prediction stage

Reply #7
Thanks all of you for the help, and specially tuffy for his amazing doc!   
I have some questions, i'll try to found the answer and if i can't i'll post aqain.
THANKS A LOT!!!!