[PD-dev] Fwd: Synchronizing OpenGL with libpd (with RtAudio or Port Audio)

0222445 Luis.Valdivia at stud.sbg.ac.at
Thu Feb 18 03:12:56 CET 2016


Yes, i'm using the C++ wrapper. I compiled the wrapper with thread support.
I was not using the queued layer.  Should I use both (mutex and queued
layer)? I made some test now (with mutex, without mutex, with mutex and
queued, with mutex and without queued, etc), and there is no difference,
the opengl draw is being blocked during the execution of the metronome. I
tested the function with a std::thread:

void BasicGLPane::rightClick(wxMouseEvent& event) {
    manager->init();
    SLEEP(2000);
    std::thread t(&BasicGLPane::start_thread,this);
    t.join();
}

and made some changes in the thread function:

void BasicGLPane::start_thread() {
    wxGLCanvas::SetCurrent(*m_context);
    ctx = CGLGetCurrentContext();
    err =  CGLEnable( ctx, kCGLCEMPEngine);
    int timer = 0;
    manager->play();
    while (_object->getCounter()<10) {
       if (err==0 && timer<_object->getCounter()) {
            std::cout<<"if CGLError: "<<err<<" timer: "<<timer<<std::endl;
            glTranslatef(p3->x, p3->y, 0);
            timer = _object->getCounter();
            Refresh();
        }
    }
    manager->stop();
    Refresh();
}

There is no context error in the OpenGL draw now (solved with the call
wxGLCanvas::SetCurrent(*m_context) but the draw still doesn't works (the
object is moved after the manager->stop() and not during the execution) . I
still think RtAudio is owning the CPU and blocking the execution of other
threads or process. It will be better to do it with PortAudio?
Regards.
Luis

2016-02-17 19:25 GMT+01:00 Dan Wilcox <danomatika at gmail.com>:

> It looks like you’re using the C++ wrapper for libpd. Did you build it
> with thread support and/or are you using the queued layer?
>
> There are actually 3 threads here:
>
> * main application thread
> * audio thread
> * Open GL thread
>
> libpd will obviously be utilized by the audio thread where you run the
> libpd process function. If you are *not* using a mutex or the queued layer,
> you may have resource issues between the audio thread and the other threads.
>
> --------
> Dan Wilcox
> @danomatika <https://twitter.com/danomatika>
> danomatika.com
> robotcowboy.com
>
> On Feb 17, 2016, at 4:00 AM, pd-dev-request at lists.iem.at wrote:
>
> *From: *0222445 <Luis.Valdivia at stud.sbg.ac.at>
> *Subject: **[PD-dev] Fwd: Synchronizing OpenGL with libpd (with RtAudio
> or Port Audio)*
> *Date: *February 16, 2016 at 9:00:30 PM MST
> *To: *pd-dev at lists.iem.at
>
>
> I have to synchonize a Metronome (wrote with libpd) and OpenGL graphics.
> I'd like to move some objects parallel with the metronome clicks.
> The language is C++, the Gui is made with WxWidgets, Threads with Poco,
> audio with RtAudio.
> The metronome works, OpenGL graphics too, I have only a problem with the
> synchronisation. I'm running both things with a Thread, but it actually
> doesn't works, the metronome run and the graphic is done after the
> metronome stops (and not parallel). i become  the CGLError 10004 from
> OpenGL during the execution of the thread (if CLGError is = 0 the draw is
> going to be done). The object is moved when the thread is completed.
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puredata.info/pipermail/pd-dev/attachments/20160218/dfcabc9c/attachment.html>


More information about the Pd-dev mailing list