Skip to content

Commit

Permalink
Add splitter/merger node to play channel specified by parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
whenov committed Apr 1, 2016
1 parent fd6efe6 commit c7e96c3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/wavesurfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ var WaveSurfer = {
this.params.channel = channel;
this.drawer.clearWave();
this.drawBuffer();
this.backend.setChannel(channel);
},

/**
Expand Down
31 changes: 29 additions & 2 deletions src/webaudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ WaveSurfer.WebAudio = {
});
this.filters = null;
// Reconnect direct path
this.analyser.connect(this.gainNode);
this.analyser.connect(this.splitter);
}
},

Expand Down Expand Up @@ -91,7 +91,7 @@ WaveSurfer.WebAudio = {
filters.reduce(function (prev, curr) {
prev.connect(curr);
return curr;
}, this.analyser).connect(this.gainNode);
}, this.analyser).connect(this.splitter);
}

},
Expand Down Expand Up @@ -128,6 +128,30 @@ WaveSurfer.WebAudio = {
this.scriptNode.onaudioprocess = null;
},

createChannelNodes: function () {
var channels = this.buffer.numberOfChannels;

this.splitter = this.ac.createChannelSplitter(channels);
this.merger = this.ac.createChannelMerger(channels);

this.setChannel(this.params.channel);

this.analyser.disconnect();
this.analyser.connect(this.splitter);

this.merger.connect(this.gainNode);
},

setChannel: function (channel) {
var channels = this.buffer.numberOfChannels;

this.splitter.disconnect();

for (var c = 0; c < channels; c++) {
this.splitter.connect(this.merger, channel === -1 ? c : channel, c);
}
},

createAnalyserNode: function () {
this.analyser = this.ac.createAnalyser();
this.analyser.connect(this.gainNode);
Expand Down Expand Up @@ -248,6 +272,8 @@ WaveSurfer.WebAudio = {
this.disconnectSource();
this.gainNode.disconnect();
this.scriptNode.disconnect();
this.merger.disconnect();
this.splitter.disconnect();
this.analyser.disconnect();
},

Expand All @@ -256,6 +282,7 @@ WaveSurfer.WebAudio = {
this.lastPlay = this.ac.currentTime;
this.buffer = buffer;
this.createSource();
this.createChannelNodes();
},

createSource: function () {
Expand Down

0 comments on commit c7e96c3

Please sign in to comment.