Im my last couple of Blogs, I have demonstrated how we can use the low level API of my Arduino Audio Tools library. Currently I am busy working on a high level API using Arduino Streams.

I did not commit my changes yet but I want to take the opportunity to share how the whole thing is supposed to work: We all know the Arduino Streams. We use them to write out print messages and sometimes we use them to read the output from Serial devices.

The same thing applies to my “Audio Streams”: You can read audio data from “Audio Sources” and you write them to “Audio Sinks”.

As “Audio Sources” we will have e.g.:

  • Analog Microphones – AnalogStream
  • Digital Microphonse – I2SStream
  • Files on the Internet – UrlStream
  • Generated Sound – GeneratedSoundStream
  • Mobile Phone A2DP Bluetooth – A2DPStream
  • Binary Data in Flash Memory – MemoryStream
  • SD Files

As “Audio Sinks” we will have e.g:

  • external DAC – I2SStream
  • an Amplifier – AnalogStream
  • Bluetooth Speakers – A2DPStream
  • Serial to display the data as CSV – CsvStream.
  • SD Files

Well – when we have an input stream from where we can read the audio data and an output stream to where we can write the data, we just need to copy from one to the other. You could program this yourself but I provide the StreamCopy class for this purpose.

Here is finally an simple example that displays some Audio Data from the internet as CSV on Serial:

#include "WiFi.h"
#include "AudioTools.h"

using namespace audio_tools;  

UrlStream music;  // Music Stream
int channels = 2; // The stream has 2 channels 
CsvStream<int16_t> printer(Serial, channels);  // ASCII stream 
StreamCopy copier(printer, music);    // copies music into printer

// Arduino Setup
void setup(void) {  
  // Open Serial 
  Serial.begin(115200);

  // connect to WIFI
  WiFi.begin("network name", "password");
  while (WiFi.status() != WL_CONNECTED){
    Serial.print(".");
    delay(500); 
  }

  // open music stream - it contains 2 channels of int16_t data
  music.begin("https://pschatzmann.github.io/Resources/audio/audio.raw");
}


// Arduino loop - repeated processing 
void loop() {
  copier.copy();
}

The result in the Arduino Plotter:

I think this looks pretty cool! – I just need to spend some more time with testing before I will finally commit…


2 Comments

Bruce Doan · 14. September 2022 at 5:30

I have a variety of questions regarding using the ESP32 in conjunction with an audio DSP device.

Are you available to answer any questions?

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *