Hi all, I've found some behaviour which is either a bug, something stupid I've done with pointers, or just me pushing the audio library past its limits!
I've been designing a modular synth where you can change the signal path between various Teensy audio modules during runtime. Rather than statically declaring AudioConnections at the start of the code (the way the online GUI handles AudioConnections), I have been creating new AudioConnections during runtime, then using the disconnect() function when they are no longer required. This has been working brilliantly on the Teensy 3.6, but I'm currently working on a stripped-down design for the Teensy 3.2 and I've realised that adding and removing several AudioConnection objects causes the audio to either go very weird or stop working completely.
Here is a test sketch to demonstrate the problem:
The audio output works as expected for a little while, then becomes glitchy/silent. My best guess is a memory problem, since increasing AudioMemory allows the sketch to work for longer (this is also why I didn't notice a problem on the Teensy 3.6, where I could allocate more memory). I've tried deleting/nullifying my connection pointer, but this didn't seem to do anything. I've also tried fiddling with the core Teensy libraries, but I'm out of my depth there - the connect() and disconnect() functions are on line 202 and 236 here https://github.com/PaulStoffregen/cores/blob/master/teensy3/AudioStream.cpp in case that helps speed up any detective work.
If anyone could possibly confirm this behaviour or suggest a possible solution, I would be extremely grateful - my synth project depends on it!
I've been designing a modular synth where you can change the signal path between various Teensy audio modules during runtime. Rather than statically declaring AudioConnections at the start of the code (the way the online GUI handles AudioConnections), I have been creating new AudioConnections during runtime, then using the disconnect() function when they are no longer required. This has been working brilliantly on the Teensy 3.6, but I'm currently working on a stripped-down design for the Teensy 3.2 and I've realised that adding and removing several AudioConnection objects causes the audio to either go very weird or stop working completely.
Here is a test sketch to demonstrate the problem:
Code:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
AudioControlSGTL5000 sgtl;
AudioOutputI2S mainOutput;
AudioSynthWaveform sineWave;
AudioConnection* connection;
void setup() {
AudioMemory(25);
sgtl.enable();
sgtl.volume(0.2);
sineWave.begin(0.5,440,WAVEFORM_SINE);
}
// ideally this loop should generate a sine wave which is switched rapidly on and off forever
// instead, it drops out after a few seconds
void loop() {
// create connection between sine wave and main output
connection = new AudioConnection(sineWave,0,mainOutput,0);
delay(100);
// break the connection
connection->disconnect();
delay(100);
}
The audio output works as expected for a little while, then becomes glitchy/silent. My best guess is a memory problem, since increasing AudioMemory allows the sketch to work for longer (this is also why I didn't notice a problem on the Teensy 3.6, where I could allocate more memory). I've tried deleting/nullifying my connection pointer, but this didn't seem to do anything. I've also tried fiddling with the core Teensy libraries, but I'm out of my depth there - the connect() and disconnect() functions are on line 202 and 236 here https://github.com/PaulStoffregen/cores/blob/master/teensy3/AudioStream.cpp in case that helps speed up any detective work.
If anyone could possibly confirm this behaviour or suggest a possible solution, I would be extremely grateful - my synth project depends on it!