diff --git a/src/audioWorklet/ringBuffer.js b/src/audioWorklet/ringBuffer.js index cb5925ff..2205eadb 100644 --- a/src/audioWorklet/ringBuffer.js +++ b/src/audioWorklet/ringBuffer.js @@ -67,7 +67,8 @@ class RingBuffer { for (let i = 0; i < sourceLength; ++i) { let writeIndex = (this._writeIndex + i) % this._length; for (let channel = 0; channel < this._channelCount; ++channel) { - this._channelData[channel][writeIndex] = arraySequence[channel][i]; + if (arraySequence[channel]) + this._channelData[channel][writeIndex] = arraySequence[channel][i]; } } diff --git a/src/main.js b/src/main.js index ca729979..7f4f874f 100644 --- a/src/main.js +++ b/src/main.js @@ -87,7 +87,8 @@ p5.prototype.outputVolume = function (vol, rampTime = 0, tFromNow = 0) { var now = p5sound.audiocontext.currentTime; var currentVol = p5sound.output.gain.value; p5sound.output.gain.cancelScheduledValues(now + tFromNow); - p5sound.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow); + if (rampTime !== 0) + p5sound.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow); p5sound.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime); } else if (vol) { vol.connect(p5sound.output.gain); diff --git a/test/tests/p5.Amplitude.js b/test/tests/p5.Amplitude.js index 392f6464..d0d41cb9 100644 --- a/test/tests/p5.Amplitude.js +++ b/test/tests/p5.Amplitude.js @@ -67,10 +67,11 @@ describe('p5.Amplitude', function () { expect(amp.normalize).to.be.false; }); - it('gets oscillator level', function () { + it('gets oscillator level', function (done) { amp.setInput(osc); setTimeout(function () { expect(amp.getLevel()).to.be.closeTo(0.55, 0.25); + done(); }, 100); }); diff --git a/test/tests/p5.AudioIn.js b/test/tests/p5.AudioIn.js index e10d8e33..1581e168 100644 --- a/test/tests/p5.AudioIn.js +++ b/test/tests/p5.AudioIn.js @@ -95,7 +95,6 @@ describe('p5.AudioIn', function () { it('can get sources', function (done) { mic.getSources().then(function (sources) { - console.log(sources); expect(sources).to.be.an('array'); done(); }); diff --git a/test/tests/p5.SoundFile.js b/test/tests/p5.SoundFile.js index 266ff5c9..da745162 100644 --- a/test/tests/p5.SoundFile.js +++ b/test/tests/p5.SoundFile.js @@ -60,7 +60,7 @@ describe('p5.SoundFile', function () { () => done(), () => {}, (progress) => { - if (progress) { + if (progress && progress !== 'size unknown') { expect(progress) .to.be.a('number') .to.be.greaterThan(0) @@ -104,7 +104,7 @@ describe('p5.SoundFile', function () { () => done(), () => {}, (progress) => { - if (progress) { + if (progress && progress !== 'size unknown') { expect(progress) .to.be.a('number') .to.be.greaterThan(0) @@ -185,7 +185,7 @@ describe('p5.SoundFile', function () { setTimeout(() => { expect(sf._playing).to.be.false; done(); - }, 500); // as play back is 2 & cued 500ms , 500ms is enough to complete playing + }, 550); // as play back is 2 & cued 500ms , 500ms is enough to complete playing }); }); it('can play with some given duration', function (done) { @@ -266,8 +266,8 @@ describe('p5.SoundFile', function () { setTimeout(() => { expect(sf.bufferSourceNode._playing).to.be.false; expect(sf._playing).to.be.false; + done(); }, 100); - done(); }); }); diff --git a/test/tests/p5.SoundRecorder.js b/test/tests/p5.SoundRecorder.js index 466ea605..09e3abb1 100644 --- a/test/tests/p5.SoundRecorder.js +++ b/test/tests/p5.SoundRecorder.js @@ -72,12 +72,23 @@ describe('p5.SoundRecorder', function () { recorder.setInput(mic); const outputSoundFile = new p5.SoundFile(); setTimeout(() => { - recorder.record(outputSoundFile, recordingDuration, function () { - expect(outputSoundFile.duration()).to.eq(recordingDuration); + recorder.record(outputSoundFile, 5 * recordingDuration, function () { + expect(outputSoundFile.duration()).to.be.approximately( + 5 * recordingDuration, + 0.01 + ); const outputChannel = outputSoundFile.buffer.getChannelData(0); - expect(outputChannel[0]).to.not.eq(0); + let isAllZero = true; + for (let i = 0; i < outputChannel.length; i++) { + if (outputChannel[i] !== 0) { + isAllZero = false; + break; + } + } + + expect(isAllZero).to.be.false; outputSoundFile.dispose(); mic.dispose(); p5.prototype.outputVolume(0);