This was a talk I had given in early 2017 that showed off some webaudio APIs and how they can be used to create some interesting visualizations. I also talked about some of the creative coding tools I use to make these things.
Transcripts (auto-generate)
-
00:06all right my name is Jacob I am JCB LW
-
00:10everywhere on the web and that's not bad
-
00:12i don't really care about that social
-
00:14website and also i'm an organizer of
-
00:17jail a because i love the Jazz community
-
00:19today I'm going to be talking about
-
00:22visualizing audio on the web very
-
00:25descriptive title nothing fancy no click
-
00:28bait or anything you know you're getting
-
00:30what you see there I probably can work
-
00:32on that especially when we put up the
-
00:33video you want to make it a little bit
-
00:34more enticing and do something with it
-
00:37but right now it's just visualizing the
-
00:39audio on the web so before we go forward
-
00:43and talk about visualizing audio I kind
-
00:44of want steak a step back I mean I'm
-
00:46getting older I turned 29 this month and
-
00:49you know got here the older the older I
-
00:53get the more I like to look back and be
-
00:54nostalgic about the things that of my
-
00:56path and one thing is you know
-
00:59visualizing audio or visualizing music
-
01:02was like it's something that I really
-
01:03really liked now who remembers this yeah
-
01:07so this is windows media player this was
-
01:10actually my first visualizations that I
-
01:13ever you know fall or probably even
-
01:15dealt with as a young child and is it
-
01:19like when I see this I'm like oh it
-
01:21brings me back to a place where I'm
-
01:23sitting in front of my computer and I'm
-
01:24shoving CDs and my you know CD Drive and
-
01:27like opening up a program is before
-
01:29streaming or anything without now this
-
01:32is a YouTube video and let's see
-
01:34comments like this it really makes me
-
01:35sad because it's like this is no longer
-
01:38going to be available to me to be able
-
01:40to use this even though granted i
-
01:41probably wouldn't use it but there's no
-
01:43there's no chance than we actually using
-
01:45it and it's being a YouTube video of
-
01:47course there is like funny comments okay
-
01:49out of trip balls on your 10 this was
-
01:52kind of funny because like I was
-
01:53probably like 10 when i was using
-
01:57windows media player and actually i
-
01:59think this is a pretty good talk title
-
02:03if you don't mind me i'm gonna change
-
02:06this real quick
-
02:09[Music]
-
02:13there we go I think that's gonna that's
-
02:16gonna get two clicks right there all
-
02:19right going forward all right enough
-
02:23about going in the past let's talk about
-
02:24the present so I don't know if you guys
-
02:27have checked out like modern interfaces
-
02:29for playing audio pretty sure you spot a
-
02:31Phi or iTunes or something and one thing
-
02:34about that is that music visualizations
-
02:36are usually gone from those interfaces
-
02:38it's more or less like these are behind
-
02:41some tab or like they're non-existent or
-
02:45the some static visualization which is
-
02:47like on soundcloud you actually have
-
02:49like these very static visualizations
-
02:52and it's pretty much just a progress bar
-
02:53that you're going through and back to
-
02:56myself I actually just started a new job
-
02:58and it's not this really cool place
-
02:59called headspace the meditation app we
-
03:01actually hosted their last month but one
-
03:04thing that's interesting as this is a
-
03:05progression in my like career is also
-
03:07that my prior places I was working with
-
03:10maps and latitude longitude putting pins
-
03:14on a map and if I ever wanted to do
-
03:17anything with audio is really on my own
-
03:19time and there was no really like
-
03:20practical use for me to do it our main
-
03:23product that headspace is actually audio
-
03:25files so me getting to look into these
-
03:27new Web Audio API is actually beneficial
-
03:29for my job as well which I kind of love
-
03:32that like I'm actually doing something
-
03:33that I wanted you as well as it's kind
-
03:36of like benefiting me a little bit and
-
03:38before like started I was like checking
-
03:40out the product that headspace and they
-
03:42have this really cool player it's very
-
03:44light but you can see that the player is
-
03:46kind of moving a little bit it has like
-
03:47a little bit of animation supposed to
-
03:49just be smooth and like soothing it's
-
03:52not really like it's not doing any audio
-
03:55visualization even though you kind of
-
03:56say it's like a vibe type of
-
03:58visualization or something because it is
-
04:00the meditation app but I thought it was
-
04:02really intriguing like I usually you see
-
04:04audio players and it's just a play
-
04:06button and then a stop button maybe a
-
04:08progress bar but you really don't have
-
04:10much innovation and besides doing that
-
04:13you have you know album art as big as
-
04:15you can get it or something and the
-
04:17first thing that went through my mind
-
04:18which I think probably goes through a
-
04:20lot of our minds
-
04:22time to time is I just want to implement
-
04:24it in JavaScript like why we actually
-
04:26have a web player at head space but it
-
04:29looks nothing like that cool one that I
-
04:31was talking about that was like our
-
04:32mobile player and that was actually a
-
04:34youtube video that I was showing that so
-
04:37before I started I actually took off a
-
04:40month and I rode my skateboard around
-
04:42New York and DC but during that time
-
04:44actually stopped in a bunch of coffee
-
04:46shops and I would just hack on stuff and
-
04:48it was mostly trying to implement this
-
04:50thing in JavaScript now the next slide
-
04:54that i'm going to show you is my first
-
04:55try or not first try it's the first step
-
04:58in a progression of trying to implement
-
05:01this player now when you look at this
-
05:05and sorry for the blurry quality but
-
05:06this looks nothing like that player at
-
05:10all so let me kind of like go through my
-
05:14thought process of this so the player is
-
05:16kind of like this random blob and
-
05:18there's like pieces of it moving in a
-
05:20certain direction so what I did was like
-
05:22I want to pick make a bunch of points
-
05:24and put them around a circle and then
-
05:25move them in a random direction and
-
05:27that's what this is except I'm really
-
05:29bad at math so as you can see it's not a
-
05:32circle it actually came out something
-
05:34that's more like a sideways donut I
-
05:37thought it was really cool and like when
-
05:39I built something really cool i liked
-
05:40like at least take a screenshot or put
-
05:43it on twitter or something so that's
-
05:46what i did with this mess just a
-
05:48progression in it as you can see i got
-
05:50better at math there's another
-
05:52visualization why didn't get better i
-
05:54just like figured out what my problem
-
05:55was and fix it and yeah so this is just
-
06:00like a i'm changing the colors around as
-
06:02you can see it's a little bit more
-
06:03coherence getting a little bit closer
-
06:04still doesn't look anything like it and
-
06:06what you'll see in some of my demos as
-
06:08well as just some of the other slides is
-
06:10I like to like I make things very
-
06:12declarative so I can just like take
-
06:14these like numbers and just twist them
-
06:16and like turn them to 11 and then
-
06:18probably turn it back to nine because my
-
06:19computer is lagging too much and that's
-
06:21what you'll see in a lot of these demos
-
06:23is me just kind of like messing around
-
06:25with numbers and I also have another
-
06:29step in here but the thing is is that I
-
06:31did a lot of this without source control
-
06:34and I really wish that I
-
06:36I used sorts of control the entire time
-
06:37because then I can show you a better
-
06:38progression of this because the last
-
06:41slide to this next slide is way
-
06:44different so more or less like there's a
-
06:47big gap in this entire history of this
-
06:50Wiz players came and more or less what I
-
06:54did when I connected those points made
-
06:56quadratic curves between them and made
-
06:58it one solid shape and then I actually
-
07:00started playing audio with it and this
-
07:02next step and fun so this is what it
-
07:07looks like there's a little bit of music
-
07:09here as you can see revision we actually
-
07:11are starting to visualize audio in this
-
07:13and francha this is nothing is not very
-
07:17calm if you look at it this would not be
-
07:20soothing to be inside of a meditation
-
07:22else but more or less this was just me
-
07:25taking that knob and dialing it to 11
-
07:27and so this is like a very simple
-
07:29visualization so I'm taking those random
-
07:32points and usually looks like a small
-
07:34threshold and that's kind of like at a
-
07:35rest 8 and when the one there's like a
-
07:38snare head or a beat drop or something
-
07:41the frequency goes up and you're able to
-
07:43have a larger variation and that's where
-
07:45you feel like the little spikes because
-
07:47it goes in and it goes out now have
-
07:49another one go and turn it back on this
-
07:53one is not so much a demo of the player
-
07:55i'm kind of like showing off some of the
-
07:56functionality because I I kind of build
-
07:59this in stats so but as you can see the
-
08:03animation got a little bit more subtle
-
08:05this one's a little bit better you could
-
08:07actually see this probably in kind of
-
08:08like an interface you could say the
-
08:11animation change instead of just doing
-
08:13like the random points and having a
-
08:14bigger threshold to them this one
-
08:16actually the border gets a little bit
-
08:17larger but it's actually what I found
-
08:19interesting at this point is there's a
-
08:22lot of different things you can do with
-
08:24audio visualization that's not so
-
08:26straightforward I mean this is like a
-
08:28subtle animation if you thought about
-
08:30windows media player that I had in the
-
08:31very first slide or second slide it
-
08:33actually that was like a full screen
-
08:35immersion sometimes a little too much I
-
08:38could say where this is a little bit
-
08:40more subtle granted it probably would
-
08:41get annoying after a while and this
-
08:44really sparked my interest and kind of
-
08:46like audio visualization so much so that
-
08:48I actually built
-
08:50npm module it's called sound dashboard
-
08:52it's on NPM and also you can find it on
-
08:55my github will actually post this to the
-
08:56flak channel afterwards so you guys can
-
08:59check it out if you want what this
-
09:00allows me to do is load up like an audio
-
09:02buffer file and then be able to like
-
09:04analyze the data of it when it's like
-
09:06playing and grab that data out really
-
09:08conveniently instead of hooking up these
-
09:11AP is now you you might be thinking like
-
09:15oh that's cool and all but like how are
-
09:17you actually doing this like what is
-
09:19actually going on that maybe somebody
-
09:21else wants to do audio visualization and
-
09:22like what is the steps that I had to
-
09:25take to get to that point so I have a
-
09:28couple little pieces of code and I'll
-
09:30try to walk through this and then i'll
-
09:33answer questions at the end and i'm
-
09:34pretty sure it'll be mostly about these
-
09:36slides but essentially i'm using the
-
09:39audio contacts API it's I want to say
-
09:42it's you but it's been around for a
-
09:44couple years now the the support for it
-
09:48is pretty good there is some methods
-
09:50that are a little bit spotty on in terms
-
09:52of browser support and more or less like
-
09:55my demos only work in chrome and firefox
-
09:57right now but more or less I'm creating
-
10:01the audio context and that's what I'm
-
10:02doing that new audio context I'm
-
10:04creating a buffer source what a buffer
-
10:06source is essentially I can attach like
-
10:08an audio buffer to it and that will
-
10:12allow me to like play and stop the audio
-
10:15buffer and then I'm also creating an
-
10:17analyzer now the analyzer does exactly
-
10:19what it sounds like it's analyzing the
-
10:21data that is going through it in the way
-
10:24that I can pump data through the
-
10:25analyzer is down below as you can see i
-
10:29am adding the audio buffer now that's
-
10:32like a un aid array which is like a
-
10:34array of arrays that's holding like
-
10:36binary data inside of it and i'm
-
10:39connecting it to the analyzer which i
-
10:41think it's spelled one of these wrong
-
10:43but analyzer connect and then i'm
-
10:46connecting the analyzer straight to the
-
10:47destination you can think of this as
-
10:48with speakers of your computer and then
-
10:50i'm just starting it you can add a bunch
-
10:52of params for that to start it at a
-
10:54certain point
-
10:55now to get the data out of the analyzed
-
10:59because I just showed you how to connect
-
11:00the analyzer this is how you would get
-
11:02it out so you get a buffered lang that's
-
11:04pretty much a the audio that it's
-
11:07playing at a certain time because we're
-
11:10going to call this function over and
-
11:11over and over again so whenever you're
-
11:13playing like an audio file and you want
-
11:14to get a certain data out of a certain
-
11:17time when it's playing you can get the
-
11:19length of the actual binary how long it
-
11:22is and then I'm going to create a UN 28
-
11:23array with that length which is going to
-
11:26just create a blank one and then call it
-
11:28calling audio analyzer get byte time
-
11:31domain data I really love that method
-
11:33name but then call it coin it with data
-
11:36array is actually going to hydrate that
-
11:38data array with a bunch of binary data
-
11:40from that current buffer and then as you
-
11:42can see here I'm just using
-
11:43requestanimationframe to call this thing
-
11:45over and over and over again and get out
-
11:46the the data for each sequence and this
-
11:52is what actually creating the
-
11:53visualization looks like now like I said
-
11:55I'm not good at math so I don't know
-
11:57exactly what's going on here granted
-
11:58there's only a little bit of code but
-
12:00more or less what's happening is we're
-
12:02we're calculating a waveform and we're
-
12:05just getting x and y coordinates for it
-
12:07that's what these are and then you can
-
12:10take those x and y coordinates and you
-
12:11can put absolute this gives or more
-
12:14likely you probably want to render those
-
12:15to a canvas and then you would have like
-
12:17an actual waveform if you just rendered
-
12:20those that's like circles on a canvas
-
12:21which is really cool because it's like
-
12:23that's not that much code to be able to
-
12:25render out a waveform and if you want to
-
12:29look at more there's actually a good mdn
-
12:31doc that i have in like some of my
-
12:33github repos that is the place where i
-
12:36actually learned how to do a lot of this
-
12:37stuff because they have a doc on how to
-
12:39analyze audio data on the web and that's
-
12:43where a lot of this code came from now
-
12:45as a few demos the first one I have here
-
12:48I was just playing around with stuff
-
12:50cranking the knobs on things and this is
-
12:54like a very sporadic like it's exactly
-
12:56like a small snippet of like an
-
12:58animation that you'll see later on but
-
13:02more or less like I call this one that
-
13:03event horizon I just thought it was cool
-
13:06yeah it's a very chaotic
-
13:08and then now I have another demo and
-
13:13this is actually turn this is actually
-
13:19the blob player that I was showing you i
-
13:22just have it down here kind of as a
-
13:23player it's not I mean the whole
-
13:26interface that doesn't revolve around
-
13:28this audio visualization exactly there's
-
13:30a lot of times where I think audio
-
13:32visualization is very good at when it's
-
13:34subtle just these subtle things I mean
-
13:36you talking to your Google assistant or
-
13:38theory or something they're doing a
-
13:40little bit of visualization of the input
-
13:41that's coming into your phone and it's
-
13:43nice that you're getting that feedback
-
13:44that there actually is like audio going
-
13:46through it so I kind of like you know
-
13:48just doing these subtle things but then
-
13:50again I don't always do very subtle
-
13:53things and I have some demos that are a
-
13:55little bit more chaotic now this is a 3d
-
14:02demo it's very it moves very quickly and
-
14:06it's very jagged and this is one trouble
-
14:08that I've been having with visualizing
-
14:10audio it's just that you're getting so
-
14:11much data coming in I like you saw I'm
-
14:14actually i'm just doing
-
14:15requestanimationframe i could delay that
-
14:17but the more i delay it where's the
-
14:19visualizations become and when you have
-
14:22these things happening in every like 100
-
14:25milliseconds or probably shorter than
-
14:26that it's hard to do tween between the
-
14:29different points and be able to do
-
14:30smooth animations it's possible but it's
-
14:33not that easy but this is showing you
-
14:35you can actually like integrate this
-
14:36kind of stuff into anything even like 3d
-
14:39objects then I have one more same song
-
14:46but this is actually just a waveform but
-
14:49it's around a surrounded circle so
-
14:53essentially took that same math that i
-
14:54was able to like to put points around
-
14:56the circle and then I just apply to
-
14:58waveform to it and then that way when it
-
15:00hits like a snare drum or beat drop or
-
15:02something you'll see that the kind of
-
15:05like fan out I'm actually caching like
-
15:07five versions of you know the waveform
-
15:10and then cycling through those and then
-
15:12this outer one is the oldest and the
-
15:15inner
-
15:15it's the newest and actually i'll show
-
15:17you really quick how easy it is to like
-
15:21change this around and this is this is
-
15:23why i have so many just random looking
-
15:26visualization I want to go to my code
-
15:28real quick and as you can see I just
-
15:30have like a bunch of variables up at the
-
15:31top but what's cool is that I could just
-
15:33say like 100 and then that should update
-
15:39and that's not I can refresh as you see
-
15:44it changed around the whole
-
15:45visualization I mean granted i think the
-
15:47other one was cooler looking this is not
-
15:49bad as you can see this is actually the
-
15:51one that the event horizon originally
-
15:53came from because you see the lines from
-
15:55the circles the outline and then i could
-
15:58even do things like this which this is
-
16:00actually going to just make my computer
-
16:02go super slow so now i'm catching up to
-
16:0910 of these things and doing the
-
16:10visualizations with that but it once you
-
16:13get something like this it actually
-
16:15starts to slow down the animation it
-
16:16looks very laggy but it's you know it
-
16:19looks really cool especially when you're
-
16:20not hearing the audio because when
-
16:22you're not hearing the audio it just
-
16:23looks like a cool animation but that is
-
16:28it and thank you we have the second mic
-
16:46up here yeah he's got the mic for you
-
16:57um I was using at weaning library uh and
-
17:02the it was just in a blob demo a lot of
-
17:07those things I'm just taking the raw
-
17:08audio data and then I'm trying to make a
-
17:09some type of wave for more like
-
17:12frequency something and then just
-
17:15putting that straight into the points
-
17:17with the blob player and I I'm not
-
17:19really using any animations and like the
-
17:21main thing here but you'll see when I
-
17:24actually press like pause it's kind of
-
17:27like you know tweens out and from those
-
17:31different points that's the only place
-
17:33when i'm actually using animation
-
17:34library at all but definitely if i
-
17:36wanted to smooth things out for instance
-
17:38in like a 3d one it's very jarring
-
17:39sometimes and I'm definitely thinking
-
17:42about integrating some types of
-
17:44animation library or some tweeting
-
17:45library to be able to submit those
-
17:46things out
-
17:54are you kidding a drum so really a lot
-
18:05of the visualizations are more or less
-
18:07based off of what would be the part of
-
18:10the waveform I'm taking like a highest
-
18:12peak of the wave form and saying that's
-
18:13kind of like the highest bit inside of
-
18:16so essentially like based off of that
-
18:18I'm making like the border fatter or the
-
18:20threshold for the the random points
-
18:23larger because you can't really like I
-
18:25mean you can get into a lot of like and
-
18:26like breaking apart the the song and
-
18:28whatnot you can actually do that with
-
18:30the stuff smarter people than I am can
-
18:32do that with that stuff I really just
-
18:34like to make things look cool right off
-
18:36the bat but more or less like what
-
18:38you're seeing here has nothing to do
-
18:40with like separating any of the sounds
-
18:41it's just more or less heavy taking part
-
18:44of the waveform at its peak and being
-
18:46like okay this is a very loud part of
-
18:48the song or something like that no
-
19:02that's a good question because I was
-
19:04going to say something but sometimes I
-
19:06forget to say something so you might see
-
19:09in this slide I actually connect instead
-
19:12of connecting I could connect the source
-
19:14directly to the destination and I that's
-
19:19actually I think inside of the the mdn
-
19:22doc that I was referencing earlier
-
19:23that's how they did it one thing I
-
19:26noticed when I did that though is that
-
19:27the visualization sometimes got out of
-
19:30sync so the way that I was able to kind
-
19:33of fix it was that I would straight from
-
19:36the analyzer go to Z the speaker so that
-
19:39way it always had to go through the
-
19:40analyzer before it hit the speakers so a
-
19:42lot of that latency wasn't there just
-
19:44because the analyzer had already gotten
-
19:46the data out of the buffer that was
-
19:49playing at that current time by the time
-
19:51it hit the speakers
-
19:56alright
-
20:00[Applause]