[LAD] jack and c++

cal cal at graggrag.com
Mon Nov 10 09:10:00 UTC 2008


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



More information about the Linux-audio-dev mailing list