Pure Data uses programming blocks and lines to build a functional script.

Reading Data from the QT Py ESP32-S2

At the top of the script, Pure Data begins listening to port 12345 and receiving data over the port using netrecieve.

The incoming data is sent from the QT Py ESP32-S2 with the socket message. This message is parsed using route. The message is divided by the variable names sent before each sensor value.

  • TSC2007 x coordinate: x
  • TSC2007 y coordinate: y
  • ADXL343 x value: aX
  • ADXL343 y value: aY
  • Run state: run
  • MIDI note number: n 

Values are sent around a Pure Data script using s or send. Underneath route, you can see each individual value being sent with s.

The Sequencer

The seq array holds the received MIDI notes and are played in a loop. You can adjust the array's parameters using the bounds, const and resize messages.

Values are received as inputs using receive or r. n and x are received by the array using r. Those values are written to the array using tabwrite.

Start the Synth

run affects whether the synth patch is playing or not. When a new run message is received from the socket, the patch will either begin playing or stop. Additionally, when it stops, a 0 is sent to all of the parameters so that the synth is muted using s off.

Loop Through the Sequencer

The + 1 and % 8 blocks act as a for loop, advancing by 1 with a limit of 8. This lets the script iterate through the notes in the seq array like a sequencer. 

tabread reads the MIDI notes in the seq array. Those note numbers are converted to frequencies using the MIDI to Frequency block (mtof). The frequency is sent to the synth.

The Sawtooth Synth

The synth is built using a sawtooth waveform, created with the phasor~ block. It has a series of filters that are affected by the accelerometer.

VCF Filter and Audio Output

The final stop is a VCF filter, created with the vcf~ block. The VCF's value is affected by the note playing in the seq array.

The output~ block controls the audio output from the patch. You can change the volume by adjusting the dB block and mute all audio by clicking next to mute.

This guide was first published on Apr 05, 2022. It was last updated on 2022-04-05 18:55:00 -0400.

This page (How the Pure Data Script Works) was last updated on May 15, 2022.

Text editor powered by tinymce.