Mirror of XTronical's excellent XT_DAC_Audio library for ease of integration into platformio projects
GNU General Public License v3.0
10
stars
18
forks
source link
Error loading wav file dinamically (audioSample defined by a static array or malloc) #4
Open
brunocantisano opened 2 years ago
I wrote an audio.wav file in my data folder. Every time I try to load this file dinamically, my ESP restarts:
My array is static:
include "XT_DAC_Audio.h"
define RelayAudio 25
XT_DAC_Audio_Class DacAudio(RelayAudio,0);
void play() {
File root = SPIFFS.open("/audio.wav"); if (root) { size_t sz = root.size(); unsigned char audioSample[sz]; if (root.available()) { root.read(audioSample, sz); } root.close(); XT_Wav_Class Sound(audioSample); DacAudio.FillBuffer(); if(Sound.Playing==false){ // volume vai até 100 //DacAudio.DacVolume=100;
DacAudio.Play(&Sound); }
} else { Serial.printf("Error to open audio.wav!"); } }
OR (with malloc)
include "XT_DAC_Audio.h"
define RelayAudio 25
unsigned char * audioSample; XT_DAC_Audio_Class DacAudio(RelayAudio,0);
void play() {
File root = SPIFFS.open("/audio.wav"); if (root) { size_t sz = root.size(); audioSample = (unsigned char *)malloc(sz); if (root.available()) { root.read(audioSample, sz); } root.close(); XT_Wav_Class Sound(audioSample);
DacAudio.FillBuffer(); if(Sound.Playing==false){ // volume vai até 100 //DacAudio.DacVolume=100;
DacAudio.Play(&Sound); }
} else { Serial.printf("Error to open audio.wav!"); } }