diff --git a/AudioConfigRP2040.h b/AudioConfigRP2040.h index eed5201b4..1edb8a6c2 100644 --- a/AudioConfigRP2040.h +++ b/AudioConfigRP2040.h @@ -44,6 +44,28 @@ #define BUFFER_SIZE 256 // total size of the buffer, in samples #endif +#if defined(ARDUINO_DATANOISETV_PICOADK) +// undefined the defindes to disable compiler warnings +// about redefinition. +#undef BCLK_PIN +#undef WS_PIN +#undef LSBJ_FORMAT +#undef AUDIO_BITS +#undef BYPASS_MOZZI_OUTPUT_BUFFER +#undef BUFFERS +#undef BUFFER_SIZE +#undef RP2040_AUDIO_OUT_MODE + +#define BCLK_PIN PIN_I2S_BCLK +#define WS_PIN (PIN_I2S_BCLK+1) +#define DOUT_PIN PIN_I2S_DOUT +#define LSBJ_FORMAT false +#define AUDIO_BITS 16 +#define BYPASS_MOZZI_OUTPUT_BUFFER true +#define BUFFERS 8 +#define BUFFER_SIZE 256 +#define RP2040_AUDIO_OUT_MODE EXTERNAL_DAC_VIA_I2S +#endif #define AUDIO_BITS_PER_CHANNEL AUDIO_BITS diff --git a/MozziGuts_impl_RP2040.hpp b/MozziGuts_impl_RP2040.hpp index 096a292ca..dd1cf4a2e 100644 --- a/MozziGuts_impl_RP2040.hpp +++ b/MozziGuts_impl_RP2040.hpp @@ -242,6 +242,19 @@ static void startAudio() { i2s.setBCLK(BCLK_PIN); i2s.setDATA(DOUT_PIN); i2s.setBitsPerSample(AUDIO_BITS); + +// The PicoADK won't output a tone until it is unmuted. +// Move it into the Mozzi implementation so the user won't need to change mozzi code. +#if (ARDUINO_DATANOISETV_PICOADK) + // Soft mute and de-emphasis for audio codec + i2s.setBCLK(PIN_I2S_BCLK); + i2s.setDATA(PIN_I2S_DOUT); + + pinMode(25, OUTPUT); + digitalWrite(25, HIGH); + pinMode(23, OUTPUT); + digitalWrite(23, LOW); +#endif #if (AUDIO_BITS > 16) i2s.setBuffers(BUFFERS, (size_t) (BUFFER_SIZE/BUFFERS), 0); diff --git a/hardware_defines.h b/hardware_defines.h index db4f0b87e..264f2c08d 100644 --- a/hardware_defines.h +++ b/hardware_defines.h @@ -46,6 +46,10 @@ #define CACHED_FUNCTION_ATTR #endif +#if IS_RP2040() +#define AUDIO_RATE_PLATFORM_DEFAULT 32768 +#endif + #if IS_STM32() // This is a little silly, but with Arduino 1.8.13, including this header inside MozziGuts.cpp does not work (fails to detect the proper include path). // Putting it here, instead, seem to work. diff --git a/mozzi_rand.cpp b/mozzi_rand.cpp index 19d5f4a9f..76a73a429 100644 --- a/mozzi_rand.cpp +++ b/mozzi_rand.cpp @@ -9,6 +9,10 @@ extern STM32ADC adc; #include #endif +#if IS_RP2040() +#include "hardware/structs/rosc.h" +#endif + // moved these out of xorshift96() so xorshift96() can be reseeded manually static unsigned long x=132456789, y=362436069, z=521288629; // static unsigned long x= analogRead(A0)+123456789; @@ -144,6 +148,16 @@ void randSeed() { x = RANDOM_REG32; y = random (0xFFFFFFFF) ^ RANDOM_REG32; z = random (0xFFFFFFFF) ^ RANDOM_REG32; +#elif IS_RP2040() + uint32_t rand_seed; + for (int i = 0; i < 32; i++) + { + bool randomBit = rosc_hw->randombit; + rand_seed = rand_seed | (randomBit << i); + } + x = random (rand_seed); + y = random (rand_seed); + z = random (rand_seed); #else #warning Automatic random seeding not implemented on this platform #endif