HydrogenAudio

Lossless Audio Compression => FLAC => Topic started by: hanrelan on 2010-09-22 18:48:43

Title: Real-time streaming FLAC using Netcat?
Post by: hanrelan on 2010-09-22 18:48:43
Hi,
I'm trying to use FLAC to stream audio to a client with low-latency using netcat. On the server I'm using:
Code: [Select]
 parec --device=sink.monitor --rate=16000 --format=s16le --channels=1 -r |   flac --fast --endian=little --channels=1 --bps=16 --sample-rate=16000 --sign=signed --force-raw-format --stdout -  | nc -l $port


Most of the time, it's low latency. However, if there's silence, then the flac encoder buffers until the silence ends and doesn't send any data (I believe this is due to flac's run length encoding).

Is there a way to turn off this behavior in the flac encoder, perhaps by telling it to never buffer more than 100ms (our max allowable latency) worth of data before encoding?

If there is another codec that might be a better fit for this task, please let me know! I've already tried MP2 (using twolame) and MP3 (using lame), but no luck with those.

Thanks!
Rohan
Title: Real-time streaming FLAC using Netcat?
Post by: tuffy on 2010-09-22 19:58:01
Perhaps adding "--disable-constant-subframes" to your FLAC encoder options will help.
Title: Real-time streaming FLAC using Netcat?
Post by: hanrelan on 2010-09-23 00:01:18
Perhaps adding "--disable-constant-subframes" to your FLAC encoder options will help.


Thanks! This seems to have worked, though it still buffers for about 1.5 seconds before sending the data. Can you explain a little bit what this option does (it doesn't seem to be documented and I'm not sure what subframes are) and if there are additional parameters that I could possibly tweak?

Thanks,
Rohan
Title: Real-time streaming FLAC using Netcat?
Post by: tuffy on 2010-09-23 13:59:32
FLAC takes its input stream of audio and chops it into frames, each a fraction of a second long in most cases.  Those frames are then separated by channels into different subframes and compressed.  Constant subframes are FLAC's way of telling the decoder that all the audio samples in that subframe will be the same (typically silence).  But naturally it has to walk all the way to the end of the silence before it can know all the samples are the same, which sounded like the problem you were having.

FLAC always needs a little buffering time in order to do compression on its subframes, but it's hard to get it to spend less time than --fast.  Beyond tweaking the block size (the amount of samples in each subframe), I'm not sure what else to try.
Title: Real-time streaming FLAC using Netcat?
Post by: hanrelan on 2010-09-23 19:50:53
FLAC takes its input stream of audio and chops it into frames, each a fraction of a second long in most cases.  Those frames are then separated by channels into different subframes and compressed.  Constant subframes are FLAC's way of telling the decoder that all the audio samples in that subframe will be the same (typically silence).  But naturally it has to walk all the way to the end of the silence before it can know all the samples are the same, which sounded like the problem you were having.

FLAC always needs a little buffering time in order to do compression on its subframes, but it's hard to get it to spend less time than --fast.  Beyond tweaking the block size (the amount of samples in each subframe), I'm not sure what else to try.


Thanks for the explanation
SimplePortal 1.0.0 RC1 © 2008-2021