[flac-dev] Newbie question about those callbacks

Johnny Rosenberg gurus.knugum at gmail.com
Sun Feb 10 01:42:48 PST 2013

2013/2/10 Erik de Castro Lopo <mle+la at mega-nerd.com>:
> Johnny Rosenberg wrote:
>> For instance the write_callback thing:
>> client_data – can it be a pointer to just about anything?
> I assume you mean:
>     https://www.xiph.org/flac/api/group__flac__stream__decoder.html#ga13
> which defines the type:
>     typedef FLAC__StreamDecoderWriteStatus
>              (* FLAC__StreamDecoderWriteCallback)
>                  (const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame
>                  , const FLAC__int32 *const buffer[], void *client_data)
> Yes, client_data can point at anything. You the callee are responsible
> to cast your pointer_to_anything to and from 'void*'

Thanks. That explains the following line in the write_callback
function one of the the two examples I found:
FILE *f=(FILE*)client_data;

>> For instance a pointer to a two-dimensional array?
> Yes. They can even be NULL.

Yes, I saw that in the other example… :)

> Whatever pointer you pass as the client_data parameter in the finction
> FLAC__stream_decoder_init_stream () will be passed back to you in the
> callbacks client_data.
>> Are those FLAC-WAV and WAV-FLAC examples the only examples available?
> There are examples in the examples/ directory of the FLAC source code
> tarball. They are in Git here:
>     https://git.xiph.org/?p=flac.git;a=tree;f=examples/c;h=dbcb345dcd699ca3f1a1b1d334f5a48d45385558;hb=HEAD

Ok, that's the two examples that I already know about. I will not
waste more time looking for more examples then. Thanks.

>> What would be the best approach to read a FLAC file to an array of
>> some kind? Passing a pointer to the array as ”client_data”? I'd like
>> to use a two-dimensional array, but it's a little tricky (for a
>> newbie) to pass to functions as a pointer.
> I agree, coding to the FLAC API is not something that is easy or obvious
> for a newbie C programmer.

No, I realised that at an early stage. The future will show if I will
give up or not… I am sure I will finish my code, but I'm not sure
whether I will use libflac or something else.

Thanks for helping.

Kind regards

Johnny Rosenberg

> Erik
> --
> ----------------------------------------------------------------------
> Erik de Castro Lopo
> http://www.mega-nerd.com/
> _______________________________________________
> flac-dev mailing list
> flac-dev at xiph.org
> http://lists.xiph.org/mailman/listinfo/flac-dev

More information about the flac-dev mailing list