[LAD] jack and c++

Maarten de Boer mdeboer at iua.upf.edu
Mon Nov 10 09:37:25 UTC 2008


Why don't you take it one step further, and call a method of audJ
right away, so you don't have use audJ-> all the time?

class AudioOutputJACK
{
    [...]
    static int sProcessJackCallback(jack_nframes_t nframes, void* arg)
    {
       AudioOutputJACK* audJ = static_cast<AudioOutputJACK*>(arg);
       return audJ->ProcessJackCallback(nframes)
    }
    int ProcessJackCallback(jack_nframes_t nframes)
    {
       [...]
    }
};



On Nov 10, 2008, at 10:10 AM, cal wrote:

> Malte Steiner wrote:
>> For a new audio application I need to code a JACK client with C++. So
>> far I did it only with C and have a problem with giving the pointer  
>> to
>> the callback process function, which is a method now. So what is the
>> best performing solution? Is a delegate function a good idea, being
>> static and triggering the method in the objectinstance?
>
> No idea what the best solution might be, but here's an approach I've  
> used...
>
> class AudioOutputJACK
> {
>   public:
>       [ ... ]
>   private:
>       static int ProcessJackCallback(jack_nframes_t nframes, void*  
> arg);
> }
>
> And in the class initialisation,
>
>   if ((chk = jack_set_process_callback(jack_client,  
> ProcessJackCallback,
>                                        this)))
>   { ... }
>
> And the callback function ...
>
> int AudioOutputJACK::ProcessJackCallback(jack_nframes_t nframes,  
> void* arg)
> {
>   AudioOutputJACK* audJ = static_cast<AudioOutputJACK*>(arg);
>   // then stuff like ...
>   size_t bytes_requested = nframes * audJ->jack_frame_bytes;
>   size_t bytes_read = jack_ringbuffer_read(audJ->ringbuffJ,
>                                            (char*)audJ->jack_tfer_buf,
>                                            bytes_requested);
>   etc ...
> }
>
> cheers, Cal
> _______________________________________________
> Linux-audio-dev mailing list
> Linux-audio-dev at lists.linuxaudio.org
> http://lists.linuxaudio.org/mailman/listinfo/linux-audio-dev




More information about the Linux-audio-dev mailing list