Monday, November 14, 2016

34. Gen9

A Gen9 UGen uses Fourier composition of sines and cosines to add inharmonically related frequencies.


For each component, we need the relative frequency, relative amplitude and relative phase.


Here, we have 3 components: first at fundamental with ratio of 1 and phase 0, second at twice fundamental, half amplitude, with 0 phase, and third at three times fundamental, ratio of 1/3, and phase of 90.


We have 2 periods of Gen9 as the phasor, driving it, varies from 0 to 1, for 2 periods.


# chuck34.py - Gen9

Phasor phasor
Gen9 g9

dac = g9
g9 = phasor

g9.coefs = [1.,1.,0., 2.,1./2.,0., 3.,1./3.,90.]

phasor.freq = 100

time(20::ms)

This is the wave, after running python createWav.py chuck34, on command line:


Sunday, November 13, 2016

33. Gen10 to create square wave

A Gen10 UGen uses Fourier composition of sines of harmonically related frequencies.


The fundamental frequency is based on the phasor frequency (it is 100 Hz in this example).


We try to compose a square wave which has odd frequencies only, which vary as the reciprocal of the frequency.


We have 2 periods of Gen10 as the phasor varies from 0 to 1, for 2 periods.


# chuck33.py - Gen10 to create square wave

Phasor phasor
Gen10 g10

dac = g10
g10 = phasor

g10.coefs = [1., 0, 1./3., 0., 1./5., 0., 1./7.]

phasor.freq = 100

time(20::ms)

This is the wave, after running python createWav.py chuck33, on command line:


32. Gen5

A Gen5 UGen can produce a wave with exponential line segments.


We have to give coefficients in range (-1 to +1), for x from 0 to 1. These serve as the y-points where the piecewise exponential curve goes through.


Since a ramp from 0 to 1 is the function of a Phasor, a phasor drives the Gen5 oscillator.


We have 2 periods of Gen5 as the phasor varies 0 to 1, for 2 periods.


# chuck32.py - Gen5

Phasor phasor
Gen5 g5

dac = g5
g5 = phasor

# 0.1 is inital value
# At 0.5, it is at 0.9
# At 0.75 (0.5+0.25), it is at 0.7
# At 1 (0.5+0.25+0.25), it is at 0.1

g5.coefs = [0.1, 0.5, 0.9, 0.25, 0.7, 0.25, 0.1]

phasor.freq = 100

time(20::ms)

This is the wave, after running python createWav.py chuck32, on command line:


31. Gen7

A Gen7 UGen can produce a wave with linear line segments.


We have to give coefficients in range (-1 to +1), for x from 0 to 1.


Since a ramp from 0 to 1 is the function of a Phasor, a phasor drives the Gen7 oscillator.


We have 2 periods of Gen7 as the phasor varies 0 to 1, for 2 periods.


# chuck31.py - Gen7

Phasor phasor
Gen7 g7

dac = g7
g7 = phasor

# 0.1 is inital value
# At 0.5, it is at 0.9
# At 0.75 (0.5+0.25), it is at 0.7
# At 1 (0.5+0.25+0.25), it is at 0.1

g7.coefs = [0.1, 0.5, 0.9, 0.25, 0.7, 0.25, 0.1]

phasor.freq = 100

time(20::ms)

This is the wave, after running python createWav.py chuck31, on command line:


30. SawOsc as phasor

We can use SawOsc to produce the wave in tutorial 1.


The gain of SawOsc is reduced by a factor of 2 (gain is 0.5) and initial phase changed so it goes up for the entire period.


The gain of SawOsc goes from -1 to +1, during a period. Changing the gain we go from -.5 to .5. If we add a step of 0.5, we get the desired wave.



# chuck30.py - SawOsc as phasor

SawOsc saw
Step step

# sawtooth oscillator + step of 0.5 connected to dac
dac = step
dac = saw 

# phasor frequency of 100 Hz, step of 0.5
saw.freq = 100
step.next = 0.5

# correct phase and gain
saw.phase = 0.75
saw.gain = 0.5

# Play for 20 ms = 0.02 second (2 periods of 100-Hz)
time(20::ms)

This is the wave, after running python createWav.py chuck30, on command line:


29. Phasor

A Phasor UGen creates a ramp from 0 to 1. In many ways it is similar to SawOsc.


# chuck29.py - phasor

Phasor phasor

# phasor connected to dac
dac = phasor 

# phasor frequency of 100 Hz
phasor.freq = 100

# Play for 20 ms = 0.02 second (2 periods of 100-Hz)
time(20::ms)

After running from the command line, python createWav.py chuck29, we get this audio file: