Welcome to CSA open day hope you guys had
a very good day attending lab demos and looking around different research in every lab so
you may be wondering what this talk is about so here is "Let's Code Music! Understanding Programming Language Design
through Music" um so just some background: in 2017 we had this course called Programming
Language Design and Implementation where we had to learn from nine languages; nine programming
languages! and each of those languages were unique in
the sense tha
t you apply to different domains right for example if you want a programming
language for logic programming there are ways to model that or implement that language differently
if you want a language that is used to build large scale systems then you have to think
differently right and one of those languages was Chuck which is a programming language
for music and which is quite interesting in the sense that um you could just write code,
run it and the output is music and what particularly intrigu
ed me now as a musician I would never
use Chuck to create music because it's too complicated you have a lot of control you
can do a lot of things with it you can code at the level of samples you know so I prefer
to use GarageBand (or Reaper) which is easier, but nevertheless this language is quite interesting
from a programming language design perspective, and that is the key idea of the talk so target
audience! I think uh how many of you have done programming
before oh that's nice it's around 7
0 percent um how many of you are musicians oh great
that's like 10 20 percent so if you don't know music don't worry I mean it's going to
be taught from scratch now um what about your background how many of you are in engineering
(Undergrad) or senior okay good most of you guys are from outside CSA? how many people outside CSA okay that is a
fairly uh good idea. Now how many of you when you implement ("use")
a language have actually thought about how it is made or what are the design decisions
t
hat go into it how many of you actually think on those lines? Anyway, I'm sure you CSA professors think
about them all the time. :P yeah the point is that the key takeaway is
that if you are a student from coming from outside CSA the key takeaway is that if you
can just think on the lines of programming language design after you leave this talk
right now I can think of C and C plus plus and see how it's designed but it may be too
technical so I've chosen this language in the sense that it will b
e a bit more fun you
play some music, you code music see some output and then actually in the end see how the language
is actually built. Now, the target audience is anyone with an
interest in programming or music or just curious to know how this intersection. Don't worry about not knowing music everything
will be explained regarding programming it's preferred if you have (some experience) but
if not still you will get something out of the talk for sure uh towards the end the last
15 or 20 minut
es I'll get into technical details uh hope you get an idea of what it feels to
think about designing a programming language but they'll be more focused towards Chuck
than a general purpose programming language now uh of course the point of this talk is
to have fun the first 20 minutes we will be having fun playing some music and seeing how
this works more importantly the takeaway or essence is understanding how the program of
language is designed right that's why I've chosen music and then think
ing about those
things. so hopefully once we reach this part (of the
talk), wherever background we have come from, let's hope you get something out of the talk
so for the first 10 20 20 30 minutes we quickly look at Chuck and the essence of what the
unlike principles of this language are and then we look at the programming language design
for the next few minutes so let's begin with music programming using Chuck as the first
part (of the talk) now what is Chuck? Chuck is a programming language f
or Real-Time
sound synthesis and Music Creation Chuck offers a unique time-based concurrent programming
model that's precise and expressive and they call this strongly timed; the key takeaway
is strongly timed and how this concurrent programming model differs from traditional
models. Dynamic control rates, and the ability to
add and modify code on-the-fly which I will show you dynamically (as the talk progresses),
like you write code, add more code and it just works smoothly and how it's done th
e
underlying synchronization model takes care of it. so we'll discuss these topics in detail this
was actually designed by GE Wang under the guidance of Perry Cook at Princeton University
it was his PhD thesis so today what we'll do is look at some music, I play some music,
I write code for it which play the same music and let's see how to go about it we will look
into live performance with On-The-Fly programming that's what I'm going to show you so let's
begin. So the essence of music is as fol
lows there
are two key paradigms here one is timing and second is concurrency; you cannot do one without
the other... [Music] so if you have say you have to write
code for something say you want to create some music right and let's say the music sounds
something like this [Music] and let's say you have another program that does something
like this [Beats] this is just basic Beats now if you combine both how should it sound? It should sound something like this right? [Plays Percussive Guitar] so
what's happening? Firstly, I'm playing with time and the second
point I'm trying to note is concurrency right? and see I'm doing two things here one I'm
strumming out something I'm also playing some beats But If you observe they happen together they are not something like you know [Plays
out of sync] or one after the other right so if the programmer specifies that at time
instant t this beat must be played from one say code snippet and this chord should be
played from the other code snippet. Chu
ck guarantees that this is exactly what
happens so that is the key idea how concurrency in Chuck is designed right it's strongly timed
and that's what we'll be looking into so anyway, I don't know if you recognized the song but
[Audience mentions a song] "Wake me up" (by Avicii) yes exactly! so let's move on to essence of music that's
done so what I'll do is uh okay let me just get into say writing some code okay I mean
just code up some music I'll explain music first for the for the uninitiated
and then
let's move ahead with the ideas right so there are a lot of points here you have unit generators
data flow granularity basic timing concurrency what samples are I'll explain these in a very
simple scenario uh we'll be coding Airtel music right let's go forward with that so
okay before moving ahead uh let me just explain what uh this frequency map is right you need
some of these ideas you just do some basic coding in this right um so let's see you have
the you have the guitar right you
have there's something known as frets let's call this fret
one two three right these partitions here right one two three four five six and so on
now each of these strings you have six strings one two three four five and six now if I say
play the first fret, the first string on the first fret right what do I get this is the
first string think of it as a matrix right and you play something like here I think so
right could you play something like this right so that's exactly what this map is but fr
om
a physics perspective uh each of those nodes have a frequency and it's it's set in stone
right uh for example if you go on to um the first string and the fourth fret that is the
G sharp note I will get your details of theory but the frequency of that node is 415 Hertz
right so if I have to play something like this [Airtel Music] so if I'm playing this I played a combination
of notes across the fretboard right so if I have to play the first few notes right so
I'm just playing the same note thr
ee times right three or four times and this is at the
second string third fret right what is that note there second string third fret is D at
294 Hertz I just want you to keep remembering two notes for the sake of it then I play something
like the second note the second different node that I'm playing is on the one two three
four five fifth right and the fourth string right which is of the A note of 440 Hertz
so let's keep these two frequencies in mind for now and let's try to code up something
okay so so what Chuck does is I can so what I want
to do now is simulate a guitar simulate the tone of a guitar right so that that can be
done using you know um say something like I'll tell you what this is so think of this as what StifKarp is it's a guitar tone synthesis
algorithm developed in 1950 or sixties by two scientists (named) Karplus and Strong;
they use Digital Signal processing techniques to synthesize a guitar tone exactly how it
would sound right every musical instrument has a diff
erent tone you would need different
signals to reproduce it so these two are scientists kind of have they generate guitar tune using
this algorithm you we obviously assume it as a black box but the point is it's stored
it into this variable called guitar right we this actually unit generators think of
these as black boxes right so the guitar generator generates a sine wave like which is of the
tone which is which will sound exactly like the guitar right and then I pass it on to
a digital to anal
og converter right so these sampled sine wave signals are eventually converted
into the real world analog current and because how you hear the sound I would say so this
is the basic block now obviously you can do a lot of things with this I'll come to that
in a second but for now just keep in mind this guitar is exactly the tone of the guitar
that you have using the Karplus Strong algorithm now what would I do is I can do stuff like
um say guitar.frequency right I can say what is the first frequ
ency that
we wanted 294 Hertz right that is what I wanted right and then I would say something like
um I can say noteOn right so this just executes the code it kind
of tells you that hey I have the guitar signal it should end now I want the signal to be
of this particular frequency to 94 Hertz at the first node of the guitar music and I want
it to be played for the entire duration now what is the duration let me just tell you
right now there is something very cool here by the way you may have ob
served this "=>" operator
here is right you can think of it as an assignment operator but it is actually being overloaded
you can do a cool lot of cool things with it which kind of makes this language very
expressive for example I just what did I do here I just kind of connected the guitar to
an like a kind of gate uh sound production Pipeline with it at the same time I just assigned
a variable to some to some value right some value to the variable so you can do a lot
of things with this operato
r now I'll do another cool thing with this operator which is I would
say now this is the cool thing here this is the
essence of what Chuck is right you have the ability to control time. Time is a first-class object of this language
by first-class object means I can actually take time and manipulate it and do whatever
the hell I want (to do with it) for example this "now" is a global variable okay even
if you have multiple instruments or multiple threads going on the same time there's a global
cl
ock or global time which is being kept track by this variable called "now" so what this
is telling me update "now" viz. the present by 0.5 seconds or essentially
the same whatever you wrote before this execute that or process the audio for 0.5 seconds
so there are two things here one is executing the code the second you're producing the audio
right so let's see how this sounds let me just run this out so this is open day 23.ck dot cks is the extension I just executed this and it executed the cod
e
for like 0.5 seconds right now you can make it uh you know I can make it more cool in
the sense that I can just add some more features to it say I wanted to sustain for like 0.2 seconds
and not a long time or something it reduces the duration of the note it sustains it isn't
sustained as much as it should now anyway so you got an idea this is the first note
that I just played now if I had to play Airtel how many times which should I play this okay
four times or something so let me just copy pa
ste this right it's a very crude way of
programming but it gives the point across which is why I'm going through this now for
example if you go into um now copy paste this four times right execute
process audio execute process audio and so on now what will be output of this but it
still doesn't sound like the exact tone right because the first note and the second and
third mode have different timings and a different time durations like for example if I make
the second note they are going to play
for just 0.25 seconds [Music] This sounds better right? So you can so a lot of things with this. We can control code at different levels of
granularity. Now, which was the next note I wanted? 440Hertz? So let me see how this sounds. [Music] Cool? So, now I can execute this in a loop by using
"while". Now the thing is, anyway I have the code for
this. let me just bring in one more point across. So here I have some parameters. Prof: "now" is a special variable? Is the name important? Yes, that is
important; it's a designated
variable which is present globally in the virtual machine and in each thread (i.e.,)
they have a global virtual machine version of "now" and thread-local versions of "now"
that doesn't differ by much (in terms of time elapsed) yeah Prof: So the name is important? the name is important yes Prof: One more question, much of this you
can actually get from the notation that one puts, so can't one have a higher level language? yes, there are many languages which kind of
a
bstract out a lot of details and which is why I said I prefer that in the sense I don't
want to go into this level of granularity right but the point is that Chuck offers a
lot of flexibility; somebody actually took a table added some sensors and they did something
you touch it and you get music out of it and they use Chuck to program it at that level
of granularity so you can do a lot of cool things with it right um so it's not very traditional
in that sense uh it just gives you a lot of contro
l that's the point I'm trying to make
and that's exactly what I'm showing you here right I'm just manipulating every small thing
(parameter) here anyway um now yeah so what I'm going to do here is uh so
just this one thing I want to talk about here is this uh this thing here what I did now
is take the guitar signal pass it through a low pass filter, add some Reverb. Reverb is the sound that you have right that
means every room is a different kind of reverb it gives you a different sound on it ri
ght
and then you pass it through digital to analog converter now let's see how this sounds... [Music plays] nice it sounds better right I kind of processed
the audience it's as good as saying that you know if I just press a button on this one
right so here I was playing a clean patch right so if I just suppose play something
like this is a clean patch and if I just press a button here you have an analog... you have
a proper analog processor inside which kind of you know changes it to a distortio
n [Plays
intro to DragonballZ :) ] so you have that's essentially what you're
doing here I mean even for a guitarist you have a pedal board which kind of you know
you take the signal and you connect a lot of things together to get different sounds
right but you here you're doing that at additional level not at an analog level right anyway
so let me just uh show you the final outcome right I have the code ready so what I would
do is take this entire thing put it into a loop add all the notes and
uh let's see how
it sounds so what I would what I'm doing here as you
see can you see? uh I'm doing "chuck add " uh whatever note
I want right now I'll show you some on-the-fly programming it's like I have a few Snippets
(of code) one code say "airtel01.ck" which kind of has the guitar part "airtel02.ck"
that has some beats "airtel03.ck" that has some snares and let's see how that sounds
I just keep adding that one layer at a time and let's see how that sounds so okay [Music]
so this is the firs
t part right [Music: Adds Beats]
now you have the bass, the kick drum, I'm adding ... [Music: Adds Hihats]
Can you hear it? You have the snares (correction: hi-hats)
[Music: Adds more Hihats] The hi-hats. That's what this is. There are two hi-hats. [Music: Adds snare]
This is the snare [Stops music] So that sounded cool. ,
Prof: So for concurrency, you are starting this at various times. I'm coming to that! Prof: So "now" is the one that ensures this? No no it doesn't right so now that is someth
ing
I've hidden which I'm going to come towards now now I'm going to remove one line from
each part in the thread and I'll show you how messy it sounds okay and I'll show why
that is needed because each run each thread each code runs at different times I'm just
starting it arbitrarily right now what I'll do now is let me just remove this specific
line here right so this is the line I'm going to remove similarly from "airtel02.ck" right
which is the kick drum right I'll just remove these two line
s and now if you just try the
same process again for just these two programs right [Music] ok so this sounds fine. no dependencies. Let me add the second thread which (also)
does not have any timing (synchronization) [Music]
Is it off? Audience: Yes. It is off right. So these two threads are not synchronized. so what happened is what is this magic thing
over here? what happens here is so you have two types
the types in the programming language (Chuck) is one is "time", second is "duration" right
so what I'm doing here is you have the duration... you specify the duration as 0.5 seconds now
every every thread every code has a (local) version of "now" (variable) like it's synchronized
to the global version of "now" so "now" is the global time that you have, what this essentially
tells you um you can work it out if you want but if I have a Time duration of 0.5 seconds
and this time duration keeps going right 0.5 1 1.5 to 2 and if I start any code right any
new code some point in between it
(Chuck Virtual Machine) will not start it right away it will
wait until the duration 0.5 seconds is completed and then it will start that's essentially
what it does you can just work it out if you have 0.5 suppose 0.5 is the value of T and
you start it (a program) at 0.2 right 0.2 mod 0.5 is 0.2
and 0.5 - 0.2 = 0.3, so it (program) would wait (due to the VM) for the remaining
0.3 seconds and then it would start and this is the key thing that kind of ensures concurrency
and synchronization acros
s all the threads. now I think I got an idea by now about how
these things work. Prof: So the "T" is common to all the threads? no T is a local variable but you are yeah
you're waiting for "now". "now" is the one that is common to all right
so that is the key idea here as to why this is synchronous right yeah Prof: ultimately though it is sequential in
the hardware and eventually in the signals that go but what's that small amount, we won't
be able to distinguish that? so so it's like okay so yo
u have the notion
of time (as a type in Chuck) right the smallest unit if you try to divide this time finally
right the smallest unit is a sample (as a type in Chuck). Chuck ensures concurrency at the sample level. For example, at the first sample whatever
second it may be right assume you have three threads and as I mentioned as the programmer
mentions that hey at this point in time T1 thread i,e. the program one should play something
program should two should play something program three shoul
d play something the scheduler
I mean the scheduler kind of waits for the data from all of them once it only gets that
it kind of moves ahead and plays the music and that is the key thing like okay if you
have a lot of (CPU) processing and audio processing it would be very slow it can be but Chuck's
guarantee is that you play that on time right fine if it's slow it's fine if it's not real-time
but the guarantee that it gives you is that it's sample-synchronous; that's the idea here
now Prof: So
I guess the question was that you
can produce sounds only sequentially right? I mean maybe there's only one speaker and
you can give it, at one instant you can play one tone or one frequency, so if you have
two threads, then no but then one then one tone right what did
I do? I played it for 0.5 seconds right and then
0.5 seconds was (internally) divided into samples and if you have multiple threads they
have this queue where you wait for each of those threads to reach that particular point
in ti
me and then you collect the data and then you play them together. that's essentially ... Prof: So you can play them together? yeah if you have multiple threads and you
program it in this way, that is I want it to be played together right that's what you're
doing here right then it will do it but if you don't it won't so that's the kind of granularity
that you have with Chuck yeah Student: so why do you pass it through a low
pass filter here? Like so the low pass filter just only allows
the low f
requencies right? So I don't hear any differences in the frequencies
when you play it before and when you pass it through a low pass filter To be very honest, I don't remember why I
did that because I did this many years back and I honestly can't remember that Student: so even if I put in a high pass filter
band pass filter it won't make a difference? I should try that out but you have those options
sorry I really don't know so yeah everybody got the gist of this right so okay so I think
uh you
got an idea of this fine um so this is what some people kind of has "on-the-fly"
like programming where uh what I just showed you everything was already coded up right,
(in this case,) people actually write code dynamically while existing code is being run
and keep pushing pieces of code and then Chuck has the capability to kind of you know keep
playing them, collect them and play. So there's another interesting thing you know
the Tower of Hanoi problem. So if you are aware of it, we start of wi
th
a descending sequence and you want to shift it from (stack) a to (stack) c right and I
don't want to get into the algorithm of that (TOH) but have you ever wondered how it sounds
like? so let's see how TOH sounds like so it's just
something again very different right so you have the code for that so so this is the Tower of Hanoi code I mean
I won't get into details which kind of takes n-1 uh stacks and uses uh uh uh you know whatever
the tower to kind of shift from tower (stack) a to tower b
using tower c and so on right but this is the code here
but if I run this code without any music it just takes peg one it just tells you it takes
peg one place it until something else (another peg) and so on but let me just play something so if in "hanoi++.ck" right here you've added
some If you observe in between the code you have a lot of things going on some Kick Drum
and uh a lot of music has been infused into the code so let's see as you keep, take a
disc from one stack to another, le's see
how this sounds like right. um okay [TOH Music plays] I mean you can see here that you're moving
this disc from peg one to two and all and in between some sounds are inerleaved and
it sounds so cool right... because Chuck is a programming language uh you can actually
use it to solve algorithms and maybe just do something more with that, I don't know
why you would do it (add music in between algorithms) but let's do it so so I think you got an idea about this programming
language in a different
way right I mean so okay let's get into I don't know how much
time I have but let's see I'll quickly try to run you through so we have understood some
Concepts right we understood what is actually happening in the background I think most of
you got a fair idea of this sample synchronous and concurrent nature that Chuck has so (I'll)
quickly try to go through an idea of quickly into a language perspective if you're not
so if you're a designer of a programming language you're essentially asking ho
w do I create
a compiler or interpreter for certain requirements like you may ask should my language be statically
typed or dynamically typed you would say oh is the user coming from a C++ background or
a Python background accordingly you will design the syntax and there are a lot of design considerations
that you're making right uh In a nutshell, in a very dumbed down way,
a compiler I think we all know it takes a high level language such as C or C++, compiles
it into machine code and then it's
executed on the CPU right? If you have a source code such as python it
is I mean python is compiled now and then interpreted, but let's assume a pure version
of python where you know you are interpreting the code line by line and executing it right
you're not compiling it into some machine code but you're interpreting it on the fly
so that's essentially an idea about what a compiler and interpreter I think most of you
will be aware of that so how Chuck looks like it's more close to Java and C++
than C or
Python; I don't have time for all this but shred is something when you just I don't know
if you're aware on the guitar if you should just play something very fast (it's called
a shred) and I don't know for what reason but they just call a thread a shred okay just
keep that in mind and if you are not from a computer science background if it helps
think of a thread as just another piece of code running in parallel right like how we
did we have a guitar running in parallel, a bass drum r
unning parallel and that is a
thread it's a shred let's call it a shred um similarly yes a scheduler is called a schreduler, and forking
a thread is called sporking and okay let's keep all this let's stick to their
terminology so ... it's (Spork) a useless piece of cutlery... okay coming back to some serious stuff so
features of Chuck as we just saw is it is strongly timed; time is a first-class object,
we just manipulated time as we just saw right. It's sample-synchronous for every sample you
h
ave we ensure the synchronous uh the nature that we ensure synchronicity at the level
of samples, it's strongly typed i.e., arbitrary type conversion is not allowed. I know I'm going a bit technical here for
all those from non-CS backgrounds please bear with me for some time uh and you have object-oriented
features as well. um I thought I should show you this as well
um anyway (due to lack of time) I'll do a last performance; now, I'm not playing anything
more uh Prof: let's do that sure let me
just go ahead and so this is "Canon
in D" , so have you heard Canon? sorry it's a different filter. so here if you observe you'll see two things
going on in parallel right and it's up to you to tell me what those two things are so
let's see [Music] [Music] [Music] [Music] Could you hear two things? I mean it's a fingerpicking style of playing
(the guitar) but what's essentially happening is that with my thumb I am playing [Music] I'm playing the bass, it's a bass guitar viz. a different instrume
nt right? and here I am doing something like (arpeggios),
so you have two things going on in parallel (bass + arpeggios). So you can actually use this to I mean if
you look at the code, I think yes, I should show you the code because it wouldn't be complete
without it. If we look at the code for ... Canon, you have a lot of things I mean I think this
is the right way to write code what I did was just a very "noob" (novice) level you
have so if you look at the uh you have a lot of things going on
here here if you see you
have connected a lot of things, you have "chucked" into the unit generator that I called right
you generate signals you process them in different ways it's called a Unit generation graph right
the key the bass guitar is passed into some okay I don't know what this is there are a
lot of things options that you have to do programming here but the point I want to note
is at some point here "while true" the program keeps on running you're doing this "spork"
right "playMelod
y()" (function) you're forking out a new uh program right and what "playMelody()"
already does it plays a different uh "playMelody()" plays a different predefined melody in different
way "playbass()" (function) plays the bass guitar right so let's play this and see how
it sounds right so um so we have um just a second so I'll actually add all of these different
pieces together at once what happened [Music] how many how many threads can you
observe here? how many three or two? three right? [Music
] you have violin playing, you have
a bass guitar playing and I have a keyboard playing
so three things are going on in parallel right? [Music] So this is how you can use to spawn
program and do a lot of things. I have not written this code, I have gotten
this from the net. okay so I think you got a fair picture of
how this is done now let's go into more quickly into the language design part because I think
it (the talk) would be incomplete without it so what you do here is you have major langua
ge
design goals the major languages and goals for Chuck is to specify both high and low
level operations in time right I mean we just specified using time move time by some seconds
right you could actually go at the level of samples and play around with it right it's
a basic unit of time uh you can write parallel models as you just saw, and programs are verified
as they run and there is strong correspondence between code structure and time. I think we just saw that (practically). I think the mai
n thing is time and duration
are the basic types in Chuck right and before 0.5 seconds it's time right it refers to the
absolute point in time starting when you start the virtual machine I'll come to what a virtual
machine is in a second actually I've not shown you but I'm adding one one thread right that
is already a virtual machine running in the background a program that takes each of those
threads and runs it and manages a lot of these things a lot of these complexities that has
been abstrac
ted out so here you have time that represents an absolute point in time
duration represents you know some seconds as you just saw you could add durations to
some time and play around with them and add that to now for example so so this I think
we just saw that "now" is a special variable of type time it holds the current Chuck time
at the time of read as I think you asked um the side effect of modifying "now" I think
this is a key concept as I mentioned the moment you say you're modifying "now"
the thread
is suspended the VM is saying hey you (thread) go to sleep let me now process audio right
and the thread awaits until the audio is completed and only then the thread is restarted again
so that is the side effect of that for example in this example when I say one second is mapped
to "now" the thread goes to sleep for one second and audio is being run that's what
essentially is happening Prof: Is it "for" one second or until now
becomes one second? yeah until yeah I mean actually until
the
value of now becomes one second Prof: But that's not the same as "for" one
second? but that's exactly what happens I mean in
the sense that you're saying that you play that for one second but so "now" gets updated
like you you pause the Prof: If it's already 5 and I say six that's
only one more second? yeah one more second right Prof: But if "now" is already 5 If "now" is already 5, then the thread goes
to sleep at 5, and then at the time when it (global time) reaches 6 then now becomes six
that's plus one Prof: then there will be only one second yeah just one second exactly um anyway so I think we got this idea where you
know the concurrency is sample-synchronous and non-preemptive; threads cannot preempt
each other that is a key design decision obviously right if not, then your music could be spoiled
so similarly it's deterministic that's the key thing in this concurrency model which
if you are coming from java background or some other object-oriented background you
would realize
that there threads can interleave in arbitrary ways. that's something which is strictly not allowed
if you're designing a programming language for the domain of music so that's a key design
decision right it has to be made similarly those threads that are created they don't
really need to know each other they just have to deal with the time locally they have "now"
the variable "now" and they kind of synchronize with respect to that that's the key thing
there and the virtual machine ensures that
the synchronization is taken care of now you
I'll come to that the diagram here right this is the key uh this is how Chuck looks like
for example here you have something like so all the code that I've written they are entered
from here I mean "Audicle" is a software from where you can write Chuck programs. But If You observe here you have a runtime
compiler and a type checker which kind of converts this into an uh or into the byte
code the intermediate representation and you can see each of tho
se new shreds that are
created are kind of passed into this scheduler right the scheduler that you have now this
schreduler is this I'm going to call it scheduler sorry uh the scheduler works with the bytecode
Interpreter right it kind of looks at these uh these uh threads/scheds/shreds and kind
of executes them line by line right as you saw and at the point where you say you've
modified time the audio engine comes into the picture and kind of looks into this Global
UGen graph you remember this
do you remember the graph? you know the DAC do you remember the guitar
I passed it/ plugged it into the low pass filter into the Reverb and into the DAC that's
essentially what this is guitar it is a big graph you can you can manipulate samples across
this graph to get the final outcome over here to produce a sound right .in a very simple
(abstracted) language, right you can and that's essentially what's happening here so this
is the entire model of how Chuck works and I think should I get into
a lot of details? I mean Chuck programs are, as I said, are
type checked, compiled into bytecode instructions, emitted into the VM, interpreted by the VM,
and the schreduler it kind of realizes the order of execution between each of those threads um you can read about this but we what we're
doing is you're actually connecting to a unit generator whenever I define a unit generator,
shreds can directly connect, disconnect and kind of change the state of the generator
with time but these are a lot
of technical details I would advise you can actually go
to the paper and read more about them right um anyway I think I don't know if I should
go into this but it is strongly typed as I said but not statically typed, Strongly typed
means arbitrary type conversions are not allowed and here you can you know you don't need the
variable to be defined always um declared always. I don't know why they made those decisions
though supposedly it helps precision and clarity in the code right like if you ob
serve the
dynamic nature of this entire virtual machine we could actually add threads dynamically
and then it somehow magically as we saw right ensures that it is synchronous that's how
dynamic this (the language) is. You have primitive reference types the compiler:
lexical syntax and type checking and you have generation of intermediate code that is this
byte code that you have the shreds and the compiler runs in the same address space as
the virtual machine this I will not get into too much de
tail but the point to note is that
every thread has a local view of the "now" variable right which is not very far ... it's
just a fractional sample away from the system wide global value of "now" right you are being
in sync with the time right. now the VM serializes the execution of a shred,
maintains a system wide value of now uh this is essentially what I was showing you right
in the sense that if you execute the code and at some point you suspend it when you
suspend it? when you have "now" w
hen you're updating "now",
you suspend it then is it the time to wake up the thread and it has 0.5 seconds elapsed? no then you would just traverse and get more
samples out and keep playing it and you repeat it and then once it's time to continue the
remaining part of the code you continue that so that's how this entire thing works right
and as I mentioned the only cause of delay is if you have a lot of computation to kind
of process the audio or the thread does not actuallly advance time that's
when you're
delayed but it gives you a guarantee that you know no compromise on synchronization
once I get all the data from all the threads for a given point in time only then it will
produce the audio right again this is too much of information you can check out the
paper again the passage of time is data driven that's the point to be noted as I keep getting
more data and that's how I'll process the audio and the final synthesis is correct and
sample faithful regardless of whether the system
is running in real time or not I think
these are the key takeaways of this even this you can check out in the paper where it kind
of uses DFS to travel through the graph this is not necessary at this point As you observe,
it's similar to Java and C++ in the sense that you have a virtual machine or internal
virtual machine that takes care of these byte codes. But the notion, the key takeaway was that
the notion of concurrency is very difficult in this setting you can read papers for Chuck
and you
can just play around with this if you have an idea that's it so I hope you have
got some key takeaway from this talk right you must have observed that it is different
to design a programming language if you want to pick the domain as music right there are
a lot of constraints here concurrency and time especially which is very different from
designing other languages so I hope that if you go back home you learn a new language
instead of just learning the syntax I hope you just take out some time
to understand
why these languages are designed in the first place right and I think that's I mean here
I think the professors would agree that they will not they will say "Java you can just
learn it in a day! Don't waste time!" that's how we entered when we entered IISc
we were like but we need time to learn, we need 1-2 weeks to learn Java. (Prof) "no I'm sorry you can learn that in
a day that's not the point of coming into CSA and doing an M Tech right" so anyway so
I think that's the end of
the talk so I'll just perform something for you guys before
leaving and um okay that's it thank you! so this is one of my uh favorite pieces that I like to play I don't
know if, maybe some of you may have heard it but [Tuning the guitar, setting up. Please be patient. Should be worth it :) ] can you hear me? sorry I just had to change the tuning a bit
so now we are gonna start so [Music. A bit out of practice. Or maybe tired. Gets better towards the end. :) ] [Music: Drifting by Andy Mckee, sure
ly not
doing justice to his song. So please listen to him separately as well.] [Music] [Applause] [Music] thank yo [Music] [Music] [Music] [Music] So you may think is this is even connected
to the talk or not but (if you observed), I had three threads running parallel! :) So let me just tell you what those three
threads are! Prof: Shreds! yes Shreds! So you have one is the bass which is going
on in parallel, so you have something like [Plays Bass part of the music] It's off tune I'm sorry I don'
t know how that
happened [Music] right you have the bass going on you have the tap that is the percussion
if you play both together [Music] right and you have my right hand is essentially doing
this [Music] (playing an arpeggio) you will normally play this separately right if I combine
all of them together and what do I get is Thank you! [Applause]
Comments