Matrix Voice and Raspberry Pi Zero Audio output


#21

Hi Yoel,

I have worked my way through the code and I am stuck comprehending this:

void bt_app_a2d_data_cb(const uint8_t *data, uint32_t len)
{
static uint16_t buffer[2048];
int16_t p = (int16_t)data;

uint16_t diff;
uint16_t buffers_fifo[2];

for (int i = 0; i < len/4; i++)
{
    buffer[i] = p[i*2]/2+16768;
    /* code */
}

wb->SpiRead(hal::kDACBaseAddress+0x802,(uint8_t*)&buffers_fifo[0],sizeof(uint16_t)*2);

if(buffers_fifo[1] > buffers_fifo[0])
    diff = buffers_fifo[1] - buffers_fifo[0];
else
    diff = 4096 - buffers_fifo[0] + buffers_fifo[1];

if(diff > 2048){
    vTaskDelay(30 / portTICK_PERIOD_MS);
//    ESP_LOGI(BT_AV_TAG, "--- Diff %d Len:%d", diff,len/2);
}
wb->SpiWrite(hal::kDACBaseAddress, (uint8_t*)buffer, len/2);

}

I understand what it does, but I do not understand the SpiRead into buffers_fifo do?
I have chosen internal DAC in the config, assuming that the sound would come from the audio-jack.
Is that correct or should I choose external I2S?

This is because I get the buffer callback and all, but no sound is produced in the jack.
Should I upgrade firmware first?


#22

Hi @Romkabouter,

Sorry about the code, it was meant to be a test and still requires some cleanup. A full example will be released in the coming weeks.

The audio data is sent from the ESP32 using SPI to the DAC implemented in the FPGA present in the board. So, that’s what SpiWrite does, is sending the audio.

Yes, you should use the latest version of matrix-creator-init package.

-Yoel


#23

Yeah, I understand and that is no problem at all :slight_smile:
I was using that code as an example to output data but when I did not hear a sound I thought I’d made some mistake.

Code is fine to tinker with, no problems. I do not think I have the latest init code in place, so that will be my first action

update: yeuh, I could play my spotify playlist!
Although the buffers and such are not good (it’s a demo anyway), I could hear the music :slight_smile:
Lots of packets drops, but that is just a buffer problem.


#24

For audio output I run into the same problem as bluetooth.
That is that the ESP framework only support 44100 16 bit for now, but I think I will just make this a requirement for incoming audio buffers instead of trying to resample on the fly.

Thanks for all the effort on the audio output :slight_smile: