For instance the write_callback thing: client_data ? can it be a pointer to just about anything? For instance a pointer to a two-dimensional array? Are those FLAC-WAV and WAV-FLAC examples the only examples available? 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. It seems like the audio data is passed to the write_callback in a small buffer. A very small buffer, in fact, only a little more than 4000 frames in my case. Is that to keep the memory usage low? I can't work directly with the buffer anyway, since I need to manipulate things ?between the buffers?. That is, if I find something in the beginning or end of the buffer, I need to manipulate data that is no longer available in the buffer. That's why I need to read the whole file into an array. Maybe I should just do something else, I'm probably too stupid for these things anyway. Or too old. Or both. Thanks for listening, you don't need to reply to this crap, sorry. Kind regards Johnny Rosenberg ????????????
Erik de Castro Lopo
2013-Feb-10 01:37 UTC
[flac-dev] Newbie question about those callbacks
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*'> For instance a pointer to a two-dimensional array?Yes. They can even be NULL. 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> 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. Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/
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=HEADOk, 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