Skip to content

Commit

Permalink
adding create.js sound library, in case it helps with IE
Browse files Browse the repository at this point in the history
  • Loading branch information
davidedc committed Nov 15, 2014
1 parent 815f060 commit 600b650
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 5 deletions.
4 changes: 3 additions & 1 deletion coffee/core/livecodelab-core.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ define [
,'sound/samplebank'
,'sound/sound-system'
,'bowser'
,'soundJS'
,'buzz'
,'lowLag'
,'threejs'
Expand Down Expand Up @@ -105,6 +106,7 @@ define [
,SampleBank
,SoundSystem
,bowser
,createjs
,buzz
,lowLag
,THREE
Expand Down Expand Up @@ -170,7 +172,7 @@ define [
@renderer = new Renderer(@)
@soundSystem =
new SoundSystem(
@eventRouter, @timeKeeper, buzz, lowLag, bowser, new SampleBank(buzz))
@eventRouter, @timeKeeper, createjs, buzz, lowLag, bowser, new SampleBank(buzz))

# this one also interacts with colourFunctions, backgroundSceneContext,
# canvasForBackground at runtime
Expand Down
4 changes: 4 additions & 0 deletions coffee/rjs-init.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
requirejs.config(
paths:
'bowser': 'lib/bowser'
'soundJS': 'lib/soundjs-0.5.2.min'
'buzz': 'lib/buzz'
'lowLag': 'lib/lowLag'
'underscore': 'lib/underscore'
Expand Down Expand Up @@ -52,6 +53,9 @@ requirejs.config(
'bowser':
deps: []
exports: 'bowser'
'soundJS':
deps: []
exports: 'createjs'
'buzz':
deps: []
exports: 'buzz'
Expand Down
39 changes: 35 additions & 4 deletions coffee/sound/sound-system.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ define () ->
buzzObjectsPool: []
soundFilesPaths: {}
soundLoops: []

useBuzzPooled: false
useBuzzFireAndForget: false
useLowLag: false
useSoundsJS: false

constructor: (@eventRouter, @timeKeeper, @buzz, @lowLag, @Bowser, @samplebank) ->
constructor: (@eventRouter, @timeKeeper, @createjs, @buzz, @lowLag, @Bowser, @samplebank) ->
@soundLoops.soundIDs = []
@soundLoops.beatStrings = []

Expand All @@ -33,7 +38,17 @@ define () ->

@timeKeeper.addListener('beat', (beat) => @soundLoop(beat) );

@playSound = (a,b,c) => @play_using_LOWLAGJS(a,b,c)
if @Bowser.msie
@useSoundsJS = true
@playSound = (a,b,c) => @play_using_SOUNDJS(a,b,c)

#@playSound = (a,b,c) => @play_using_BUZZ_JS_FIRE_AND_FORGET(a,b,c)

#@useBuzzPooled = true
#@playSound = (a,b,c) => @play_using_BUZZJS_WITH_ONE_POOL_PER_SOUND(a,b,c)

else
@playSound = (a,b,c) => @play_using_LOWLAGJS(a,b,c)

addToScope: (scope) ->

Expand Down Expand Up @@ -94,6 +109,9 @@ define () ->
availableBuzzObject = new @buzz.sound(soundFilePath)
availableBuzzObject.play()

play_using_SOUNDJS: (soundFilesPaths,loopedSoundID,@buzzObjectsPool) ->
@createjs.Sound.play(loopedSoundID)

play_using_DYNAMICALLY_CREATED_AUDIO_TAG: (soundFilesPaths,loopedSoundID,@buzzObjectsPool) ->
audioElement = undefined
source1 = undefined
Expand Down Expand Up @@ -133,7 +151,7 @@ define () ->
# create a new one
# OR there are already too many, so simply put the sound system
# is mangled.
if @totalCreatedSoundObjects > 31
if @totalCreatedSoundObjects > 91
@soundSystemIsMangled = true
$("#soundSystemIsMangledMessage").modal()
$("#simplemodal-container").height 250
Expand Down Expand Up @@ -204,9 +222,22 @@ define () ->
soundInfo = undefined
preloadSounds = undefined
soundDef = @samplebank

if @useSoundsJS
loadHandler = (event, theSound) ->
# This is fired for each sound that is registered.
instance = createjs.Sound.play(event.src) # play using id. Could also use full source path or event.src.
instance.volume = 0.001
return
createjs.Sound.addEventListener "fileload", createjs.proxy(loadHandler, @);

for cycleSoundDefs in [0...soundDef.sounds.length]

soundInfo = soundDef.getByNumber(cycleSoundDefs)
#@buzzObjectsPool[soundInfo.name] = []
if @useSoundsJS
createjs.Sound.registerSound soundInfo.path, soundInfo.name, 30
if @useBuzzPooled
@buzzObjectsPool[soundInfo.name] = []
@soundFilesPaths[soundInfo.name] = soundInfo.path
@lowLag.load(soundInfo.path,soundInfo.name)

Expand Down
18 changes: 18 additions & 0 deletions js_lib/soundjs-0.5.2.min.js

Large diffs are not rendered by default.

0 comments on commit 600b650

Please sign in to comment.