Teensy Crashes on AudioControlSGTL5000 sgtl5000_2.enable(); call

Hello everybody,
Please forgive my bad english...

I am quite stuck here. I tried to work on a project of synth after a while and after having upgraded teensyduino. My project used to work before but now, after some time searching, I found out that when I call the enable() function of AudioControlSGTL5000 object during class initialization, the Teensy reboots.

However Teensy's samples sketches such as MidiSynthKeyboard.ino works fine.

In my project I have a lot of classes because I wanted to do a kind of an unified platform for the great synths developped for Teensy, giving generic tools for hardware, midi, controlers, EEPROM patch saving and audio software, but it is quite empty.

Does anyone got an idea ? You may download the src folder.
The call which make the crash is in src/TeensyInstruments/SympleSynth/SimpleSynthInstrument.h on line 104

Thanks a lot, I don't know how to move forward, except starting form scratch.

And here is the building configuration :
Code:
CONFIGURATION: https://docs.platformio.org/page/boards/teensy/teensy41.html
PLATFORM: Teensy (4.18.0) > Teensy 4.1
HARDWARE: IMXRT1062 600MHz, 512KB RAM, 7.75MB Flash
DEBUG: Current (jlink) External (jlink)
PACKAGES:
 - framework-arduinoteensy @ 1.158.0 (1.58)
 - tool-teensy @ 1.158.0 (1.58)
 - toolchain-gccarmnoneeabi-teensy @ 1.110301.0 (11.3.1)
Converting SillonsSynthMedium.ino
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Found 92 compatible libraries
Scanning dependencies...
Dependency Graph
|-- USBHost_t36 @ 0.2
|-- Bounce
|-- Wire @ 1.0
|-- Audio @ 1.3
|-- EEPROM @ 2.0
Building in release mode
 

Attachments

  • Sillons TeensyMusicHost src.zip
    46.2 KB · Views: 510
In my project I have a lot of classes because I wanted to do a kind of an unified platform for the great synths developped for Teensy, giving generic tools for hardware, midi, controlers, EEPROM patch saving and audio software, but it is quite empty.

Does anyone got an idea ? You may download the src folder.
The call which make the crash is in src/TeensyInstruments/SympleSynth/SimpleSynthInstrument.h on line 104

Thanks a lot, I don't know how to move forward, except starting form scratch.

Regis:

I did not load up your entire project, but in looking at the SimpleSynthInstrument.h file that you pointed out, there are multiple definitions for two of the audio patch connections, specifically patchCord7 & patchCord8.

Code:
    AudioConnection          patchCord7[1] = {{waveformSimple1, 0, i2s_8, 0}};
    AudioConnection          patchCord8[1] = {{waveformSimple1, 0, i2s_8, 1}};
    AudioConnection          patchCord7[1] = {{mixerSimple2, 0, i2s, 0}};
    AudioConnection          patchCord8[1] = {{mixerSimple2, 0, i2s, 1}};

Very likely if you correct those duplicates (every "AudioConnection" should have a unique number as part of the patchCord definition), you'll be able to make forward progress.

Mark J Culross
KD5RXT
 
Thanks a lot for the reply, I was reducing elements step by step to find the bug which explain the duplicates.

However, the part you mention is commented (is it correct in english, I mean shall not be compiled).
 
the part you mention is commented (is it correct in english, I mean shall not be compiled).
@Regis:

My apologies !! I completely missed the surrounding c-style comment marks.

I'll load up your entire project & try to give it a closer look to see if I can find anything.

Mark J Culross
KD5RXT
 
OK, I loaded up your entire project, built it for the T4.0 (that's where I currently have my Audio Adapter connected to, but I'd expect that a T4.1 would work the same with this setup).

I started with your sources extracted directly from your ZIP file. There are a few warnings during the build, but your project does successfully load & run on my hardware.

Here's what I get in the Serial Monitor:

Code:
INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Warning : Control Descriptor not initialized

INSTRUMENT Control received : cc=7 value=64
INSTRUMENT Control received : cc=73 value=60
INSTRUMENT Control received : cc=75 value=40
INSTRUMENT Control received : cc=79 value=64
INSTRUMENT Control received : cc=72 value=0
INSTRUMENT Control received : cc=74 value=65
INSTRUMENT Control received : cc=71 value=0
INSTRUMENT Control received : cc=47 value=90
INSTRUMENT Control received : cc=48 value=30
USB HOST MIDI Class Compliant Listening
--------------------------------
---RRC Simple Synth
---   This basic synth if proudly brought to you by the RRC company
---   Instrument id : 255
--------------------------------------

Available controls : 9
    Volume :     midiCC=7     default value=64
    Delay Feedback :     midiCC=47     default value=90
    Delay Time :     midiCC=48     default value=30
    Filter Resonance :     midiCC=71     default value=0
    Release :     midiCC=72     default value=0
    Attack :     midiCC=73     default value=60
    Filter Frequency :     midiCC=74     default value=65
    Decay :     midiCC=75     default value=40
    Sustain :     midiCC=79     default value=64
3 factory patches found
--------------------------------

Started ok
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0
Efficiency Stats :     proc=0 max=0        mem=0 max=0

A new Efficiency Stats : proc=0 max=0 mem=0 max=0 line is printed approximately every 15 seconds, so I do not seem to be seeing a crash.

You might try adding the following to your setup() function, right after the call to Serial.begin(115200); & open the Serial Monitor in the Arduino IDE to see any report that may be generated:

Code:
while(!Serial) ;
if (CrashReport)
   Serial.print(CrashReport);

See if that report provides any clues . . .

Note that with the Crash Report monitor written this way (specifically, the while(!Serial) ;), it will wait forever if the Serial Monitor is not connected, so this added code should be commented out and/or removed after you've identified & resolved the cause of your crash.

Mark J Culross
KD5RXT
 
Hello Mark,

Thanks for taking time helping me.



The fact that it works on your side made me try to compile on Arduino instead of PlatformIO and it worked also !
I guess this is because my old Arduino (still on Windows 7) uses Teensyduino 1.56 instead of PlatformIO which updated to Teensyduino 1.8 (I've installed it recently, was using Sloeber before). Could you tell me which teensyduino you use to confirm this clue ?

The code you gave didn't give any result. I am not sure on how to use it. The code don't even reaches the Serial.begin() function (I tried to light up inside led before without succes). So maybe I shall put it somewhere else.
I kept on searching and moved back SGTLAudioControl initializing inside class in order to call it after Serial.begin() and called the constructor in setup() function and... it worked !
C++:
void setup() {

    pinMode(13, OUTPUT);
    digitalWrite(13, HIGH); // Test if it comes here

    Serial.begin(115200);

    while(!Serial) ;
    Serial.println("Serial started");
    if (CrashReport)
           Serial.print(CrashReport);

    Serial.println("Try to load instrument");
    instrument = new SimpleSynthInstrument();
    Serial.println("Instrument loaded");
    if (CrashReport)
           Serial.print(CrashReport);
    Serial.println("After crash report");
which gives :
Code:
Serial started
Try to load instrument
Instrument loaded
After crash report

We could infer that initialization of SGTL before Serial could crasch, however the MidiSynthKeyboard.ino do it this way and it works.
So I tried added SGTLAudio as global variable on top class but it didn't work.
Then I've put instrument initialization on top of setup() funtion and it worked also. So maybe it is just that we should not call sgtl.enable() before setup()...

Don't kown what to do next, so I'll create classes inside setup but it is still weird, as it used to work before...

Thanks a lot for helping me !
 
I am running Arduino 1.8.19, with TD 1.59beta3 installed. I would definitely recommend that you update to the latest Arduino, & that you install at least TD 1.58.

The Crash Report (if any) will show up in the Serial Monitor that you have to open from the Arduino IDE. If there is in fact a crash, the Teensy will reboot every 8 seconds, and with each reboot, the crash report will show up in the Serial Monitor.

As I attempted to advise/warn in my previous post, if you don't open the Serial Monitor, your Teensy will be stuck waiting forever at the while(!Serial) ; line.

Hope that helps . . .

Mark J Culross
KD5RXT
 
We could infer that initialization of SGTL before Serial could crasch, however the MidiSynthKeyboard.ino do it this way and it works.
So I tried added SGTLAudio as global variable on top class but it didn't work.
Then I've put instrument initialization on top of setup() funtion and it worked also. So maybe it is just that we should not call sgtl.enable() before setup()...

Don't kown what to do next, so I'll create classes inside setup but it is still weird, as it used to work before...

Thanks a lot for helping me !
As noted in this thread, Teensyduino 1.58 broke a number of things that depended on SPI and Wire being constructed before dependent objects are used. AudioControlSGTL5000 depends on Wire, as the SGTL5000 is controlled via I²C. This is fixed in 1.59 beta 3. If you make your classes with a begin() method that's called in setup(), you'd be safer.

Note also that the stock Audio library does not in general support creation and destruction of objects at run time - the only exception is AudioConnection objects. You may find that new works for most objects, but even then a few bugs have been uncovered recently (e.g. in AudioEffectWaveshaper) where runtime creation causes a crash.
 
Back
Top