Fourier Series: Square Wave

Formula

The square wave has a faster decay towards higher partials than the sawtooth. It can be found in spectra of wind instruments.

  • only odd harmonics

  • constant sign

\begin{equation*} X(t) = \frac{4}{\pi} \sum\limits_{i=0}^{N} \frac{\sin(2 \pi (2i+1)ft)}{(2i + 1)} \end{equation*}

Interactive Example

Pitch (Hz):

Number of Harmonics:

Output Gain:

Time Domain:

Frequency Domain:

Like the sawtooth, the square wave shows the occurrence of ripples at the steep edges of the waveform. The higher the number of partials, the denser the ripples. This is referred to as the Gibbs phenomenon.

Faust: Compile for Puredata

Faust can compile Puredata objects:

$ faust2puredata sine.dsp

On linux systems this will create a file sine~.pd_linux, on MacOS a file sine~.pd_darwin. Place the file in your PD search paths and use it, as in the help file sine~-help.pd. Parameters are set with messages.

/images/Sound_Synthesis/sine_pd_example.png

Faust: Parallel Composition

Parallel processes in Faust are separated with the , operator. The following example uses two square wave oscillators, each passing through a lowpass filter. These chains are running in parallel, creating an output signal with two channels for the left and right audio output:

text


This example is a parallel combination of two sequential compositions. In Faust syntax, these need to be put in parenthesis.

Load this example in the Faust online IDE for a quick start:

import("stdfaust.lib");

freq  = hslider("Cutoff Frequency",100, 10, 1000, 0.001);

sig1  = os.square(50);
sig2  = os.square(70);

filt = fi.lowpass(5,freq);

process = (sig1:filt),(sig2:filt);

Online Tools and Materials

Faust Code

The Faust project features a rich set of properly documented examples. Nevertheless, this class has an accompanying Git Repository for code snippets and small tutorials.


IEM Plugins

The IEM Plug-in Suite was created by staff and students student of the Institute of Electronic Music and Acoustics in Graz. It is free and open source. Downloads and documentation can be found here https://plugins.iem.at/.

An in depth documentation of the IEM plugins features detailed information on installing and using the tools inside Reaper: https://plugins.iem.at/docs/.

The following pages include additional information on how to use the plugins with external software for control and processing, such as PD, SuperCollider and others.

A First Arduino-Sensor-Circuit

The Arduino

For all examples in this section, the Arduino UNO is used. The documentation on the official Arduino website covers all details on the connection possibilities and many examples to get started. The most important bit of information for most tutorials and basic applications is the pinout map:

/images/basics/arduino/A000066-pinout.png

