Lag problems with DatagramSocket and OSC receiving


#1

Hi,

I'm new to Juce and currently programming a plugin (AU/VST on Mac OS) that listens for OSC messages from an external application and uses the values to set the plugin's sliders. I've got it to work except that if the sender application sends a high rate of data (e.g. sending from Max/MSP at 1 message every 10ms) the received messages accumulate in the socket's queue and the slider changes start to lag. I tried placing the message checking calls in the PluginEditor (using a Timer at 1ms) and in the processBlock, but both showed lagging.

I couldn't find any methods in the DatagramSocket class that would allow me to drop messages (I guess clearing the socket's queue?) if they exceed the processing capacity of the receiver. I was wondering if someone could help me poniting out in what direction should I go to solve this problem. This is my read() method for checking messages:

char * oscListener::read() {

    int sizeRead = 0;
    int result = dataSocket.waitUntilReady(true, 0);

    if (result) {
        sizeRead = dataSocket.read(buffer, 512, false);
    }

    if (sizeRead > 0) {
        return buffer;
    } else {
        return emptyBuffer;
    }
}

Thanks in advance,

 

Hector


#2

OK, it seems that placing the listener in its own running Thread and directly updating the processor's variables from there solved the problem. In the processBlock I just check for changes in those variables and if changed call setParameterNotifyingHost. The Timer in the PluginEditor checks for discrepancies between the slider values and the variables and updates the sliders without notifying. 

I hope I'm doing things the right way.

Hector