Audio Crackling For Flash Memory Playback #542
-
I've been trying to integrate sound into certain projects without additional hardware which is why I've been looking into putting small sounds (for sound effect feedback on button press) entirely into memory. For reference, when I used the "Star Wars" example with my setup (MAX98357 amp with an 8ohm speaker) the audio has no crackling. However, when I try to play short sound effects that I cut and load into an array of memory streams as a sort of audio reference table, I get crackling towards the end of the sound effect. In audacity, when cut out the relevant sound effects I ensure that the file is mono and not stereo and of the sample rate 44100Khz, and in playback on my laptop, I don't hear any crackling. I then encode it into a C style array using a hex editor like the example. However on playback with the test sketch enclosed, the audio starts to crackle/have a fuzz near the end of playback. I'm not sure if its the fact that I'm cutting the audio and there's some sort of artifacting effect happening or something to do with code handling the end of the byte array. ` uint8_t channels = 1; I2SStream i2s; // Output to I2S StreamCopyT<int16_t> copier(i2s, soundEffects[0]); // copies sound into i2s void setup(){ //blocking playback audio function long beginning = millis(); //reset memory stream object to play from beginning } void loop(){ for (int i = 0; i < 4; i++){ }` |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
My guess is that I2S does not like it if you abruptly stop to provide any data. I suggest that you check what happens if you add plenty of silence at the end before you stop. |
Beta Was this translation helpful? Give feedback.
-
ESPs do some stuff in the background and need some spare CPU cycles for this. |
Beta Was this translation helpful? Give feedback.
-
I don't understand your comment regarding files: Just open the file and copy the content to the output stream. |
Beta Was this translation helpful? Give feedback.
My guess is that I2S does not like it if you abruptly stop to provide any data. I suggest that you check what happens if you add plenty of silence at the end before you stop.
ps. instead of your while(copier.copy()) loop you can just use a copier.copyAll().