Arduino pinout (https://docs.arduino.cc/).

Besides power and ground pins, the following connections are of interest for these examples:

  • 6 analog inputs (0-5V)

  • 14 digital pins (in and output mode can be set for each pin)

  • 5 PWM output pins

  • serial receive

  • serial transmit


The Sensor

This very first step shows how to use basic sensors with the Arduino. These sensors are variable resistors, which change their conductivity based on physical quantities. Examples are temperature, distance or force. The following examples us a light dependent resistor (LDR). The brighter the light it is exposed to, the lower its resistance.

/images/basics/ldr_curve.png

Figure: Approximated curve of the LDR in this example.


The Voltage Divider

In order to use the light dependent sensor in a measurement setup, a so called voltage divider is needed. It compares the variable resistor R1 (in this case the LDR) with a fixed resistor R2:

/images/basics/voltage_divider.png

Figure: Voltage divider circuit.

For a full use of the voltage range, R3 needs to be chosen properly. The voltage measured at the output depends on the reference voltage of 5V and the ratio between the two resistors:

$$ V_{out} = 5V \frac{R_2}{R_1 + R_2} $$

Some components, like potentiometers and faders, have the voltage divider integrated and thus have three pins for connection. They do not require an additional resistor.


Breadboard Wiring

The above-shown circuit can be realized using all components, a mini breadboard and three jumper cables. The documentation on the original Arduino website (Getting Started with Arduino introduces the board with all its connection capabilities in detail. For this example, we need a small breadboard, the LDR, one resistor and three jumper cables. A $100 \Omega$ resistor is chosen. For first steps, the Arduino can be powered via USB, which will also be used to read the sensor data into the Arduino serial monitor.

/images/basics/ldr_input_fritzing.png

Figure: Arduino breadboard wiring.


Arduino Code

The easiest way to program an Arduino is the dedicated Arduino IDE, which is available for all major operating systems. Install and use instructions are thoroughly documented on the official Arduino website.

The Arduino code for testing this sensor circuit is minimalistic. Like most Arduino sketches, basic setup is carried out in the setup() function on boot. In this case, the serial interface is started with a baud rate (speed in symbols per second) of 9600 bauds. Afterwards, the loop() function is carried out infinitely. It reads the given voltage at the selected pin A0 and prints it to the serial output.

Follow the instructions on the Arduino website to upload the below code to your board. In general, the serial port of the board needs to be selected in the IDE's dropdown manual, alongside the Arduino model - in this case the Arduino UNO.

void setup() {

Serial.begin(9600);
}

void loop() {

int sensorValue = analogRead(A0);

Serial.println(sensorValue);

delay(5);
}

Without any manipulation, the values from the analogRead() function range from 0 to 1024, since the Arduino analog-digital converters have 10 bit resolution:

$$ N = 2^{10} = 1024 $$


Exercise

Max for Live: A Short Introduction

Max for Live makes max patches run as part of an Ableton Live session. Depending on the nature of the patch, it can be inserted as a device in Audio or MIDI tracks by drag and drop. MIDI and audio outlets of the patch will be visible and usable inside Live like the connection of any other component. Over the years, many devices have been created by the community, some for free, some for sale: https://maxforlive.com/

The concept and its details are best described on Ableton's Live page. This short introduction should only cover the very basics for a quick start.


Max Audio Effects

Dragging the default Max Audio Effect into a track gives a basic patch connecting audio inlets (plugin~) with audio outlets (plugout~). Any processing can be inserted in between.

The default Max Audio Effect.

The default Max Audio Effect.

The following example uses the degrade~ object inside a Max Audio Effect.

A degrader effect.

A degrader effect inside Max for Live.


Max Instruments

The default Max Instrument can be dragged into a MIDI channel. It gives a patch with a midiin object to receive any incoming MIDI data and the plugout~ object to send audio into Live. Unlike the default Audio Effect, this patch is not functional.

The default Max Instrument.

The default Max Instrument.

Like the midiin object, other MIDI objects in Max can also be used inside Max For Live devices. The following mini saw example shows how to control a patch with MIDI from Live, using the notein and the ctlin objects.

A mini saw synthesizer.

A mini saw synthesizer.


Automation to Max for Live

The Inspector View

Although controlling Max for Live with MIDI is a good solution for many applications, Device Parameter Automation offers more flexibility and can also be used in audio channels. Most parameters in a Max for Live patch can be activated for automation, by editing inside the number inspector:

The number inspector in Max for Live.

The number inspector in Max for Live.

The following adjustments need to be made:

  • Parameter Mode Enable: check

  • Name (long/short): foo

  • Type: match parameter

  • Range: match parameter

  • Modulation Mode: match parameter

  • Parameter Visibility: Automated and Stored

Track Automation

After making the Max for Live parameters ready for automation, the general automation mode needs to be enabled in the Arranger view (the tiny blue button above the audio track). Afterwards, each tack shows the available automation parameters and they can be edited.

Automation in the arranger window.

Automation in the arranger window.

Clip Automation

The automation panel in the clip view gives access to all activated Max for Live parameters. This kind of modulation is tightly linked to the audio material, which can be both helpful and complicated.

Clip automation.

Clip automation.

Find more information on live parameters: https://docs.cycling74.com/max5/vignettes/core/live_parameters.html


Exercise

Binaural Introduction

Binaural Listening

Two-ear (binaural) listening encodes information on the direction and distance of a sound source by several cues. Figure 1 shows a listener with a sound source and its properties azimuth elevation and distance.

Interaural cues are based on the signal of both ears, more precisely their differences. They are in particular relevant for the horizontal Localization, respectively the azimuth:

  • interaural time differences (medium frequencies)

  • interaural level differences (high frequencies)

  • interaural phase differences (low frequencies)

In addition to the interaural cues, the coloration gives information on the elevation of a sound source, as well as on opposing azimuth angles which have identical interaural cues.

/images/spatial/binaural/binaural.png

Figure 1: Sound source with angles and distances to left and right ear.


Binaural Recording Technology

Dummy Head

Dummy Head recordings use the principles of binaural listening with two microphones and a model head, carrying these microphones at the position of the ear drum.

When the dummy head is placed in any environment, it listens and records the signals of both ears to two channels.

Many binaural records were released during the 1970s, yet without larger success.

https://binauralrecording.wordpress.com/2016/01/13/testing-spatial-hearing-the-development-of-the-neumann-ku80-dummy-head/

In Ear Microphones


With the increased use of in ear headphones and streaming, binaural techniques became more and more popular in the 2010s. ASMR artists, for example, use close-up binaural recordings to create intimate

https://www.youtube.com/watch?v=2CTc4gqW8Kk


HRTF Generation

Individual

Generic

Binaural Room Impulse Responses


References

1993

  • Elizabeth M Wenzel, Marianne Arruda, Doris J Kistler, and Frederic L Wightman. Localization using nonindividualized head-related transfer functions. The Journal of the Acoustical Society of America, 94(1):111–123, 1993.
    [details] [BibTeX▼]

1992

  • Henrik Møller. Fundamentals of binaural technology. Applied acoustics, 36(3-4):171–218, 1992.
    [details] [BibTeX▼]

Ansible

Ansible is a tool for managing a fleet of machines. There might be some tasks that you have to execute on every machine in your data center.

---

Ansible Without SSH Keys

apt-get install sshpass

Playbooks

Instead of logging in in every machine via SSH, we write an Ansible playbook that describes all tasks in a YAML file.

---
- name: Installing packages
  hosts: web
  become: yes
  gather_facts: no
  tasks:
    - name: Install git
      apt:
          name: git
          state: present
          update_cache: yes
    - name: Install ALSA
      apt:
          name: alsa
          state: present
          update_cache: yes
    - name: Install ALSA Dev
      apt:
          name: libasound2-dev
          state: present
          update_cache: yes
    - name: Install Jack
      apt:
          name: jackd2
          state: latest
          update_cache: yes

By default Ansible logs into every machine via SSH. hosts: web tells ansible to execute following tasks on all machines in the inventory group web. Installing packages with APT requires superuser permissions. become: yes tells Ansible to become root. The default method for this is sudo.

The biggest benefit over shell scripts is that it is possible to describe the state of a machine. In the example four packages will be installed. Only jackd2 will be updated if it is already present.

---

Inventory

For executing our new playbook Ansible needs to know what machines are in our inventory. The inventory can be written in INI or YAML syntax.

[local]
localhost

[web]
google.de
facebook.de

The default location for your inventory file is /etc/ansible/hosts.

For more information for creating your inventory see the official user guide.

---

ansible.cfg

A separate inventory file can be set for your project in an Ansible configuration file ansible.cfg:

[defaults]
inventory = hosts
ansible_ssh_user = studio
sudo_user = studio

This file sets the location of your inventory file to ./hosts. Furthermore the default SSH user as well as the sudo user gets set to studio.

---

Executing a Playbook

Executing our playbook file install_basic.yml:

ansible-playbook install_basic.yml -k -K

For this to work every machine in group web must have a user studio with the same password. The flag -k lets Ansible ask for a SSH password. -K is for the sudo password.

If there's a SSH key for user studio on all machines, no SSH password has to be typed, but the password for sudo is still necessary.