Skip to content

Commit

Permalink
Merge pull request #4 from cstoquer/master
Browse files Browse the repository at this point in the history
Fixes: pitch & unmute
  • Loading branch information
Cedric Stoquer committed Jun 29, 2015
2 parents b25bd67 + b578593 commit 7027936
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
10 changes: 5 additions & 5 deletions SoundBuffered.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,13 @@ SoundBuffered.prototype.setLoop = function (value) {
*/
SoundBuffered.prototype.setPitch = function (pitch, portamento) {
this.pitch = pitch;
this._setPlaybackRate(pitch, portamento);
this._setPlaybackRate(portamento);
};

//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
SoundBuffered.prototype._setPlaybackRate = function (pitch, portamento) {
SoundBuffered.prototype._setPlaybackRate = function (portamento) {
if (!this.source) return;
var rate = Math.pow(2, (this._playPitch + pitch) / 12);
var rate = Math.pow(2, (this._playPitch + this.pitch) / 12);
portamento = portamento || 0;
this.source.playbackRate.setTargetAtTime(rate, this.audioContext.currentTime, portamento);
};
Expand Down Expand Up @@ -205,7 +205,7 @@ SoundBuffered.prototype._play = function (pitch) {
// update pitch if needed
if ((pitch || pitch === 0) && pitch !== this._playPitch) {
this._playPitch = pitch;
this._setPlaybackRate(this.pitch + this._playPitch, 0);
this._setPlaybackRate(0);
}
return;
}
Expand All @@ -231,7 +231,7 @@ SoundBuffered.prototype._play = function (pitch) {

this._playPitch = pitch || 0;
if (pitch || this.pitch) {
this._setPlaybackRate(this.pitch + this._playPitch, 0);
this._setPlaybackRate(0);
}

sourceNode.loop = this.loop;
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "AudioManager",
"repo": "Wizcorp/AudioManager",
"version": "0.1.1",
"version": "0.1.2",
"description": "Play sounds using Web Audio, fallback to HTML5 Audio",
"dependencies": {
"Wizcorp/util": "0.1.0"
Expand Down
12 changes: 7 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,15 @@ AudioManager.prototype.setVolume = function (channelId, volume, muted) {
if (wasChannelMuted) { channel.loopSound.play(); }
} else if (!channel.muted) {
// no sounds are loaded in channel, channel is unmutted
this.playLoopSound(channelId, channel.loopId, channel.loopVol);
this.playLoopSound(channelId, channel.loopId, volume * channel.loopVol);
}
};

//▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
/** Create and load sound
*
* @param {number} id - sound id
* @param {Function} [cb] - optionnal callback function called when sound has finished to load
* @param {Function} [cb] - optional callback function called when sound has finished to load
*/
AudioManager.prototype.loadSound = function (id, cb) {
var sound = this.createSound(id);
Expand Down Expand Up @@ -251,9 +251,11 @@ AudioManager.prototype.freeSound = function (sound) {
*
* @param {string} channelId - channel id.
* @param {string} soundId - sound id
* @param {number} [volume] - sound volume, a integer in rage ]0..1]
* @param {number} [volume] - optional volume, a integer in range ]0..1]
* @param {number} [pan] - optional panoramic, a integer in rage [-1..1]
* @param {number} [pitch] - optional pitch, in semi-tone
*/
AudioManager.prototype.playLoopSound = function (channelId, soundId, volume) {
AudioManager.prototype.playLoopSound = function (channelId, soundId, volume, pan, pitch) {
var defaultFade = this.settings.defaultFade;
var channel = this.channels[channelId];
var currentSoundId = channel.loopId;
Expand All @@ -272,7 +274,7 @@ AudioManager.prototype.playLoopSound = function (channelId, soundId, volume) {
channel.nextLoop = null;
sound.setLoop(true);
sound.fade = defaultFade;
sound.play();
sound.play(volume * channel.volume, pan, pitch);
}

function stopCurrentLoop() {
Expand Down

0 comments on commit 7027936

Please sign in to comment.