Skip to content

Pipelines

Phil Schatzmann edited this page Apr 19, 2024 · 24 revisions

Currently it is already possible in the Arduino AudioTools Library to define some processing chains: Audio Objects are connected to other objects e.g. by adding the dependent object as parameter in the constructor.

I2SStream i2s
VolumeStream vol(i2s);

Since the beginning of the library, I wanted to have some Pipeline object that would help to define such chains in a more intuitive way. I finally committed this functionality to the Github:

Output Pipelines

All pipeline processing components are added with the help of the add() method, finally we define the final output with setOutput(). Calling begin() calls the begin method on all pipeline components. Any subclass of ModifyingStream can be used a pipleline component.

Pipeline pipeline;
I2SStream i2s;
VolumeStream volume;

pipeline.add(volume);
pipleine.setOutput(i2s);
pipeline.begin();

Example

Here is a full working example of an internet streaming application, that provides a volume control and outputs the data with 32 bits:

#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"

URLStream url("Phil Schatzmann","sabrina01");  
Pipeline pipeline;
MP3DecoderHelix helix;
EncodedAudioStream dec(&helix); 
VolumeStream volume;
NumberFormatConverterStream bits;
I2SStream i2s;
StreamCopy copier(pipeline, url);

void setup(){
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);  
  // mp3 radio
  url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");

  // predefine define some values
  volume.setVolume(0.5);
  bits.setToBits(32);

  // start pipeline
  pipeline.add(dec);
  pipeline.add(volume);
  pipeline.add(bits);
  pipeline.setOutput(i2s);
  // start all components with their default values
  pipeline.begin();
}

void loop(){
  copier.copy();
}

Input Pipelines

All pipeline processing components are added with the help of the add() method and we start the chain by defining the input with setInput(). Calling begin() calls the begin method on all pipeline components. Any subclass of ModifyingStream can be used a pipeline component.

Pipeline pipeline;
I2SStream i2s;
VolumeStream volume;

pipleine.setInput(i2s);
pipeline.add(volume);
pipeline.begin();

Example

Here is a full working example of an internet streaming application, that provides a volume control and outputs the data with 32 bits:

#include "AudioTools.h"
#include "AudioCodecs/CodecMP3Helix.h"
#include "AudioLibs/AudioBoardStream.h"

URLStream url("Phil Schatzmann","sabrina01");  
Pipeline pipeline;
MP3DecoderHelix helix;
EncodedAudioStream dec(&helix); 
VolumeStream volume;
NumberFormatConverterStream bits;
AudioBoardStream i2s(AudioKitEs8388V1);
StreamCopy copier(i2s, pipeline);

void setup(){
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Info);  
  // mp3 radio
  url.begin("http://stream.srg-ssr.ch/m/rsj/mp3_128","audio/mp3");

  // predefine define some values
  volume.setVolume(0.5);
  bits.setToBits(32);

  // pipeline
  pipeline.setInput(url);
  pipeline.add(dec);
  pipeline.add(volume);
  pipeline.add(bits);
  // start all components with their default values
  pipeline.begin();
}

void loop(){
  copier.copy();
}