Some help in correctly using the audio player needed (troubleshooting crashes, skeleton code?) #305
-
Hi, I understand that this may be too much to ask, but I have been trying in the past months to achieve the following I am experimenting with a large sized esp32-based physical panel to control many things in the house. Ideally, the small audio samples (mp3 encoded) were to be saved in SPIFFS, and I had found some contributions showing how to use SPIFFS, and merged it with some other examples from your repos on how to connect to the BT speaker and play them. I think I did not do a great job of it (one was using streams, the other the "old" method of managing the files), but it mostly worked. That was a few months ago, now I am giving it a try again and am trying to piece it all together I understand that the problem is fully in my code. but I would really appreciate it if you could help me with a skeleton code I was able to play the test sine wave via AD2P so the whole hardware setup seems to work. Again, apologies if this is a lot to ask. I am just getting a bit lost with all the moving parts and the slowness of my debug loop. Maybe I should avoid the audioplayer and just figure out how to play a specific sample based on needs? yet, how to properly detect if some other sample is currently playing? I'm kind of getting a little lost in the treasure trove of all the many ways of achieving this. Thanks for any direction |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments 3 replies
-
The fact that you want to use A2DP should drive the architecture: If you look at this example you can see that A2DP is constantly pulling data, so for your project you would return the content of your file piece by piece until it has finished. If there is no file to play you would just return an empty array, to keep A2DP open. This way your buttons would just open and set the actual file to be played. I think this is the most efficient way to deal with this, but so far, you will need to forget about mp3 since you need to provide the data in the format that a2dp needs. I would need to extend my api to support directly reading from an encoded file... by the way: files are also streams so you can also read them with readBytes(uint_t*data, size_t len) like in the example. |
Beta Was this translation helpful? Give feedback.
-
@pschatzmann thanks for the clarifications. I guess I was overcomplicating it.
Did I get that right? |
Beta Was this translation helpful? Give feedback.
-
I suggest that you try
And dont't forget: if you open a wav file first read 44 bytes which are the header which must be ignored. |
Beta Was this translation helpful? Give feedback.
-
My gut feeling is that your problems come from print statements in get_sound_data: This just uses too much time. |
Beta Was this translation helpful? Give feedback.
-
Just tried that, error is the same as above. New sketch -
|
Beta Was this translation helpful? Give feedback.
-
not sure if this will help, but try
And dont forget to remove the Serial.println in get_sound_data |
Beta Was this translation helpful? Give feedback.
-
Hi @pschatzmann , I tried your suggestion but still no luck. I have been ill in the past days, as soon as I feel better, I'll try to work from the sine generator example and will probably just generate different notes depending on the type of touch, then try to grow from there and see if I can make it play proper sounds. thanks for your help thus far! |
Beta Was this translation helpful? Give feedback.
I suggest that you try
And dont't forget: if you open a wav file first read 44 bytes which are the header which must be ignored.