sensorium / Mozzi

sound synthesis library for Arduino
https://sensorium.github.io/Mozzi/
GNU Lesser General Public License v2.1
1.09k stars 187 forks source link

Hardware support for the PicoADK RP2040 DSP Board #168

Open DatanoiseTV opened 1 year ago

DatanoiseTV commented 1 year ago

The PicoADK is a board which is focused on building standalone synthesizers, oscillators etc. By default, it uses the PicoADK-Firmware-Template, which is based on the Pico SDK.

It has a 32-bit Audio DAC and a 8 channel ADC128S102 12-bit 3.3V/5V ADC with up to 1 Megasample/s. The audio output is very low noise, due to a dedicated LDO for the Audio Codec Analog Supply.

Would be cool to see Mozzi support for it to make it also useful for Arduino IDE users. https://github.com/DatanoiseTV/PicoADK-Hardware https://github.com/DatanoiseTV/PicoADK-Firmware-Template

Discord: https://discord.gg/BsHUEdStMt

tomcombriat commented 1 year ago

Hi,

I actually wonder if this should not be working already, probably with minor configuration:

Have you tried :) ?

DatanoiseTV commented 1 year ago

I didn't figure out yet where to start. Is Mozzi able to handle 16-bit/32-bit I2S output?

tomcombriat commented 1 year ago

Yup. First step I think would be to adapt "AudioConfigRP2040.h" to the hardware:

Then I would just try to run one of the examples

DatanoiseTV commented 1 year ago

@tomcombriat https://github.com/sensorium/Mozzi/pull/169 I've also added random seed support using the ROSC of the RP2040. This is the way recommended by Raspberry. Now I need some help on implementing the ADC handling.

The code for reading the ADC (example):


spi_init(spi1, 16000000);
spi_set_format(spi1, 8, SPI_CPOL_0, SPI_CPHA_0, SPI_MSB_FIRST);
spi_set_slave(spi1, false);

....
uint16_t adc128_read(uint8_t chan)
{
        if (chan > 7)
                return 0;
        gpio_put(13, 0);
        uint8_t data[2] = {(chan << 3), 0};
        uint8_t rxData[2];
        spi_write_read_blocking(spi1, data, rxData, 2);
        gpio_put(13, 1);
        uint16_t result = (rxData[0] << 8) | rxData[1];

        return result;
}
tomcombriat commented 1 year ago

I made a few review on your PR. For the DAC I do not have one to test this but is this code working? As I said in the review I do not think this level of details should go in Mozzi but probably more in your sketches (or any higher level api that goes with the board). Let's see what the others say.

DatanoiseTV commented 1 year ago

I will review it. Yes, I've tested using all the examples and it works. The reason for adding the PicoADK specific mute pin control is that the user won't need to modify sketches in order to use them with an PicoADK board.

pschatzmann commented 1 year ago

In the config we can define an EXTERNAL_AUDIO_OUTPUT. I think it would be cool to have the same on the input side as well, so that we could add any custom audio input in the sketch itself.

This would also help e.g. for the ESP32 where the getADCReading() is not implemented. This way we could even support the audio input from an ESP32 AudioKit.