YasarYY
Active member
Hi.
I use Snooze v6.3.9 library to snooze Teensy 4.1 with deepSleep() method. Snoozing and waking work as expected, but audio library doesn't function after waking up, i.e. doesn't play wav files via AudioPlayMemory. (I have a speaker connected to MQS output.)
I know Snooze library is old and not maintained anymore, but I cannot find an alternative either. I tried reallocating memory by AudioMemory() after wake, disabling/enabling audio interrupts before/after snooze by AudioNoInterrupts()/AudioInterrupts(), but the issue persisted. Many other chip-level suggestions are for the chip of Teensy 3.
Can anyone recommend a method on how the audio library can be revived, through reinitializing it or by any other means?
If this issue turns out not solvable, then I'll switch to hibernate() method that restarts on wake, which is not my first choice but is a solution.
Here is a minimum code with comments describing the issue, if anyone wants to have a look:
I use Snooze v6.3.9 library to snooze Teensy 4.1 with deepSleep() method. Snoozing and waking work as expected, but audio library doesn't function after waking up, i.e. doesn't play wav files via AudioPlayMemory. (I have a speaker connected to MQS output.)
I know Snooze library is old and not maintained anymore, but I cannot find an alternative either. I tried reallocating memory by AudioMemory() after wake, disabling/enabling audio interrupts before/after snooze by AudioNoInterrupts()/AudioInterrupts(), but the issue persisted. Many other chip-level suggestions are for the chip of Teensy 3.
Can anyone recommend a method on how the audio library can be revived, through reinitializing it or by any other means?
If this issue turns out not solvable, then I'll switch to hibernate() method that restarts on wake, which is not my first choice but is a solution.
Here is a minimum code with comments describing the issue, if anyone wants to have a look:
C++:
#include <Snooze.h>
#include <SnoozeBlock.h>
#include <Bounce.h>
#include "AudioSampleBird.h" // sound sample created by wav2sketch
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
// GUItool: begin automatically generated code
AudioPlayMemory playMem1; //xy=588,313
AudioAmplifier amp1; //xy=744,313
AudioOutputMQS mqs1; //xy=895,313
AudioConnection patchCord1(playMem1, amp1);
AudioConnection patchCord2(amp1, 0, mqs1, 0);
// GUItool: end automatically generated code
SnoozeTimer snoozeTimer;
SnoozeUSBSerial snoozeUsb;
SnoozeSPI snoozeSpi;
SnoozeBlock sbTimer(snoozeTimer, snoozeUsb, snoozeSpi);
bool slept = false;
const uint8_t pinButton = 28;
Bounce button = Bounce(pinButton, 50);
void setup() {
Serial.begin(9600);
pinMode(pinButton, INPUT_PULLUP);
// init audio library
AudioMemory(20);
amp1.gain(2.0f);
// start playing sample sound
playMem1.play(AudioSampleBird); // PLAYS
Serial.println("*** setup is completed ***");
// set snooze timer
snoozeTimer.setTimer(5);
}
void loop() {
// play sound if the button is pressed
button.update();
if (button.fallingEdge()) {
Serial.println("starting play");
playMem1.play(AudioSampleBird); // DOESN'T play after snooze but hangs for several seconds and restarts
}
// print current millis
Serial.printf("millis = %u", millis());
Serial.println(playMem1.isPlaying() ? " playing" : "");
// sleep when some seconds passed after startup
if (!slept && millis() > 10000) {
slept = true;
Serial.println("going to snooze...");
// request and wait for sending buffered serial data
Serial.send_now();
delay(10);
Snooze.deepSleep(sbTimer);
// wait for serial to reinitialize
delay(250);
Serial.println("awakened!");
}
delay(100);
}