Skip to content

Pure Data

Phil Schatzmann edited this page Feb 28, 2024 · 14 revisions

Pure Data (or just "Pd") is an open source visual programming language for multimedia. Pure Data is developed by Miller Puckette since 1996 and you can find it on his official website along with the official documentation and other related resources.

I wanted to have the possibility to run PD sketches on microcontrollers and I am using the hvcc hcompiler to achieve this. Here are the steps to produce a working sketch using the AudioTools library. I am assuming that you have the AudioTools library already installed.

  1. Install PureData on your desktop
  2. Install Python3 and hvcc with pip3 install hvcc
  3. Start PureData and define your audio. I was using a minimum example which outputs a sine tone

image

  1. Save it as a file: The file content of test.pd was:
#N canvas 349 94 450 300 12;
#X obj 134 65 osc~ 220;
#X obj 132 178 dac~;
#X connect 0 0 1 0;
  1. Now you can generate the c and c++ code with hvcc -n <name> <pd-file> e.g. hvcc -n test test.pd. The -n parameter gives your generated code a unique name.
  2. Create an Arduino Sketch, save it and then close it:
#include "AudioLibs/AudioBoardStream.h"  // install https://github.com/pschatzmann/arduino-audio-driver
#include "AudioLibs/PureDataStream.h"
#include "AudioTools.h"
#include "Heavy_test.hpp"  // import before PureDataStream!

Heavy_test pd_test(44100);
PureDataStream pd(pd_test);
AudioBoardStream out(AudioKitEs8388V1);
StreamCopy copier(out, pd);  // copy kit to kit

void setup() {
  Serial.begin(115200);
  AudioLogger::instance().begin(Serial, AudioLogger::Warning);

  // setup pd
  pd.begin();

  // setup output
  auto cfg = out.defaultConfig(TX_MODE);
  cfg.sd_active = false;
  cfg.copyFrom(pd.audioInfo());
  out.begin(cfg);
}

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

Here you can find further information on how to use the Heavy API

  1. Copy the generated files from the c subdirectory to the sketch directory.
  2. Open the project, compile and deplay it.