Thanks to Rob and Tony for the answers to the channel question.
I'm trying to implement a class within my C++ app that presents a stream
interface to the MAD decoder, i.e. it does buffering and provides a Tick()
method that returns the next decoded sample in the stream as a floating point
number. My first attempt uses the high-level API but I've stumbled on a problem
I can't seem to get around.
The logic I'm using in Tick is something like the following:
1. Check PCM buffer.
2. If data present, just return next sample.
3. If buffer empty, go away and decode some more to fill buffer.
4. When buffer is full, stop decoding and return first sample in buffer.
I need to stop and start decoding the same stream at regular intervals depending
on the PCM buffer size. So at stage 3 above, I call mad_decoder_run on the
properly initialised decoder, and in the output callback, I return MAD_FLOW_STOP
when I've been given enough frames to fill the buffer.
Up until now everything's fine. But, it seems that the next time the buffer gets
empty and I restart by calling mad_decoder_run again on the same decoder, the
decoder doesn't remember the input last given to it by the input callback. So
the first thing it does is call the input callback for more input. The
mad_stream->next_frame passed into the input callback is always 0 after a
restart.
This causes problems because the input callback has no way of knowing how far
into the previous chunk MAD has decoded. Is there any way to find this out from
the decoder itself?
I haven't looked at the low-level API yet, will I maybe need to use that to
achieve what I want?
Hope the above makes sense, I've only just started using MAD so might have
overlooked something blindingly obvious.
Many thanks,
Erik