Hi everyone
So, I'm building an OSC controller with a teensy 3.6. I'm reading 16 fader (slide potentiometer) values and sending them to a computer if a fader is moved. The code works as expected on Windows machines, but Macs seem to not be able to handle the amount of data I'm sending. If I make big jumps with a fader there is a very noticeable lag and if I do that with more than one fader it sometimes takes the mac seconds to process all the sent values. Then sometimes it recovers and i can receive a single fader signal normally, but sometimes the lag persists or gets continually worse, even if don't make any crazy movements.
I see that behavior in the software for which the control messages are meant (Max), as wells as the Arduino serial monitor. I have tried it on two different Macbooks.
Reducing the resolution of the ADC (hence reducing the amount of data sent) helps, but I have to reduce it by about 2/3 (!!) for it to work as smoothly as on Windows (and I have yet to see as much as a stutter on a windows machine).
I'm assuming Apples USB implementation doesn't just generally suck, so what am I missing? What am I doing wrong?
So, I'm building an OSC controller with a teensy 3.6. I'm reading 16 fader (slide potentiometer) values and sending them to a computer if a fader is moved. The code works as expected on Windows machines, but Macs seem to not be able to handle the amount of data I'm sending. If I make big jumps with a fader there is a very noticeable lag and if I do that with more than one fader it sometimes takes the mac seconds to process all the sent values. Then sometimes it recovers and i can receive a single fader signal normally, but sometimes the lag persists or gets continually worse, even if don't make any crazy movements.
I see that behavior in the software for which the control messages are meant (Max), as wells as the Arduino serial monitor. I have tried it on two different Macbooks.
Reducing the resolution of the ADC (hence reducing the amount of data sent) helps, but I have to reduce it by about 2/3 (!!) for it to work as smoothly as on Windows (and I have yet to see as much as a stutter on a windows machine).
I'm assuming Apples USB implementation doesn't just generally suck, so what am I missing? What am I doing wrong?
Code:
#include <OSCMessage.h>
#include <SLIPEncodedUSBSerial.h>
#include <ResponsiveAnalogRead.h>
const int faderAmount = 16;
const int analogInputPins[16] = {A14, A13, A16, A17, A18, A19, A20, A1, A2, A3, A4, A5, A6, A7, A8, A9};
char* oscAdresses[16] = {"/fader1", "/fader2", "/fader3", "/fader4", "/fader5", "/fader6", "/fader7",
"/fader8", "/fader9", "/fader10", "/fader11", "/fader12", "/fader13", "/fader14",
"/fader15", "/fader16"};
class Fader {
public:
Fader(int _inputPin, char* _oscAdress);
void handleInput(SLIPEncodedUSBSerial& SLIPSerial);
private:
int inputPin;
char* oscAdress;
ResponsiveAnalogRead analog;
};
Fader::Fader(int _inputPin, char* _oscAdress)
: inputPin(_inputPin), oscAdress(_oscAdress), analog(_inputPin, true)
{
pinMode(inputPin, INPUT);
analog.enableEdgeSnap();
}
void Fader::handleInput(SLIPEncodedUSBSerial& SLIPSerial) {
analog.update();
/* sending the OSC message */
if(analog.hasChanged()) {
OSCMessage msg(oscAdress);
msg.add(analog.getValue());
SLIPSerial.beginPacket();
msg.send(SLIPSerial);
SLIPSerial.endPacket();
}
}
const int ledPin = 13;
Fader** fader = new Fader*[faderAmount];
SLIPEncodedUSBSerial SLIPSerial(Serial);
void setup() {
pinMode(ledPin, OUTPUT);
SLIPSerial.begin(9600);
/* initializing the fader objects */
for(int i = 0; i < faderAmount; i++) {
fader[i] = new Fader(analogInputPins[i], oscAdresses[i]);
}
digitalWrite(ledPin, HIGH); // turn on LED, so we know the Controller is powered.
}
void loop() {
for(int i = 0; i < faderAmount; i++) {
fader[i]->handleInput(SLIPSerial);
}
}
Last edited: