all right hello I'm back in this video
I'm to another video about the recomment
in the previous video what I did was
visualize it and you can see here this
is me vision this is not me but this is
the p5 code I wrote to visualize the
recommend number sequence as a
continuous series of arcs looks like
they're circles but they're actually
connected arcs you can watch the
previous video where I go and build this
whole code but one of the things that
people that you can do also with number
sequences besides visualize them is
create an audio version of them and in
fact if you go back to mine your
favorite website entirely in the entire
world the online encyclopedia of integer
sequences you know if I'm here on the
recommendation and it will give me a
MIDI file MIDI being a system for
encoding music as numbers so if I can
encode music as numbers and I have a
number sequence then I can make that
number sequence MIDI and then I can play
it as music so this is what I want to
try to do and I'm going to attempt to do
it with the p5.js
sound library making use probably and
this I don't really know that well so
we're doing a lot of looking up in the
reference while I do this learn to do it
with it oscillator to generate a sound
and the envelope an envelope to kind of
craft that sound essentially creating my
own synthesizer should also mention that
um this video was pointed out to me from
Dale Gert Amon
which is also visualizing the sequence
and a completely different wedding with
colors and also making it into audio so
I hope after watching both of these we
will see a world full of I mean I don't
know do we want this world I think why
not let's see a world full of
visualizations and audio versions of
numeric sequences okay so let's start
coding again I'm gonna close these
windows I'm gonna go here and let's
think about this so do I want to I'm
gonna keep the visualization going and
basically so I could start from
scrimmage us keep this code I'm gonna
add to it and what I want to do is I
want to play a note so let's see if I
how to best to do this so the first
thing that I know that I need to do is I
need to create an oscillator an
oscillator is an object that will
generate a tone and there are different
kinds of oscillators right I it's
basically a pure sound wave and I can
have a sine wave or a triangle wave and
I believe I have a video about p5
oscillators that will go into that
perhaps a bit more but I thought what
I'm gonna do is I'm just gonna take this
code exactly as is and I'm gonna paste
it in to set up your coding challenge
copy paste from examples and then I'm
going to create make that a global
variable and I'm going to discover what
interesting error I will have now so p5
oscillator is not a constructor why do I
have why did this come up why do I have
this because I don't actually use the
sound library that often and I didn't
include it here I should use it more
often so I'm going to go and add
reference in my HTML file to the p5
sound library so hopefully that's going
to clear that error up great it's going
do I hear anything mm-hmm
so let's go to the sketch and why do I
not hear anything because I set the
amplitudes to zero let's set the
amplitude to 1 and which is 100% volume
I'm hit refresh
so now you hear the sine-wave now so
what's what do I want to do here so I
have this I don't really click back here
to stop the sound for a second I have
this number sequence that's going up we
can look at those numbers there 0 1 3 6
2 7 13 20 so what if I just took each
number and assigned it and took the
number in the sequence and made it a
frequency so for example as I'm stepping
through I could say oscillator frequency
index right index is actually the number
of that that's currently part of the
sequence so if I do this and go back to
here and click on this I don't hear
anything
do you hear something you might have to
have headphones have it turned up
eventually I think I'm gonna start
hearing something so here's the thing
there is a range of frequencies
frequency as being a measurement of how
many cycles of a wave per second we can
start to hear it like that okay so for a
while we didn't hear any notes and then
also we started to hear something so
here's I think it's much too arbitrary
to just setting the number from zero to
whatever as the frequency there is a
specific audible range or frequencies
that we can hear and so and there also
are formulas for converting from MIDI
notes to frequency and back and forth
I'm sorry about this applause there's
nothing to do with me clearly there's
nothing going on in the hallway there's
nothing I could do about it right now so
it's gonna be in this video forever but
umm and so I pretty sure that p5 has a
like MIDI - frequency or - note or
something function somewhere but I'm
actually I'm not gonna use that I'm
gonna go to this Wikipedia page which I
have loaded up here called piano key
frequencies and if you look at this this
formula here I want to use this
basically if we number all the keys on
the piano from the very bottom key to
the top key I can't remember how many
keys are on a piano 88 keys standard 108
key extended we can actually find the
frequency of any key N through this
formula sure we could think about this
in interesting ways but I'm just gonna
go and use this formula so look at this
I'm going to say
if the if the recommen knows all these
numbers and I'm just gonna do from zero
to 88 like I'm not gonna let it go
forever if I consider each one needs to
be a key on the piano then we should be
able to play the music so really this is
very distracting
all right okay so I want to say the the
frequency is and go back to this formula
two to the N minus 49 okay so power -
and of what n which is index - 49
divided by divided by 12 times and I
believe it was 440 it's for 440 I wonder
for 40 is like middle C or the note a I
think it's the tune to a 440 so a is
like the 440 is a Hertz is the is the
note a so so now if I were to say this
and let's console.log index and the
frequency just to hear it and I also
want to just go to set up and I'm gonna
if I already had set the frame rate down
to five and anticipation of this but I'm
actually set it to one make it even
slower all right let's take a listen
do you guys hear those very low notes
[Music]
use index mod 88 that makes sense all
right so I can't seem to get those
really low notes to play let's increase
the frame rate so first of all I would
need to add an envelope to this the
whole point of this I wanted to sound
somewhat nice so what is an envelope so
in addition to the oscillator there is
this thing called an envelope and
envelope has four elements to it they're
actually described right here and I have
a video all about this which is attack
decay sustain release so you think about
playing a note like when you hit a note
on the piano there's the sort of attack
there's the notes for fading out there's
the sustain there's the release all
those those four things various
parameters I'm just gonna kind of use a
default setting and I'm gonna go to this
example P v dot envelope and this sort
of look so let's let's grab thank you
well that's crab putting because I have
fake applause sound effect and then
there's people applauding answer so I'm
gonna grab all of this stuff these
settings for that envelope I am going to
create an envelope right here and then
I'm going to make the envelope sorry
before I make the oscillator so I
basically want to use the envelope in
cents as a wrapper around the oscillator
the oscillator is going to give me the
quality of the sound and the frequency
is what kind of wave it is and the
envelope is gonna allow me to make it
feel like I'm almost playing a key on a
synthesizer
and so now if we go and look here we can
see envelope play so now so the
amplitude gets tied to the envelope so
instead of saying amplitude of one I'm
gonna say awesome amplitude envelope and
then I'm just going to say envelope dot
play let's try this
and I need to start any frequency on
envelope top play okay so then I want to
then I want to also comment this out
right now
and just we should just hear one note
you hear that so what I'm going to do
now is I should be able to then say I
should be able to set the frequency and
play the envelope again so here I'm
gonna set the frequency and I'm going to
play the envelope again I am going to
not set the frequency here or play the
envelope here and let's see what we get
these okay that is loud I don't know if
I just totally destroyed your ears one
thing that I can do here that would be
kind of nice would be to make this
actually index mod 88 so that if the
index goes higher than the last key on
the keyboard it will then wrap back down
to the bottom one and I almost feel like
what I want to do is use a smaller range
but let's try this I'm gonna turn the
volume down a little bit how's the
volume
[Music]
I'm terrible at doing stepid-- music and
sounds hold on this video is not over
yet
getting a suggestion from the chat from
K week mom saying you will get more
musical results by restricting the range
of it I'd say 2 octaves top so what I
should be doing here is basically two
octaves right would be how many notes
total 24 C C sharp D d sharp e F f-sharp
G g-sharp a a sharp B that's 12 then I
have C so that's 12 notes total so if I
so I want like range of two octaves
would be 24 notes and maybe I would
allow the last note so I would have 25
notes so I would maybe I want to say
something like the the N is index + I
don't know I should start up somewhere
like plus 48 modulus 25 is that like
crazy Oh 14 + - 49 that's interesting
okay
so is this does this make any sense at
all
[Music]
let's try a little bit higher like 24 48
96 what because I'm I'm module no no no
no I have to modulus the 25 plus 48 this
better so anyway now you see that I a
have no in addition having no visual
talent I also have no musical talent I
don't know that much about music I know
but I played the violin and I attempt to
play a very out of tune ukulele alright
so this is the end of my video
I've said that so many times share with
me your musical compositions based off
of this number sequence or other number
sequences and ways that you discover and
I look forward to seeing you in future
coding challenges ok goodbye
[Music]