Skip to content

Commit 600b650

Browse files
committed
adding create.js sound library, in case it helps with IE
1 parent 815f060 commit 600b650

4 files changed

Lines changed: 60 additions & 5 deletions

File tree

coffee/core/livecodelab-core.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ define [
7676
,'sound/samplebank'
7777
,'sound/sound-system'
7878
,'bowser'
79+
,'soundJS'
7980
,'buzz'
8081
,'lowLag'
8182
,'threejs'
@@ -105,6 +106,7 @@ define [
105106
,SampleBank
106107
,SoundSystem
107108
,bowser
109+
,createjs
108110
,buzz
109111
,lowLag
110112
,THREE
@@ -170,7 +172,7 @@ define [
170172
@renderer = new Renderer(@)
171173
@soundSystem =
172174
new SoundSystem(
173-
@eventRouter, @timeKeeper, buzz, lowLag, bowser, new SampleBank(buzz))
175+
@eventRouter, @timeKeeper, createjs, buzz, lowLag, bowser, new SampleBank(buzz))
174176

175177
# this one also interacts with colourFunctions, backgroundSceneContext,
176178
# canvasForBackground at runtime

coffee/rjs-init.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
requirejs.config(
88
paths:
99
'bowser': 'lib/bowser'
10+
'soundJS': 'lib/soundjs-0.5.2.min'
1011
'buzz': 'lib/buzz'
1112
'lowLag': 'lib/lowLag'
1213
'underscore': 'lib/underscore'
@@ -52,6 +53,9 @@ requirejs.config(
5253
'bowser':
5354
deps: []
5455
exports: 'bowser'
56+
'soundJS':
57+
deps: []
58+
exports: 'createjs'
5559
'buzz':
5660
deps: []
5761
exports: 'buzz'

coffee/sound/sound-system.coffee

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,13 @@ define () ->
1818
buzzObjectsPool: []
1919
soundFilesPaths: {}
2020
soundLoops: []
21+
22+
useBuzzPooled: false
23+
useBuzzFireAndForget: false
24+
useLowLag: false
25+
useSoundsJS: false
2126

22-
constructor: (@eventRouter, @timeKeeper, @buzz, @lowLag, @Bowser, @samplebank) ->
27+
constructor: (@eventRouter, @timeKeeper, @createjs, @buzz, @lowLag, @Bowser, @samplebank) ->
2328
@soundLoops.soundIDs = []
2429
@soundLoops.beatStrings = []
2530

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

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

36-
@playSound = (a,b,c) => @play_using_LOWLAGJS(a,b,c)
41+
if @Bowser.msie
42+
@useSoundsJS = true
43+
@playSound = (a,b,c) => @play_using_SOUNDJS(a,b,c)
44+
45+
#@playSound = (a,b,c) => @play_using_BUZZ_JS_FIRE_AND_FORGET(a,b,c)
46+
47+
#@useBuzzPooled = true
48+
#@playSound = (a,b,c) => @play_using_BUZZJS_WITH_ONE_POOL_PER_SOUND(a,b,c)
49+
50+
else
51+
@playSound = (a,b,c) => @play_using_LOWLAGJS(a,b,c)
3752

3853
addToScope: (scope) ->
3954

@@ -94,6 +109,9 @@ define () ->
94109
availableBuzzObject = new @buzz.sound(soundFilePath)
95110
availableBuzzObject.play()
96111

112+
play_using_SOUNDJS: (soundFilesPaths,loopedSoundID,@buzzObjectsPool) ->
113+
@createjs.Sound.play(loopedSoundID)
114+
97115
play_using_DYNAMICALLY_CREATED_AUDIO_TAG: (soundFilesPaths,loopedSoundID,@buzzObjectsPool) ->
98116
audioElement = undefined
99117
source1 = undefined
@@ -133,7 +151,7 @@ define () ->
133151
# create a new one
134152
# OR there are already too many, so simply put the sound system
135153
# is mangled.
136-
if @totalCreatedSoundObjects > 31
154+
if @totalCreatedSoundObjects > 91
137155
@soundSystemIsMangled = true
138156
$("#soundSystemIsMangledMessage").modal()
139157
$("#simplemodal-container").height 250
@@ -204,9 +222,22 @@ define () ->
204222
soundInfo = undefined
205223
preloadSounds = undefined
206224
soundDef = @samplebank
225+
226+
if @useSoundsJS
227+
loadHandler = (event, theSound) ->
228+
# This is fired for each sound that is registered.
229+
instance = createjs.Sound.play(event.src) # play using id. Could also use full source path or event.src.
230+
instance.volume = 0.001
231+
return
232+
createjs.Sound.addEventListener "fileload", createjs.proxy(loadHandler, @);
233+
207234
for cycleSoundDefs in [0...soundDef.sounds.length]
235+
208236
soundInfo = soundDef.getByNumber(cycleSoundDefs)
209-
#@buzzObjectsPool[soundInfo.name] = []
237+
if @useSoundsJS
238+
createjs.Sound.registerSound soundInfo.path, soundInfo.name, 30
239+
if @useBuzzPooled
240+
@buzzObjectsPool[soundInfo.name] = []
210241
@soundFilesPaths[soundInfo.name] = soundInfo.path
211242
@lowLag.load(soundInfo.path,soundInfo.name)
212243

js_lib/soundjs-0.5.2.min.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)