Skip to content

Commit

Permalink
Merge pull request #113 from ideoforms/docs/examples
Browse files Browse the repository at this point in the history
Documentation: Examples
  • Loading branch information
ideoforms authored Feb 11, 2024
2 parents 7c0adb4 + 913147a commit 9dacb89
Show file tree
Hide file tree
Showing 29 changed files with 363 additions and 11 deletions.
28 changes: 28 additions & 0 deletions docs/library/envelope/asrenvelope/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using ASREnvelope to shape the sound of an oscillator over time.
# The Line node generates a continuously-changing value which we use as the
# release time.
#-------------------------------------------------------------------------------
clock = Impulse(8.0)
CMaj7 = [ 60, 64, 67, 71, 74, 76 ] * 8
FMaj9 = [ 65, 69, 72, 76, 77, 81 ] * 8
arpeggios = CMaj7 + FMaj9
sequence = Sequence(arpeggios, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = TriangleOscillator(frequency)
release = Line(0.1, 0.5, 6, True)
envelope = ASREnvelope(attack=0.0,
sustain=0.0,
release=release,
curve=1.0,
clock=clock)
voice = oscillator * envelope

pan = SineLFO(0.1667, -1.0, 1.0)
output = StereoPanner(voice, pan)
output.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/envelope/line/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
clock = Impulse(frequency=1.0)
line = Line(0.0, 0.5, 0.5, False, clock)
osc = SawOscillator(200)
output = osc * line
output = StereoPanner(osc * line)
output.play()
graph.wait()
23 changes: 23 additions & 0 deletions docs/library/envelope/line/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using Line to repeatedly alter the release value of an envelope applied to the
# main synth voice, in time with the music.
#-------------------------------------------------------------------------------
clock = Impulse(8.0)
CMaj7 = [ 60, 64, 67, 71, 74, 76 ] * 8
FMaj9 = [ 65, 69, 72, 76, 77, 81 ] * 8
arpeggios = CMaj7 + FMaj9
sequence = Sequence(arpeggios, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = TriangleOscillator(frequency)
release = Line(0.1, 0.5, 6, True)
envelope = ASREnvelope(0.0, 0.0, release, 1.0, clock)
voice = oscillator * envelope

pan = SineLFO(0.1667, -1.0, 1.0)
output = StereoPanner(voice, pan)
output.play()
graph.wait()
11 changes: 11 additions & 0 deletions docs/library/operators/channelarray/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using ChannelArray to pan a low tone to the left and a high tone to the right.
#-------------------------------------------------------------------------------
low = TriangleOscillator(220)
high = TriangleOscillator(660)
panned = ChannelArray([low, high]) * 0.3
panned.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/oscillators/impulse/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
clock = Impulse(1.0)
osc = TriangleOscillator(250)
envelope = ASREnvelope(0.01, 0.0, 0.5, 1.0, clock)
output = osc * envelope
output = StereoPanner(osc * envelope)
output.play()
graph.wait()
3 changes: 2 additions & 1 deletion docs/library/oscillators/sawlfo/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#-------------------------------------------------------------------------------
lfo = SawLFO(1, 200, 1000)
sine = SineOscillator(lfo)
sine.play()
output = StereoPanner(sine) * 0.5
output.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/oscillators/sawoscillator/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#-------------------------------------------------------------------------------
saw = SawOscillator(440)
envelope = ASREnvelope(0.05, 0.1, 0.5)
output = saw * envelope
output = StereoPanner(saw * envelope) * 0.5
output.play()
graph.wait()
3 changes: 2 additions & 1 deletion docs/library/oscillators/sinelfo/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#-------------------------------------------------------------------------------
lfo = SineLFO(1, 200, 1000)
saw = SawOscillator(lfo)
saw.play()
output = StereoPanner(saw) * 0.3
output.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/oscillators/sineoscillator/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#-------------------------------------------------------------------------------
sine = SineOscillator(440)
envelope = ASREnvelope(0.1, 0.1, 0.5)
output = sine * envelope
output = StereoPanner(sine * envelope) * 0.5
output.play()
graph.wait()
3 changes: 2 additions & 1 deletion docs/library/oscillators/squarelfo/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#-------------------------------------------------------------------------------
lfo = SquareLFO(1, 200, 400)
sine = SineOscillator(lfo)
sine.play()
output = StereoPanner(sine) * 0.5
output.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/oscillators/squareoscillator/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#-------------------------------------------------------------------------------
square = SquareOscillator(440)
envelope = ASREnvelope(0, 0.1, 0.5)
output = square * envelope
output = StereoPanner(square * envelope) * 0.5
output.play()
graph.wait()
3 changes: 2 additions & 1 deletion docs/library/oscillators/trianglelfo/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
#-----------------------------------------------------------------------------------
lfo = TriangleLFO(3, 200, 900)
sine = SineOscillator(lfo)
sine.play()
output = StereoPanner(sine) * 0.5
output.play()
graph.wait()
2 changes: 1 addition & 1 deletion docs/library/oscillators/triangleoscillator/example-0.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
#-------------------------------------------------------------------------------
tri = TriangleOscillator(440)
envelope = ASREnvelope(0.1, 0.1, 0.5)
output = tri * envelope
output = StereoPanner(tri * envelope) * 0.5
output.play()
graph.wait()
22 changes: 22 additions & 0 deletions docs/library/processors/delays/allpassdelay/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using AllpassDelay to add a delay effect to a simple melodic sequence.
# The original oscillator can be heard in the left channel.
# The delay effect can be heard in the right channel.
#-------------------------------------------------------------------------------
clock = Impulse(1.0)
sequence = Sequence([ 60, 62, 64, 65, 67, 69, 71, 72 ], clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = TriangleOscillator(frequency)
envelope = ASREnvelope(0, 0.2, 0.3, 1.0, clock)
voice = oscillator * envelope
delayed = AllpassDelay(input=voice,
delay_time=0.4,
feedback=0.8)

output = ChannelArray([ voice, delayed ]) * 0.75
output.play()
graph.wait()
25 changes: 25 additions & 0 deletions docs/library/processors/delays/allpassdelay/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using AllpassDelay to add a dreamy atmosphere to synth arpeggios
#-------------------------------------------------------------------------------
clock = Impulse(3.5)
Am7 = [ 67, 64, 60, 57 ] * 4
D7 = [ 62, 66, 69, 72] * 4
arpeggios = Am7 + D7
sequence = Sequence(arpeggios, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = SquareOscillator(frequency)
envelope = ASREnvelope(0.1, 0, 0.2, 1.0, clock)
voice = oscillator * envelope
filtered = SVFilter(voice, "low_pass", 4000, 0.3)
delayed = AllpassDelay(input=filtered,
delay_time=0.15,
feedback=0.8)

pan = TriangleLFO(0.1, -1.0, 1.0)
output = StereoPanner(delayed, pan) * 0.5
output.play()
graph.wait()
23 changes: 23 additions & 0 deletions docs/library/processors/delays/combdelay/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using CombDelay to change the character of a saw wave oscillator.
#-------------------------------------------------------------------------------
clock = Impulse(4)
arpeggio = [60, 62, 64, 66, 68, 70,
72, 70, 68, 66, 64, 62]
sequence = Sequence(arpeggio, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = SawOscillator(frequency)
envelope = ASREnvelope(0.1, 0, 0.2, 1.0, clock)
voice = oscillator * envelope
comb = CombDelay(input=voice,
delay_time=0.09,
feedback=0.6,
max_delay_time=0.9)

output = StereoPanner(comb) * 0.5
output.play()
graph.wait()
16 changes: 16 additions & 0 deletions docs/library/processors/delays/onetapdelay/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using OneTapDelay to create a delay effect with no feedback.
# The original sound is heard in the left channel, and the delayed sound in the
# right channel.
#-------------------------------------------------------------------------------
clock = Impulse(1)
oscillator = TriangleOscillator(440)
envelope = ASREnvelope(0.001, 0, 0.3, 1.0, clock)
voice = oscillator * envelope
delayed = OneTapDelay(voice, 0.25) * 0.5
output = ChannelArray([voice, delayed]) * 0.5
output.play()
graph.wait()
26 changes: 26 additions & 0 deletions docs/library/processors/delays/onetapdelay/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using OneTapDelay to bring controlled rhythmic interest to a melodic sequence
#-------------------------------------------------------------------------------
clock = Impulse(3.5)
Dm = [ 62, 65, 69 ] * 2
Bdim = [ 59, 62, 65 ] * 2
Gm = [55, 58, 62 ] * 2
Bb = [77, 74, 70 ]
A = [ 76, 73, 69 ]

arpeggios = Dm + Bdim + Gm + Bb + A
sequence = Sequence(arpeggios, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = SquareOscillator(frequency)
envelope = ASREnvelope(0.1, 0, 0.2, 1.0, clock)
voice = oscillator * envelope
filtered = SVFilter(voice, "low_pass", 4000, 0.3)
delayed = filtered + OneTapDelay(filtered, 0.4) * 0.5

output = StereoPanner(delayed) * 0.3
output.play()
graph.wait()
11 changes: 11 additions & 0 deletions docs/library/processors/distortion/resample/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using Resample to distort a sine wave.
#-------------------------------------------------------------------------------
sine = SineOscillator(440)
crushed = Resample(sine, 11025, 4)
output = StereoPanner(crushed) * 0.3
output.play()
graph.wait()
17 changes: 17 additions & 0 deletions docs/library/processors/filters/eq/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using EQ to shape white noise. The low band (below 500Hz) is reduced. The mid
# band is boosted. The high band (above 2000Hz) is reduced drastically.
#-------------------------------------------------------------------------------
noise = WhiteNoise()
eq = EQ(input=noise,
low_gain=0.0,
mid_gain=1.5,
high_gain=0.2,
low_freq=1000,
high_freq=2000)
output = StereoPanner(eq) * 0.5
output.play()
graph.wait()
14 changes: 14 additions & 0 deletions docs/library/processors/filters/svfilter/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using SVFilter as a low-pass filter on white noise.
#-------------------------------------------------------------------------------
noise = WhiteNoise()
filtered = SVFilter(input=noise,
filter_type="low_pass",
cutoff=1000,
resonance=0.6)
output = StereoPanner(filtered)
output.play()
graph.wait()
27 changes: 27 additions & 0 deletions docs/library/processors/filters/svfilter/example-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using SVFilter as a low-pass filter to reduce the harshness of a square wave
# oscillator.
#-------------------------------------------------------------------------------
clock = Impulse(3.5)
Am7 = [ 67, 64, 60, 57 ] * 4
D7 = [ 62, 66, 69, 72] * 4
arpeggios = Am7 + D7
sequence = Sequence(arpeggios, clock)
frequency = MidiNoteToFrequency(sequence)

oscillator = SquareOscillator(frequency)
envelope = ASREnvelope(0.1, 0, 0.2, 1.0, clock)
voice = oscillator * envelope
filtered = SVFilter(input=voice,
filter_type= "low_pass",
cutoff=4000,
resonance=0.3)
delayed = AllpassDelay(filtered, 0.15, 0.8, 0.5)

pan = TriangleLFO(0.1, -1.0, 1.0)
output = StereoPanner(delayed, pan) * 0.3
output.play()
graph.wait()
17 changes: 17 additions & 0 deletions docs/library/processors/panning/stereobalance/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Demonstrating the effects of StereoBalance. First a low tone is assigned to
# the left channel and a high tone is assigned to the right channel.
# Setting StereoBalance's balance value to 0.0 will mean both tones are heard
# equally. A value of -1.0 will result in only the left channel being heard.
# A value of 1.0 will result in only the right channel being heard.
# In this example, an LFO is modulating the balance value between -1.0 and 1.0.
#-------------------------------------------------------------------------------
low = TriangleOscillator(220)
high = TriangleOscillator(660)
panned = ChannelArray([low, high])
balanced = StereoBalance(panned, TriangleLFO(0.2, -1, 1)) * 0.5
balanced.play()
graph.wait()
16 changes: 16 additions & 0 deletions docs/library/processors/panning/stereopanner/example-0.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from signalflow import *
graph = AudioGraph()

#-------------------------------------------------------------------------------
# Using StereoPanner to pan a low pitch to the left and a high pitch to the
# right.
#-------------------------------------------------------------------------------
low = TriangleOscillator(220)
high = TriangleOscillator(660)

left = StereoPanner(low, -0.8)
right = StereoPanner(high, 0.8)

output = (left + right) * 0.5
output.play()
graph.wait()
Loading

0 comments on commit 9dacb89

Please sign in to comment.