Tweening the volume of a sound

955 views
Skip to first unread message

mst101

unread,
Jun 22, 2013, 10:59:10 AM6/22/13
to createjs-...@googlegroups.com
Hi folks,

I've got two sound instances - sndMusic & sndNarration. I'd like the music to play initially, then fade out before the narration starts.

I am adding the following tweens to the timeline of my main application (MyVideo)...

//////////////////////////////////////////////////////////////////////////
this.timeline.addTween(cjs.Tween.get(sndMusic)
.call(sndMusic.play)          // Play music
.wait(200)                         // for 200 frames
.to({volume:0}, 50));           // Reduce volume to 0 over a period of 50 frames

this.timeline.addTween(cjs.Tween.get(sndNarration)
.wait(250)                         // Wait until music has finished
.call(sndNarration.play));    // Start narration

//////////////////////////////////////////////////////////////////////////

The music plays, but does not fade out before the narration starts. 

If I print out the value of sndMusic.getVolume() between frames 200-250, my eyes tell me that the volume of sndMusic gradually reduces to zero. Trouble is my ears don't agree!

Where am I going wrong? 

Here's some more code, in case it helps. Thanks

///////////////////////////////////////////////////////
function init() {
canvas = document.getElementById("canvas");
stage = new createjs.Stage(canvas);

// Preload sound
var manifest = [
{src:"sndMusic.mp3", id:"sndMusic"},
{src:"sndNarration.mp3", id:"sndNarration"}];

var loader = new createjs.LoadQueue(false);
loader.installPlugin(createjs.Sound);
loader.addEventListener("complete", handleComplete);
loader.loadManifest(manifest);
}

function handleComplete() {

// Initialise sounds
sndMusic = createjs.Sound.createInstance("sndMusic");
sndNarration = createjs.Sound.createInstance("sndNarration");
// Start the video
myVideo= new lib.MyVideo();
stage.addChild(myVideo);
}

Lanny

unread,
Jun 24, 2013, 11:34:27 AM6/24/13
to createjs-...@googlegroups.com
The volume of a sound in SoundJS is just a property. You have to use the setVolume method to actually change it. You can do this currently by adding an "change" listener to the tween, and calling setVolume each time the volume property changes.

That said, we are going to be pushing up a change this week to SoundJS which should make your approach possible. A few properties on Sound will be changing to getter/setters which will enable audio tweening -- and we already have a sample prepared to showcase it. 

Cheers.

mst101

unread,
Jun 25, 2013, 5:43:02 AM6/25/13
to createjs-...@googlegroups.com
Thanks Lanny. I understand now & have got it working. You guys are doing a great job; keep up the good work!

O'Jay Robinson

unread,
Jun 25, 2013, 11:11:31 AM6/25/13
to createjs-...@googlegroups.com
The change to getter setter functions that allows tweening volume and pan of sound instances is now pushed to GitHub (https://github.com/CreateJS/SoundJS/).

Hopefully that helps.

fumio

unread,
Jun 29, 2013, 5:23:42 AM6/29/13
to createjs-...@googlegroups.com
Current SoundJS is seemed to have been already updated.  Is this correct version 0.4.1?
On Wednesday, June 26, 2013 12:11:31 AM UTC+9, O'Jay Robinson wrote:

O'Jay Robinson

unread,
Jul 2, 2013, 11:44:11 AM7/2/13
to createjs-...@googlegroups.com
Hi Fumio, the correct version should be NEXT, available on GitHub.
The online docs are showing the NEXT build, rather than 0.4.1, which we will try to correct.

Thanks for bringing that to our attention.
Reply all
Reply to author
Forward
0 new messages