Skip to content
Phil Schatzmann edited this page Oct 25, 2024 · 7 revisions

This fork contains the implementation for the support of Audio.

I recommend to test it with PlatformIO because the installation is quite simple. Here is the platformio.ini:

Example Sketch

and here is the related minimal sketch

#include <Arduino.h>
#include "Adafruit_TinyUSB.h"

Adafruit_USBD_Audio usb;

size_t readCB(uint8_t* data, size_t len, Adafruit_USBD_Audio& ref) {
  int16_t* data16 = (int16_t*)data;
  size_t samples = len / sizeof(int16_t);
  size_t result = 0;
  // generate random stereo data
  for (int j = 0; j < samples; j+=2) {
    data16[j] = random(-32000, 32000);
    data16[j+1] = random(-32000, 32000);;
    result += sizeof(int16_t)*2;
  }
  return result;
}

void setup() {
  // Start USB device as Audio Source
  usb.setReadCallback(readCB);
  usb.begin(44100, 2, 16);
}

void loop() {
  // use LED do display status
  usb.updateLED();
}

Arduino RP2040 Installation Instructions

Clone this wiki locally