Skip to content

Commit

Permalink
Merge pull request #732 from Abhijay007/Abhijay007/Correction-tests
Browse files Browse the repository at this point in the history
(Chore): Minor Corrections in some existing tests and src files
  • Loading branch information
davepagurek authored Jan 22, 2023
2 parents 76bac0a + 4e321a3 commit 78d0865
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/audioWorklet/ringBuffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion test/tests/p5.Amplitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
1 change: 0 additions & 1 deletion test/tests/p5.AudioIn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down
8 changes: 4 additions & 4 deletions test/tests/p5.SoundFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
});

Expand Down
17 changes: 14 additions & 3 deletions test/tests/p5.SoundRecorder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 78d0865

Please sign in to comment.