-
-
Notifications
You must be signed in to change notification settings - Fork 237
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 latest version of the AudioTools library already installed.
- Install PureData on your desktop
- Install Python3 and hvcc with
pip3 install hvcc
- Start PureData and define your patch. I was using a minimum example which outputs a sine tone
- Save your patch 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: The generated Heavy_test class will be used in our sketch. - Create a new Arduino Sketch:
#include "AudioTools.h"
#include "Heavy_test.hpp" // import before PureDataStream!
#include "AudioLibs/PureDataStream.h"
Heavy_test pd_test(44100);
PureDataStream pd(pd_test);
I2SStream out; // or use any other output stream
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.
You need to use a microcontroller with quite some big Progmem: On an ESP32 you get
Sketch uses 612817 bytes (46%) of program storage space. Maximum is 1310720 bytes.
Global variables use 32392 bytes (9%) of dynamic memory, leaving 295288 bytes for local variables. Maximum is 327680 bytes.