Switched-On Yampa Switched-On Yampa Declarative Programming of Modular Synthesizers George Giorgidze Henrik Nilsson School of Computer Science University of Nottingham Tenth International Symposium on Practical Aspects of Declarative Languages San Francisco, USA January 8, 2008
41
Embed
Switched-on Yampa: Declarative programming of modular synthesizers
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Switched-On Yampa
Switched-On YampaDeclarative Programming of Modular Synthesizers
George Giorgidze Henrik Nilsson
School of Computer ScienceUniversity of Nottingham
Tenth International Symposium onPractical Aspects of Declarative Languages
San Francisco, USAJanuary 8, 2008
Switched-On Yampa
Outline
1 Modular Synthesizers
2 Yampa
3 Practical Aspects
4 Examples
5 Real Music
6 Performance
7 Conclusions
Switched-On Yampa
Modular Synthesizers
Modular Synthesizer
Switched-On Yampa
Modular Synthesizers
Clavia Nord Modular
Switched-On Yampa
Modular Synthesizers
Clavia Nord Modular
Switched-On Yampa
Yampa
What is Yampa?
Domain-specific language embedded in Haskell for programminghybrid (mixed discrete-time and continuous-time) systems.
Yampa is based on the concepts of Functional ReactiveProgramming (FRP) [Elliott, Hudak, Nilsson, Peterson, ...].
Switched-On Yampa
Yampa
Key Concepts
Signals: time-varying values
Signal Functions: functions on signals
Switching between signal functions
Yampa programs are structured using arrows [Hughes, Paterson]
Switched-On Yampa
Yampa
Key Concepts
Signals: time-varying values
Signal Functions: functions on signals
Switching between signal functions
Yampa programs are structured using arrows [Hughes, Paterson]
Programming model:
Switched-On Yampa
Yampa
Key Concepts
Signals: time-varying values
Signal Functions: functions on signals
Switching between signal functions
Yampa programs are structured using arrows [Hughes, Paterson]
Programming model:
Switched-On Yampa
Yampa
Signals and Signal Functions
Intuition:
type Signal α ≈ Time → α
x :: Signal T1
y :: Signal T2
type SF α β ≈ Signal α→ Signal β
f :: SF T1 T2
Switched-On Yampa
Yampa
Programming with signal functions
In Yampa, systems are described by combining signal functions (formingnew signal functions).
A combinator can be defined that captures this idea:
(≫) :: SF a b → SF b c → SF a c
Switched-On Yampa
Yampa
Signal Function Combinators
arr :: (a→ b)→ SF a b
(&&&) :: SF a b → SF a c → SF a (b, c)
switch :: SF a (b, Event c)→ (c → SF a b)→ SF a b
Switched-On Yampa
Practical Aspects
Some Points
Music can be seen as a hybrid phenomenon.
Music is sound: continuous pressure waves in some medium such asair.
Switched-On Yampa
Practical Aspects
Some Points
Music can be seen as a hybrid phenomenon.
Music is sound: continuous pressure waves in some medium such asair.Musical performance has clear discrete aspects.
Musical scoresMIDI StandardHaskore [Hudak]
Thus it is interesting to explore a hybrid approach to programmingmusic and musical applications.
Switched-On Yampa
Practical Aspects
Some Other Points
Yampa’s programming model is very reminiscent of programmingmodular synthesizers.
Switched-On Yampa
Practical Aspects
Some Other Points
Yampa’s programming model is very reminiscent of programmingmodular synthesizers.
We apply declarative Embedded Domain Specific Language (EDSL)to practical problem.
Switched-On Yampa
Practical Aspects
Some Other Points
Yampa’s programming model is very reminiscent of programmingmodular synthesizers.
We apply declarative Embedded Domain Specific Language (EDSL)to practical problem.
Fun application!
MIDI Music playerReal-time synthesizerCan be used in educational context
Switched-On Yampa
Practical Aspects
What we have done so far
Framework for programming modular synthesizers in Yampa:
Sound-generating and sound-shaping modules
Switched-On Yampa
Practical Aspects
What we have done so far
Framework for programming modular synthesizers in Yampa:
Sound-generating and sound-shaping modules
Supporting infrastructure:
Reading MIDI files (musical scores)Reading SoundFont files (instrument definitions)Writing result as audio files (.wav)Rendering audio directly to soundcard in real-timeKeyboard driver with basic GUI to play music with your synthesizer
Switched-On Yampa
Examples
Simple Patch
Switched-On Yampa
Examples
Simple Sine Oscillator
s = sin(2πft) (1)
Switched-On Yampa
Examples
Simple Sine Oscillator
s = sin(2πft) (1)
time :: SF a Time
oscSine :: Frequency → SF a Sample
oscSine f = time ≫ arr (λt → sin (2 ∗ pi ∗ f ∗ t))
Switched-On Yampa
Examples
Dynamically Controllable Sine Oscillator
φ = 2π
t∫
0
f (τ)dτ (2)
s = sin(φ) (3)
Switched-On Yampa
Examples
Dynamically Controllable Sine Oscillator
φ = 2π
t∫
0
f (τ)dτ (2)
s = sin(φ) (3)
oscSine :: Frequency → SF CV Sample
oscSine f0 = proc cv → do
let f = f0 ∗ (2 ∗∗ cv)phi ← integral−≺ 2 ∗ pi ∗ f
returnA−≺ sin phi
Switched-On Yampa
Examples
Dynamically Controllable Sine Oscillator
φ = 2π
t∫
0
f (τ)dτ (2)
s = sin(φ) (3)
oscSine :: Frequency → SF CV Sample
oscSine f0 = proc cv → do
let f = f0 ∗ (2 ∗∗ cv)phi ← integral−≺ 2 ∗ pi ∗ f
returnA−≺ sin phi
oscSine f0 =arr (λcv → let f = f0 ∗ (2 ∗∗ cv) in 2 ∗ pi ∗ f )≫ integral
FM synthesis is a form of audio synthesis where the timbre of a simplewaveform is changed by frequency modulating it with a modulatingfrequency that is also in the audio range, resulting in a more complexwaveform and a different-sounding tone.
Switched-On Yampa
Examples
Bell
FM synthesis is a form of audio synthesis where the timbre of a simplewaveform is changed by frequency modulating it with a modulatingfrequency that is also in the audio range, resulting in a more complexwaveform and a different-sounding tone.
bell :: Frequency → SF () (Sample, Event ())bell f = proc ()→ do
m ← oscSine (2.33 ∗ f )−≺ 0
audio ← oscSine f −≺ 2.0 ∗m
(ampl , end)← envBell −≺ noEvent
returnA−≺ (audio ∗ ampl , end)
Switched-On Yampa
Real Music
MIDI Music
Parse MIDI file and obtain event source:
SF a (Event [Midi .Message ])
Obtain MIDI messages from keyboard and feed them to runningsignal function during reactimation.
Switched-On Yampa
Real Music
Monophonic Synthesizer
Read samples (instrument recordings) together with other synthesisparameters from SoundFont file into internal table.
Oscillator similar to sine oscillator, except sine function replaced bytable lookup and interpolation.
We obtain collections of monophonic syntehsizers
Switched-On Yampa
Real Music
Exploit Yampa’s switching capabilities to:
create and switch in a monophonic synthesizer instance is responseto each note on event;
switch out the instance in response to a corresponding note offevent.
Switched-On Yampa
Real Music
Polyphonic Synthesizer
pSwitchB :: Functor col ⇒
col (SF a b) -- Initial signal func. collection→ SF (a, col b) (Event c) -- Triggers change→ (col (SF a b)→ c → SF a (col b)) -- Performs change→ SF a (col b)
Even t ( )
S a m p l e
S a m p l e
S a m p l e
m i x e r
t r i g g e r C h a n g e
p e r f o r m C h a n g e
m o n o S y n t h
m o n o S y n t h
m o n o S y n t h
M i d i E v e n t
S y n t h S t a t e
( [ N o t e I d ] , [ M o n o S y n t h I d ] , S y n t h S t a t e )