-
-
Notifications
You must be signed in to change notification settings - Fork 278
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. In order to achieve this I am using the hvcc hcompiler that can translate a pd file to c and c++ code.
Here are the steps to produce a working sketch using the AudioTools library. I am assuming that you have the AudioTools library already installed.
- Install PureData on your desktop
- Install Python3 and hvcc with
pip3 install hvcc
- Start PureData and define your audio. I was using a minimum example which outputs a sine tone
- 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;
- 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. - Create a new Arduino Sketch:
#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
- Save the sketch and then close it!
- Copy the generated files from the c subdirectory to the sketch directory.
- Open the project in Arduino, compile and deploy it on your microcontroller.