From ccb2152126942c97700a9db40f7e85d4d883602a Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Thu, 19 Jan 2023 23:35:06 +0530 Subject: [PATCH 1/4] (Chore): Minor Corrections in some exisitng tests and src files Signed-off-by: Abhijay Jain --- src/audioWorklet/ringBuffer.js | 2 ++ src/main.js | 3 ++- test/tests/p5.Amplitude.js | 3 ++- test/tests/p5.AudioIn.js | 1 - test/tests/p5.SoundFile.js | 8 ++++---- test/tests/p5.SoundRecorder.js | 17 ++++++++++++++--- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/audioWorklet/ringBuffer.js b/src/audioWorklet/ringBuffer.js index cb5925ff..8363e626 100644 --- a/src/audioWorklet/ringBuffer.js +++ b/src/audioWorklet/ringBuffer.js @@ -67,7 +67,9 @@ class RingBuffer { for (let i = 0; i < sourceLength; ++i) { let writeIndex = (this._writeIndex + i) % this._length; for (let channel = 0; channel < this._channelCount; ++channel) { + 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); From 5471df330136071c3041c6dd71e8210baecee0eb Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Thu, 19 Jan 2023 23:41:26 +0530 Subject: [PATCH 2/4] (Chore): fixed linting error Signed-off-by: Abhijay Jain --- src/audioWorklet/ringBuffer.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/audioWorklet/ringBuffer.js b/src/audioWorklet/ringBuffer.js index 8363e626..2205eadb 100644 --- a/src/audioWorklet/ringBuffer.js +++ b/src/audioWorklet/ringBuffer.js @@ -68,8 +68,7 @@ class RingBuffer { let writeIndex = (this._writeIndex + i) % this._length; for (let channel = 0; channel < this._channelCount; ++channel) { if (arraySequence[channel]) - this._channelData[channel][writeIndex] = arraySequence[channel][i]; - } + this._channelData[channel][writeIndex] = arraySequence[channel][i]; } } From dd55bc11e7ef88044219b235cf33072f7cd5f383 Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Thu, 19 Jan 2023 23:45:20 +0530 Subject: [PATCH 3/4] minor update in tests/p5.SoundRecorder.js Signed-off-by: Abhijay Jain --- test/tests/p5.SoundRecorder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/p5.SoundRecorder.js b/test/tests/p5.SoundRecorder.js index 09e3abb1..4cd3b791 100644 --- a/test/tests/p5.SoundRecorder.js +++ b/test/tests/p5.SoundRecorder.js @@ -146,7 +146,7 @@ describe('p5.SoundRecorder', function () { expect(outputSoundFile.duration()).to.eq(recordingDuration); const outputChannel = outputSoundFile.buffer.getChannelData(0); - expect(outputChannel[0]).to.not.eq(0); + let isAllZero = true; outputSoundFile.dispose(); p5.prototype.outputVolume(0); From 4e321a39d0d92201212ccaaaddf9d2beadec9a11 Mon Sep 17 00:00:00 2001 From: Abhijay Jain Date: Thu, 19 Jan 2023 23:49:31 +0530 Subject: [PATCH 4/4] minor update in tests/p5.SoundRecorder.js Signed-off-by: Abhijay Jain --- test/tests/p5.SoundRecorder.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/tests/p5.SoundRecorder.js b/test/tests/p5.SoundRecorder.js index 4cd3b791..09e3abb1 100644 --- a/test/tests/p5.SoundRecorder.js +++ b/test/tests/p5.SoundRecorder.js @@ -146,7 +146,7 @@ describe('p5.SoundRecorder', function () { expect(outputSoundFile.duration()).to.eq(recordingDuration); const outputChannel = outputSoundFile.buffer.getChannelData(0); - let isAllZero = true; + expect(outputChannel[0]).to.not.eq(0); outputSoundFile.dispose(); p5.prototype.outputVolume(0);