Closed madskjeldgaard closed 3 months ago
And from the serial monitor, this is the last thing posted before the crash:
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 1024 -> 1024 -> 1024 bytes - in 1 hops
[I] StreamCopy.h : 158 - StreamCopy::copy 766 -> 766 -> 766 bytes - in 1 hops
[I] main.cpp : 48 - The audio rate from the wav file is 44100
[I] main.cpp : 49 - The channels from the wav file is 2
Restarting...
[I] PWMAudioBase.h : 124 - decimation: 1
[I] PWMAudioBase.h : 153 - ->Buffer available: 4004
[I] PWMAudioBase.h : 154 - ->Buffer available for write: 96
[I] PWMAudioBase.h : 155 - ->is_timer_started: true
[I] AudioEncoded.h : 75 - virtual void audio_tools::EncodedAudioOutput::addNotifyAudioChange(audio_tools::AudioInfoSupport&)
Another point of debugging: If I set looping to active on the MemoryStream, it doesn't seem to crash.
My gut feeling is that calling pwmOutput.begin(); again might be the source of your problem. You can set the log level to debug to get more details....
Removing that from the loop doesn't help unfortunately. I set logging to Debug and got this before crashing:
. Connected!
[D] StreamCopy.h : 98 - copy 1024 bytes
[D] StreamCopy.h : 192 - available: 36606
[D] StreamCopy.h : 384 - write: 1024
[I] AudioEncoded.h : 75 - virtual void audio_tools::EncodedAudioOutput::addNotifyAudioChange(audio_tools::AudioInfoSupport&)
[D] AudioEncoded.h : 190 - EncodedAudioOutput::write: 1024
[D] CodecWAV.h : 323 - virtual size_t audio_tools::WAVDecoder::write(const uint8_t*, size_t)
[I] CodecWAV.h : 56 - WAVHeader::write: 1024 -> 44 -> 44
[I] CodecWAV.h : 63 - WAVHeader::begin: 44
[I] CodecWAV.h : 220 - WAVHeader sound_pos: 44
[I] CodecWAV.h : 221 - WAVHeader channels: 1
[I] CodecWAV.h : 222 - WAVHeader bits_per_sample: 16
[I] CodecWAV.h : 223 - WAVHeader sample_rate: 8000
[I] CodecWAV.h : 224 - WAVHeader format: 1
[I] CodecWAV.h : 420 - WAV sample_rate: 8000
[I] CodecWAV.h : 421 - WAV data_length: 2147418104
[I] CodecWAV.h : 422 - WAV is_streamed: 1
[I] CodecWAV.h : 423 - WAV is_valid: true
[I] AudioPWM.h : 35 - virtual void audio_tools::PWMAudioOutput::setAudioInfo(audio_tools::AudioInfo)
[I] AudioTypes.h : 128 - sample_rate: 8000 / channels: 1 / bits_per_sample: 16
[D] PWMAudioRP2040.h : 52 - virtual void audio_tools::PWMDriverRP2040::end()
[D] AudioPWM.h : 50 - bool audio_tools::PWMAudioOutput::begin(audio_tools::PWMConfig)
[D] AudioOutput.h : 47 - virtual void audio_tools::AudioOutput::setAudioInfo(audio_tools::AudioInfo)
[I] AudioTypes.h : 128 - sample_rate: 8000 / channels: 1 / bits_per_sample: 16
[D] PWMAudioBase.h : 119 - bool audio_tools::DriverPWMBase::begin(audio_tools::PWMConfig)
[I] PWMAudioBase.h : 124 - decimation: 1
[I] PWMAudioBase.h : 132 - ->Allocating new buffer 4 * 1024 bytes
[I] Buffers.h : 372 - resize: 4096
[I] PWMAudioBase.h : 87 - sample_rate: 8000
[I] PWMAudioBase.h : 88 - channels: 1
[I] PWMAudioBase.h : 89 - bits_per_sample: 16
[I] PWMAudioBase.h : 90 - buffer_size: 1024
[I] PWMAudioBase.h : 91 - buffer_count: 4
[I] PWMAudioBase.h : 92 - pwm_frequency: 30000
[I] PWMAudioBase.h : 93 - resolution: 8
[D] PWMAudioRP2040.h : 81 - virtual void audio_tools::PWMDriverRP2040::setupPWM()
[D] PWMAudioRP2040.h : 104 - pwm_config audio_tools::PWMDriverRP2040::setupPWMConfig()
[I] PWMAudioRP2040.h : 112 - ->wrap_value = 63
[I] PWMAudioRP2040.h : 113 - ->max clock speed = 133000000.000000
[I] PWMAudioRP2040.h : 114 - ->divider = 70.370369
[I] PWMAudioRP2040.h : 115 - ->clock speed = 1890000.000000
[I] PWMAudioRP2040.h : 92 - PWM pin 2
[D] PWMAudioRP2040.h : 125 - void audio_tools::PWMDriverRP2040::setupPWMPin(pwm_config&, audio_tools::PicoChannelOut&) for gpio 2
[I] PWMAudioBase.h : 153 - ->Buffer available: 0
[I] PWMAudioBase.h : 154 - ->Buffer available for write: 4096
[I] PWMAudioBase.h : 155 - ->is_timer_started: false
[I] CodecWAV.h : 443 - WAVDecoder writing first sound data
[D] PWMAudioBase.h : 172 - adjusted size: 980
[D] Buffers.h : 77 - writeArray 980 -> 980
[D] PWMAudioRP2040.h : 70 - virtual void audio_tools::PWMDriverRP2040::startTimer()
[I] AudioTimerRP2040.h : 37 - timer time: 125 us
[D] PWMAudioBase.h : 172 - [D] Buffers.h : 50 - readArray 2 -> 2
adjusted size: 44
[D] Buffers.h : 50 - readArray 2 -> 2
[D] Buffers.h : 50 - readArray 2 -> 2
[D] Buffers.h : 77 - [D] Buffers.h : 50 - readArray 2 -> 2
[[D] Buffers.h : 50 - readArray 2 -> 2
D] AudioEncoded.h : 202 - EncodedAudioOutput::write: 1024 -> 1024
With logging set to Debug it also crashes as soon as I connect the serial monitor now.
Ah, I think I found the issue.
In the else part of the loop, the wavefile should have .end() called on it before calling .begin() again.
void loop() {
if (wavfileMemory) {
copier.copy();
} else {
// after we are done we just print some info form the wav file
auto info = out.audioInfo();
LOGI("The audio rate from the wav file is %d", info.sample_rate);
LOGI("The channels from the wav file is %d", info.channels);
// restart from the beginning
Serial.println("Restarting...");
// out.begin(); // indicate that we process the WAV header
wavfileMemory.end(); // reset actual position to 0
wavfileMemory.begin(); // reset actual position to 0
// pwmOutput.begin(); // reset counters
}
}
It still crashes the Pico when I connect the Serial monitor while Logging is set to Debug, but with Info and Warning it works fine it seems (maybe that's a seperate issue).
My gut feeling is that this might be related to the PWMStream.
Did you try to replace it with an I2SStream ?
In order to avoid some unnecessary changes, set the sample rate to 8000!
I committed a correction that stops an active timer before it is restarted again....
I did not check if I can reproduce your issue, but I was double checking after the correction and it did not crash....
Thanks @pschatzmann , I just tested the changes here and so far it seems to work! Thanks so much :)
Problem Description
Running a modified version of an example of streaming wav file audio from memory causes the Raspberry Pi Pico board to crash after playing the audio file 5-10 times approximately. The Pico becomes completely unresponsive after that, does not play audio and does not respond to software resets.
Here is the code that makes it crash. For comparison, using something like a SineWave generator instead of the MemoryStream does not crash. Also I tried sample rates of 8000 as well as resolutions of 8-11 for the PWM output.
Device Description
Raspberry Pi Pico.
Sketch
Other Steps to Reproduce
No response
What is your development environment
PlatformIO on a MacOS.
platformio.ini looks like this:
I have checked existing issues, discussions and online documentation