-
Notifications
You must be signed in to change notification settings - Fork 669
Description
Describe the bug
In the a2dp_sink_demo example built for the pico2W there is no more audio, after reconnecting.
Expected behavior
Audio working after reconnecting to the pico.
HCI Packet Logs
Packets arrives but are not saved in the SBC ring buffer. In fact I logged them and they arrive but I don't have a dump now.
Environment: (please complete the following information):
- btstack version 1.6.2 for the latest pico-sdk 2.1.1
- Pico 2 W with onboard controller
- Pixel 8A
Additional context
From the concise description when I follow these steps:
1)I connect to the pico with my phone
2)I listen to some music, it works really good!
3)I disconnect and then reconnect
4)and finally I restart the music,
The first thing happened was that the pico panicked because it cannot claim again the same pio SM, so i modified the code of the audio_i2s.c to have a deinit function that is something like this:
void audio_i2s_deinit() {
audio_i2s_set_enabled(false);
pio_remove_program_and_unclaim_sm(&audio_i2s_program,audio_pio,shared_state.pio_sm,shared_state.offset);
dma_irqn_set_channel_enabled(PICO_AUDIO_I2S_DMA_IRQ, shared_state.dma_channel, 0);
irq_set_enabled(DMA_IRQ_0 + PICO_AUDIO_I2S_DMA_IRQ, 0);
user_irq_unclaim(DMA_IRQ_0 + PICO_AUDIO_I2S_DMA_IRQ);
added_irq = true;
dma_channel_unclaim(shared_state.dma_channel);
} and i added that code to
https://github.com/raspberrypi/pico-examples/blob/84e8d489ca321a4be90ee49e36dc29e5c645da08/pico_w/bt/btstack_audio_pico.c#L192
static void btstack_audio_pico_sink_close(void){
// stop stream if needed
if (btstack_audio_pico_sink_active){
btstack_audio_pico_sink_stop_stream();
}
audio_i2s_deinit();
}so now it works, i can disconnect and reconnect and it doesn't panic anymore but I can't hear any audio and on the console I receive the "Error storing samples in SBC ring buffer!!!" over and over. It seems to have something to do with buffers, in fact using the debugger i found out that the code listed below (in the same file btstack_audio_pico.c) always breaks the loop and doesn't fill the audio_buffer.
static void btstack_audio_pico_sink_fill_buffers(void){
while (true){
audio_buffer_t * audio_buffer = take_audio_buffer(btstack_audio_pico_audio_buffer_pool, false);
if (audio_buffer == NULL){
break; // BREAKS HERE
}
int16_t * buffer16 = (int16_t *) audio_buffer->buffer->bytes;
(*playback_callback)(buffer16, audio_buffer->max_sample_count);
// duplicate samples for mono
if (btstack_audio_pico_channel_count == 1){
int16_t i;
for (i = SAMPLES_PER_BUFFER - 1 ; i >= 0; i--){
buffer16[2*i ] = buffer16[i];
buffer16[2*i+1] = buffer16[i];
}
}
audio_buffer->sample_count = audio_buffer->max_sample_count;
give_audio_buffer(btstack_audio_pico_audio_buffer_pool, audio_buffer);
}
}Any help would be greatly appreciated.
Thanks.
Mattia.