Play Audio to a BT Device on a button press #770
-
|
my current setup looks like: init everything play the sound on a button press. basically i got everything up and running. But: the usage of the callback does not really work the way i expect it to. in the setup i use: and in the isr i just set a variable (pressed) to true. the loop looks like: my callback looks like: i guess there is more going on. since i dont see a reason in the documentation how the callback should be used. i will change the loading of the file to a buffer... but first i would like to understand the callback. do you have a hint for that? |
Beta Was this translation helpful? Give feedback.
Replies: 16 comments 14 replies
-
|
Your code is impossible to read: please use the proper code formatting provided by Markdown! In any case, you need to feed the requested number of bytes as described in the Readme Chapter Sending Data from a A2DS Data Source with a Callback: if you have nothing just initialize the array with zeros. Here is an example that processes an mp3 file! |
Beta Was this translation helpful? Give feedback.
-
|
thank you for your answer! I gave it a short shot. and even turned off wifi after getting the file. i will have to look into that later... i am headed out for vacation. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, sorry for not beeing able to respond for a while. the debouncing and handling works a little better, but still not quite as i expect it to be. the first trigger works fine, but afterwards it is more or less sporadic. |
Beta Was this translation helpful? Give feedback.
-
|
i stripped down my code a little. i removed the ISR for the button. The output looks like but i hear the sound super random and not in the 5 second manor that i expected. sometimes twice without delay, sometimes it takes more than a minute. The "file loaded" appears every 5 seconds. so the timing for that is fine. i guess i did not really understand the get_sound_data() method and how it works. My wifi should be turned off. At least it was the only way to turn it off. |
Beta Was this translation helpful? Give feedback.
-
|
hi, thank you for your answer. i was trying to get closer. your thought seems reasonable. i moved the opening to the setup() and the behavior stayed the same. afterwards i was experimenting with some output to see if sth happens. but no luck yet. since i was not able to get vscode up and running i am still stuck with arduino ide. i will keep on working on it. and keep you posted. |
Beta Was this translation helpful? Give feedback.
-
|
Hi, i looked into the timing here. as soon as i am able to compile and test one of your examples, i might be able to look into the multithread issues. |
Beta Was this translation helpful? Give feedback.
-
|
i tried to move the relevant stuff to a separate task. but i guess i dont get the concept of the multithreading/multicore here. my serial output looks like: the LED lights up everytime the word FIRE is outputed, but the sound is still just random. |
Beta Was this translation helpful? Give feedback.
-
|
The Arduino loop is already in a task whch is separate from the Bluetooth data provider! All you need to do is to write and read from/to the same (thread save) queue:
This way the sketch should get pretty small! Do not use any Serial print: this will mess up the audio output because it is much too slow! |
Beta Was this translation helpful? Give feedback.
-
|
hm. i wonder: i will try a bigger file... maybe the buffer is just too empty!? |
Beta Was this translation helpful? Give feedback.
-
|
the serial prints are only in there for debugging purpose. another aproach could be: just set the pointer in that buffer to beginning everytime the sound needs to play (it is basically always the same) but my sketch would not work as soon as i do that. the bluetooth never connects if i have the buffer declard. i guess your suggestions dont fit in pattern i have in mind. so i dont really know what to do with them. i will keep playing around with what i think you mean. |
Beta Was this translation helpful? Give feedback.
-
|
If you want to store the whole "file", put your audio data in PROGMEM or PSRAM since the RAM is limited. I guess the simplest would be to use the A2DPStream from the AudioTools: in the loop just write the file data to it... Finally note that A2DP has quite some lag. So there is quite some delay between an action on the ESP and the time you hear it on the speaker. |
Beta Was this translation helpful? Give feedback.
-
|
i guess then i dont understand what i am doing at that point. i thought the A2DPStream was kind of what i am trying to do. how big can the lag be? are we talking milliseconds? seconds? |
Beta Was this translation helpful? Give feedback.
-
|
so you are talking about set_data_source vs set_data_callback? |
Beta Was this translation helpful? Give feedback.
-
|
i will go to bed now... maybe i get further tomorrow. thank you so much for your tips! |
Beta Was this translation helpful? Give feedback.
-
|
sorry, this is driving me nuts... i guess bed has to wait. i dont even know anymore how i got that older library. i am not intentionally using the older one. i am working as a software engineer/developer for 20 years now... and i cannot get that to work... thats so frustrating... not your fault... i just feel so stupid... EDIT: this is what i get. at least it compiles and does something. now i need to read further how i can get the data in there. thank you! so i call it a day. |
Beta Was this translation helpful? Give feedback.
-
|
i got a little further. i chose to go with the example. that basically works pretty good for my idea. even timing and so on. i only need to swap out the sinus with a "real" sound. i will keep you posted! |
Beta Was this translation helpful? Give feedback.
i dont think it is an issue with the example.
i am sure it is a problem with my setup. i just dont know where to look to debug what i am missing.
the one ino compiles (thats why i tried to go small steps) with all the others i was not able to compile. and if it does not compile, i am way to far off to ask any questions.
i guess i need to step a way out and try to get my envirionment under control.
sorry to bother you with my lack of experience! i should be better at that point.
just for completeness...