Lab 2: Embedded Audio DSP with Faust and the Teensy

By the end of this lab, you should know how to synthesize and process sound on the Teensy using Faust!

Assembling the Teensy and the Audio Shield

To assemble your Teensy and your audio shield, take the following elements from your lab kit:

Take a small wire cutter and cut all the stackable pin headers on their 15th pin (the Teensy and the audio shield both have 14 pins on both sides):

Make the cut on the pin input (not on the junction of the pin)!

There are a bunch of breadboards in the Max Lab that have been prepared for 250a to facilitate the soldering of the pin headers on the Teensy and the audio shield. They should look like that:

You can’t miss them!

Place the Teensy and the headers on the breadboard as such (use the pins on the breadboard as a guide):

and solder them to the Teensy:

Make sure that your solder joints are clean and that they cover the pins on the Teensy. Solder joints should not touch each others. If you’re not sure about this, have it checked by Doga or Romain. If you make a mistake, you might fry your Teensy when you power it, so this is important!

Do the same for the audio shield:

Place the 5 male pins on the audio shield as such:

and solder them on the back of the audio shield:

Make sure that they are straight when you do that!

Finally, assemble the Teensy and the shield together by stacking them like this:

Make sure that the USB port and the audio jack are on the same side (like on the picture above)!

Making Sound

The Teensy is programmed using the Arduino software. Install Teensyduino on your system using the following instructions: https://www.pjrc.com/teensy/td_download.html.

Follow the DSP on the Teensy with Faust tutorial on the Faust website. Skip the section on “Audio Effect” (it is slightly outdated and we’ll do that later in this lab). Since Faust is probably not installed on your system, you should use the export (truck) function of the Faust Web IDE to generate Faust Teensy DSP objects (select Teensy as platform and Teensy as architecture). For now, use the headphone jack output on the Teensy as the main output. If you don’t have headphones with a jack plug, there’s a rubber maid bin in the Max Lab that says “headphones” on it. Feel free to use one of the headphones in that bin. Please, don’t bring it home and put it back in the bin once you’re done working.

Don’t forget to read the section on audio latency of the tutorial! This is important stuff!

Attaching Jack Plugs to the Teensy and the Audio Shield

The headphone jack output of the audio shield is handy for debugging, but you don’t necessarily want to use it for your “final product.” Instead, you should use the line input and output of the shield which are accessible through the male header pins that you soldered on the shield earlier. Note that audioShield.volume controls the gain of the headphone amplifier and will have no impact on the gain of the line output.

Your lab kit should contain the following elements (2 1/4in stereo (TRS) female jacks, 5 Dupont female crimps, 5 Dupont crimps housings, 4 short red stranded wires, 2 short black stranded wires):

Note: the picture only shows one black stranded wire, that’s a mistake.

Strip all the cables on both sides:

Then use a crimping plier:

to attach the crimps on one end of all the cables (except the second black cable):

Solder the wires onto the jack plugs as follows:

Note that the second black cable (the one with the crimp) is used to connect the ground pin of one of the jack plug to the other.

Finally, connect your assembly to the audio shield:

Audio Effect (Dealing with Audio Input)

The same procedure as the one described in the Faust/Teensy tutorial can be followed to generate audio effects for the Teensy Audio Library.

Let’s write a simple stereo Faust echo and run it on the Teensy:

import("stdfaust.lib");
del = hslider("del",20000,1,30000,1);
feedback = hslider("feedback",0.5,0,1,0.01);
echo = +~de.delay(30000,del)*feedback;
process = par(i,2,echo);

Note that for simplicity, the delay is controlled here as a number of samples (i.e., not a duration in seconds).

Generate a FaustEcho object from it and import it in a new Arduino project:

#include <Audio.h>
#include "FaustEcho.h"

FaustEcho faustEcho;
AudioInputI2S in;
AudioOutputI2S out;
AudioControlSGTL5000 audioShield;
AudioConnection patchCord0(in,0,faustEcho,0);
AudioConnection patchCord1(in,1,faustEcho,1);
AudioConnection patchCord2(faustEcho,0,out,0);
AudioConnection patchCord3(faustEcho,1,out,1);

void setup() {
  AudioMemory(6);
  audioShield.enable();
  faustEcho.setParamValue("del",22000);
  faustEcho.setParamValue("feedback",0.6);
}

void loop() {
}

Note that we had to increase the value for AudioMemory.

Run this program on the Teensy and test it by sending some audio signal to the 1/4in jack input and retrieving the result on the 1/4in jack output or the headphone output. There are a few 1/4in male to 1/8in male jacks in the Max Lab that can be used for this purpose (e.g., use your smartphone, etc.).

Assignment: Music Box/Sound Generator (Due on Jan. 23, 2019)

loop{
  faustInstrument.setParamValue("gate",1);
  faustInstrument.setParamValue("freq",440);
  delay(1000);
  faustInstrument.setParamValue("gate",0);
  delay(100);
  faustInstrument.setParamValue("gate",1);
  faustInstrument.setParamValue("freq",880);
  delay(1000);
  faustInstrument.setParamValue("gate",0);
  delay(100);
}

Note how delays here (in ms) are used to control the “rhythm,” etc. One more thing: controlling pitch with a frequency is not necessarily convenient so you might want to use the ba.midikey2hz Faust function.

Submissions

  • Raul Altosaar
  • Monica Ngozi Anuforo
  • Noah Louis Bailyn
  • Andrea Baldioceda
  • Noah Nathan Berrie
  • Hannah Lee Choi
  • Engin Daglik
  • Richard Chaffin Givhan
  • David Mendoza
  • Nolan Ashvin Miranda
  • John Mistele
  • Mike Robert Mulshine
  • Jeremy Thomas Raven
  • Samantha Elinon Silverstein
  • Kathlynn Marie Simotas
  • Jan Stoltenberg
  • Kangrui Xue