need help! a2dp receiver + wav or mp3 sound at the same time. #1809
Replies: 2 comments 1 reply
-
You are quite unclear what you want to achieve, so I try double check your problem statement:
The A2DPSink provides data with 16 bits on 2 channels with a sample rate of 44100. If you want to mix this with some other source you need to make sure that this format is matching. You can do this by double checking your files or by running them thru a format conversion. Please note that the data is provided faster then the data format might imply and it is usually throttled by the i2s output. If I understand your code above right, you are thinking of doing the mixing in the a2dp callback. I have never done something like this, but in my gut feelig you might get away with this when you use some wav files but I am not sure if this will also work with mp3 since the output of an mp3 decoder can be quite bursty. You were writing that you don't know how to replace the generated sine with a file: I suggest that you go back to the Decoding Wiki and re-read the chapter about Decoding on the Input Side which is exactly that: in the example mp3 is the copy source which means that the exactly same readBytes() (that you use above) gets called on it. A2DP uses up quite some PROGMEM and RAM, the same is true for MP3 decoders, so check first if both fit into PROGMEM. If you are running out of RAM, using PSRAM might help. A more reliable architechture would be to have separate tasks:
One of the advantages here is, that you can test each queue separately and by having the queue always filled, your mixer does not risk to run out of data. As a final comment: please follow the advice given here and build the solution in steps: if something is not working you can identify exactly where you screwed up! I also recommend to check the result of each method call: I left this out in my examles to be more readable, but you should not make assumptions! |
Beta Was this translation helpful? Give feedback.
-
I am sincerely grateful for your prompt response. I must explain: The code I relied on in the post was one of the options I was considering to work. I understand the logic of the necessary actions, the problem is that I am unable to do this. !!Especially how to transfer a2dp somewhere!! :( It is clear that from the logic: or no less logical, although not scalable I am very ashamed and embarrassed to ask, or rather waste your time. Please give a working example SD + wav or mp3 + a2dp Next I will suffer over the rest, but having a base will be useful to many! |
Beta Was this translation helpful? Give feedback.
-
Hello! I'm already desperate. I am not a normal programmer and I have a huge difficulty with this task.
I reviewed all the discussions over two years, revised the examples, but did not find the solution I needed.
The best I've found is calling a2dp and running wav or mp3 from SD. When I try to activate the sound, I get distortion.
It seemed logical to me to make an example of such a task, because this is one of the most logical implementations for a BT speaker system.
I found the a2dp callback + generated sine wave, but I absolutely don’t understand how to put a file stream in its place. I'm talking about this post:
`void read_data_stream(const uint8_t *data, uint32_t length) {
// To keep the mixing buffer small we split up the output into small chunks
int count = length / buffer_size + 1;
for (int j = 0; j < count; j++) {
const uint8_t *start = data + (j * buffer_size);
const uint8_t *end = min(data + length, start + buffer_size);
int len = end - start;
if (len > 0) {
// write a2dp
mixer.write(start, len);
}
}`
Please don't send me to VIKI, I've been living there for almost a month without any results - it's very difficult. And sorry for the emotional outburst.
I saw several similar questions, but there was nothing in terms of a solution there either and people left empty-handed. Because do not understand are very far from your level of understanding.
Beta Was this translation helpful? Give feedback.
All reactions