Web Audio Tutorial 9/4, 2015 Your Goal Learn what digital audio is - - PowerPoint PPT Presentation

web audio tutorial
SMART_READER_LITE
LIVE PREVIEW

Web Audio Tutorial 9/4, 2015 Your Goal Learn what digital audio is - - PowerPoint PPT Presentation

Web Audio Tutorial 9/4, 2015 Your Goal Learn what digital audio is and how it works Implement the concept of digital audio on the Web My Goal Introduce you Web Audio API (+ basic Web programming) Provide some starting points and


slide-1
SLIDE 1

Web Audio Tutorial

9/4, 2015

slide-2
SLIDE 2

Your Goal

  • Learn what digital audio is and how it works
  • Implement the concept of digital audio on the Web
slide-3
SLIDE 3

My Goal

  • Introduce you Web Audio API (+ basic Web

programming)

  • Provide some starting points and references
slide-4
SLIDE 4

Why Web?

  • Platform independent
  • Network-familiar
  • Easy distribution
slide-5
SLIDE 5

History of Web Audio

http://www.devbattles.com/en/sand/post-69-Learn+Web+Audio+API

slide-6
SLIDE 6

The Web

“The World Wide Web (www, W3) is an information space where documents and other web resources are identified by URIs, interlinked by hypertext links, and can be accessed via the Internet.”

https://en.wikipedia.org/wiki/World_Wide_Web

slide-7
SLIDE 7

The Web You See

slide-8
SLIDE 8

Web Page

  • Web Page : HTML + CSS + Javascript (+…)
slide-9
SLIDE 9

HTML

  • Hypertext Markup Language
  • Hypertext: text that uses hyperlink
  • Markup Language: a language that uses

<bold>mark</bold>

  • Usually, HTML provides the structure and contents
  • f a page
slide-10
SLIDE 10

HTML Tutorial

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default

slide-11
SLIDE 11

HTML Elements

An element is a part of a webpage. In XML and HTML, an element may contain a data item or a chunk of text or an image,

  • r perhaps nothing.

A typical element includes an opening tag, attributes, content, and a closing tag:

https://developer.mozilla.org/en-US/docs/Glossary/Element

Consult https://developer.mozilla.org/en-US/docs/Web/HTML/Element

slide-12
SLIDE 12

Style

  • Specify how a tag or an HTML element will look like
  • Often separated as a single file called CSS cascade
slide-13
SLIDE 13

CSS-Striped Web Page

slide-14
SLIDE 14
slide-15
SLIDE 15

Do we call this programming?

slide-16
SLIDE 16

Javascript

  • A programming language that is (often) used for

Dynamic Web pages

  • Consult https://developer.mozilla.org/en-US/docs/

Web/JavaScript

slide-17
SLIDE 17

<a href="javascript:void(0);"

  • nclick="fn_trendKeyAnimation('R');"

style="position: absolute; right: 0px;”> <img src="/kaist/images/portal/ptl_main/sl_next.gif" alt=“next"> </a>

slide-18
SLIDE 18

function fn_trendKeyAnimation(direction) { var width = 0; if (direction == "R") { width = $('#trendKey li:last-child').width(); $("#trendKey").animate({ left: + width }, 400, function () { $('#trendKey li:last-child').prependTo('#trendKey'); $('#trendKey').css('left', ''); }); } else { /* hidden for compactness */} }

slide-19
SLIDE 19

Back To The History

slide-20
SLIDE 20

The History

  • <bgsound>: an element that can play a midi file
  • flash: yeah, the Flash you know
  • <audio>: an element that can play audio files
slide-21
SLIDE 21

<audio>

http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default

slide-22
SLIDE 22

<audio>

+ You can play, stop, seek, or even detect some events + Programmatically controllable (via Javascript)

  • Nothing more than playing audio files
slide-23
SLIDE 23

Web Audio API

  • Audio mixing, routing, signal processing, synthesis,

and a bit of analysis

  • Consists of an audio context and audio nodes

https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API

slide-24
SLIDE 24

Real Audio System

https://jfkoernia.wordpress.com/category/gubuk-audio/page/2/

input/source mixer effect gain

  • utput/destination
slide-25
SLIDE 25

In Web Audio

http://chimera.labs.oreilly.com/books/1234000001552/ch01.html#s01_1

slide-26
SLIDE 26

Web Audio in Action

  • https://www.soundtrap.com/studio/
  • http://dinahmoelabs.com/plink
  • http://webaudiodemos.appspot.com/
  • https://chromium.googlecode.com/svn/trunk/

samples/audio/samples.html

slide-27
SLIDE 27

Web Audio in Action

  • http://www.google.com/doodles/robert-

moogs-78th-birthday

  • http://onlinesequencer.net/
  • http://www.hongkiat.com/blog/virtual-instrument-

