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: Block size and Input buffer required for FLAC Decoding (Read 5479 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Block size and Input buffer required for FLAC Decoding

Hi all,
  I recently started with FLAC implementation....I read that FLAC can have a worst case block size as 65536 samples.....Do we really get that huge block sizes??
If that is the case then my I/O buffers have to be declared for almost 2MB...Did anyone face with similar kind of issue...if so please reply me...i am in urgent need of this information...

Block size max = 65536 samples
Num channel max = 8

so my I/O buffer size = Block size * Num channels * sizeof(int)
                              = 65536 * 8 * 4
                              = 2MB

Do we really require these huge buffers or is there any alternate way to avoid it??

Regards,
Gopi

Block size and Input buffer required for FLAC Decoding

Reply #1
practically all flac encoded audio conforms to the subset which has a lower maximum blocksize (4608 samples up to 48kHz).

Block size and Input buffer required for FLAC Decoding

Reply #2
practically all flac encoded audio conforms to the subset which has a lower maximum blocksize (4608 samples up to 48kHz).


Thanks for the reply.....so you mean that block size is not required to be declared that large.....Even if I have to decode the files with large block sizes, Is there any way to do it by just allocating less size(a chunk of 8KB or 16KB) to the input buffer....

Block size and Input buffer required for FLAC Decoding

Reply #3
The "subset" that Josh speaks of is a limited form of the specification that probably 99.999% of FLAC files conform to.  If you write a decoder that only conforms to the subset, you won't be able to play files that don't conform to the subset.  However, these files are exceedingly rare.

In this particulra example, files with larger block size would not be playable if you allocate a smaller block size.  But it's extremely unlikely you'll ever have to play back such a file, and perfectly acceptable to file on files outside of the subset.

Block size and Input buffer required for FLAC Decoding

Reply #4
Is there any way to do it by just allocating less size(a chunk of 8KB or 16KB) to the input buffer....

not with libFLAC currently, the residual buffer and decoded pcm buffers (where the majority of mem is used) are allocated internally.

if memory is that tight you can check for the max block size of a stream in the STREAMINFO metadata block and fail if it's too big.  as long as you handle the subset you can say "flac compliant".  it is unlikely you will ever see a non-subset file.

p.s. the maximum framesize in STREAMINFO will give you an upper bound on the size that the residual buffer will grow to.  a rough estimate of mem usage for a stream is max_framesize+4*channels*max_blocksize bytes.  for cd audio this is almost always <54k.

Block size and Input buffer required for FLAC Decoding

Reply #5
Is there any way to do it by just allocating less size(a chunk of 8KB or 16KB) to the input buffer....

not with libFLAC currently, the residual buffer and decoded pcm buffers (where the majority of mem is used) are allocated internally.


Yes I too observed the same with the present library it is taking more buffer sizes for residual buffer and output PCM buffer....but we moved the allocation of output PCM to Wrapper API... and using the same output PCM for residual even.....but presently we allocated maximum sizes for that....

But memories are constraint here as we are planning it on a DSP....So at the main can we send only few samples information of of every subframe and start decoding those samples...??Can I ge the length of the subframe and can i track the information of subframe start psoition??

 

Block size and Input buffer required for FLAC Decoding

Reply #6
you would have to modify libFLAC more to do that, but once you buffer the frame, yes you can eliminate the block-long pcm buffers altogether if you first search for the beginning of each subframe in the frame.  then you can decode one or more samples at a time into a smaller buffer.  then you need just 18k max (12k typical) for the frame buffer.

edit: clarification