|
|
@ -86,17 +86,18 @@ PCMPlayer.prototype.destroy = function() {
|
|
|
|
PCMPlayer.prototype.flush = function() {
|
|
|
|
PCMPlayer.prototype.flush = function() {
|
|
|
|
if (!this.samples.length) return;
|
|
|
|
if (!this.samples.length) return;
|
|
|
|
var bufferSource = this.audioCtx.createBufferSource(),
|
|
|
|
var bufferSource = this.audioCtx.createBufferSource(),
|
|
|
|
length = this.samples.length,
|
|
|
|
length = this.samples.length / this.option.channels,
|
|
|
|
audioBuffer = this.audioCtx.createBuffer(this.option.channels, length, this.option.sampleRate),
|
|
|
|
audioBuffer = this.audioCtx.createBuffer(this.option.channels, length, this.option.sampleRate),
|
|
|
|
audioData,
|
|
|
|
audioData,
|
|
|
|
channel,
|
|
|
|
channel,
|
|
|
|
offset,
|
|
|
|
offset,
|
|
|
|
i,
|
|
|
|
i,
|
|
|
|
decrement = 50;
|
|
|
|
decrement;
|
|
|
|
|
|
|
|
|
|
|
|
for (channel = 0; channel < this.option.channels; channel++) {
|
|
|
|
for (channel = 0; channel < this.option.channels; channel++) {
|
|
|
|
audioData = audioBuffer.getChannelData(channel);
|
|
|
|
audioData = audioBuffer.getChannelData(channel);
|
|
|
|
offset = channel;
|
|
|
|
offset = channel;
|
|
|
|
|
|
|
|
decrement = 50;
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
audioData[i] = this.samples[offset];
|
|
|
|
audioData[i] = this.samples[offset];
|
|
|
|
/* fadein */
|
|
|
|
/* fadein */
|
|
|
@ -114,7 +115,7 @@ PCMPlayer.prototype.flush = function() {
|
|
|
|
if (this.startTime < this.audioCtx.currentTime) {
|
|
|
|
if (this.startTime < this.audioCtx.currentTime) {
|
|
|
|
this.startTime = this.audioCtx.currentTime;
|
|
|
|
this.startTime = this.audioCtx.currentTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log('start vs current '+this.startTime+' vs '+this.audioCtx.currentTime);
|
|
|
|
console.log('start vs current '+this.startTime+' vs '+this.audioCtx.currentTime+' duration: '+audioBuffer.duration);
|
|
|
|
bufferSource.buffer = audioBuffer;
|
|
|
|
bufferSource.buffer = audioBuffer;
|
|
|
|
bufferSource.connect(this.gainNode);
|
|
|
|
bufferSource.connect(this.gainNode);
|
|
|
|
bufferSource.start(this.startTime);
|
|
|
|
bufferSource.start(this.startTime);
|
|
|
|