web-browser/

  • http://patternsketch.com/
  • http://webaudioapi.com/samples/
slide-28
SLIDE 28

Simple Code

  • Simple audio player
  • Button interaction and event listening
  • Audio context
  • Loading and decoding audio files
  • Buffer, BufferSourceNode and connecting nodes
slide-29
SLIDE 29

First ¡of ¡all, ¡you ¡need ¡ ¡a ¡*working* ¡web ¡browser

Download ¡Chrome ¡or ¡Firefox ¡(preferably ¡Developer ¡Edition)

slide-30
SLIDE 30

…and ¡an ¡text ¡editor

slide-31
SLIDE 31

Make ¡an ¡HTML ¡file

slide-32
SLIDE 32

The ¡very ¡skeleton Save ¡and ¡open ¡it ¡ ¡ ¡ ¡ ¡in ¡your ¡browser

slide-33
SLIDE 33

Add ¡a ¡file ¡chooser

  • nchange ¡refers ¡a ¡script ¡to ¡be ¡run ¡ ¡

when ¡the ¡content ¡of ¡the ¡element ¡is ¡changed ¡ So, ¡once ¡we ¡choose ¡a ¡file, ¡ ¡the ¡function ¡“loadFile” ¡will ¡be ¡called

slide-34
SLIDE 34

Try ¡choosing ¡a ¡file

nothing ¡happens… Let’s ¡check ¡the ¡console ¡

¡ ¡(for ¡Chrome, ¡View ¡-­‑> ¡Developer ¡-­‑> ¡Javascript ¡Console ¡ ¡ ¡ ¡ ¡for ¡Firefox, ¡Tools ¡-­‑> ¡Web ¡Developer ¡-­‑> ¡Web ¡Console)

It ¡says ¡there’s ¡no ¡such ¡function ¡“loadFile”

slide-35
SLIDE 35

Add ¡a ¡Javascript ¡file

add ¡a ¡“script” ¡tag ¡to ¡import ¡a ¡js ¡file and ¡put ¡a ¡js ¡file ¡with ¡the ¡“loadFile” ¡function

note ¡that ¡we ¡use ¡“console.log” ¡ ¡ ¡ ¡ ¡to ¡print ¡something ¡on ¡the ¡console

And ¡now ¡... Gotcha!

slide-36
SLIDE 36

Let’s ¡create ¡an ¡(instance ¡of) ¡AudioContext

Declare ¡a ¡global ¡variable And ¡after ¡the ¡page ¡is ¡loaded, ¡ create ¡it ¡ ¡ ¡ ¡ You ¡can ¡check ¡your ¡global ¡variables ¡ by ¡entering ¡its ¡name ¡

slide-37
SLIDE 37

Load ¡the ¡file ¡and ¡decode

One ¡more ¡global ¡variable loadFile ¡-­‑> ¡fileLoaded ¡-­‑> ¡audioFileDecoded

audioContext ¡decodes ¡ ¡the ¡content ¡of ¡the ¡file fileReader ¡reads ¡ the ¡content ¡of ¡the ¡file now ¡we ¡have ¡the ¡audioBuffer, ¡ which ¡is ¡an ¡array ¡of ¡audio ¡samples

slide-38
SLIDE 38

Write ¡play()

Yet ¡another ¡global ¡variable

An ¡error ¡handling ¡function Stop ¡the ¡bufferSourceNode ¡if ¡it ¡is ¡playing Create ¡a ¡new ¡node, ¡set ¡the ¡buffer, ¡ ¡ connect ¡it ¡to ¡the ¡destination ¡note, ¡and ¡start ¡the ¡source

slide-39
SLIDE 39

Add ¡a ¡button ¡for ¡play

Yet ¡another ¡global ¡variable

An ¡error ¡handling ¡function Stop ¡the ¡bufferSourceNode ¡if ¡it ¡is ¡playing Create ¡a ¡new ¡node, ¡set ¡the ¡buffer, ¡ ¡ connect ¡it ¡to ¡the ¡destination ¡note, ¡and ¡start ¡the ¡source

slide-40
SLIDE 40

System ¡Overview

Buffer ¡ Source ¡ Node

Destination ¡ Node

AudioContext

Audio ¡ Buffer

slide-41
SLIDE 41

http://dilu.kaist.ac.kr/simpleWebPlayer/simpleWebPlayer.html

slide-42
SLIDE 42

Recommended Links

  • Web Audio API book (O’Reilly): 


http://chimera.labs.oreilly.com/books/ 1234000001552/

  • W3C’s Web Audio API Reference: 


http://webaudio.github.io/web-audio-api/

  • Mozilla’s Web Audio API page:


https://developer.mozilla.org/en-US/docs/Web/API/ Web_Audio_API

slide-43
SLIDE 43

Q&A