Skip to content

Commit 78d0865

Browse files
authored
Merge pull request #732 from Abhijay007/Abhijay007/Correction-tests
(Chore): Minor Corrections in some existing tests and src files
2 parents 76bac0a + 4e321a3 commit 78d0865

File tree

6 files changed

+24
-11
lines changed

6 files changed

+24
-11
lines changed

src/audioWorklet/ringBuffer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class RingBuffer {
6767
for (let i = 0; i < sourceLength; ++i) {
6868
let writeIndex = (this._writeIndex + i) % this._length;
6969
for (let channel = 0; channel < this._channelCount; ++channel) {
70-
this._channelData[channel][writeIndex] = arraySequence[channel][i];
70+
if (arraySequence[channel])
71+
this._channelData[channel][writeIndex] = arraySequence[channel][i];
7172
}
7273
}
7374

src/main.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ p5.prototype.outputVolume = function (vol, rampTime = 0, tFromNow = 0) {
8787
var now = p5sound.audiocontext.currentTime;
8888
var currentVol = p5sound.output.gain.value;
8989
p5sound.output.gain.cancelScheduledValues(now + tFromNow);
90-
p5sound.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow);
90+
if (rampTime !== 0)
91+
p5sound.output.gain.linearRampToValueAtTime(currentVol, now + tFromNow);
9192
p5sound.output.gain.linearRampToValueAtTime(vol, now + tFromNow + rampTime);
9293
} else if (vol) {
9394
vol.connect(p5sound.output.gain);

test/tests/p5.Amplitude.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ describe('p5.Amplitude', function () {
6767
expect(amp.normalize).to.be.false;
6868
});
6969

70-
it('gets oscillator level', function () {
70+
it('gets oscillator level', function (done) {
7171
amp.setInput(osc);
7272
setTimeout(function () {
7373
expect(amp.getLevel()).to.be.closeTo(0.55, 0.25);
74+
done();
7475
}, 100);
7576
});
7677

test/tests/p5.AudioIn.js

-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ describe('p5.AudioIn', function () {
9595

9696
it('can get sources', function (done) {
9797
mic.getSources().then(function (sources) {
98-
console.log(sources);
9998
expect(sources).to.be.an('array');
10099
done();
101100
});

test/tests/p5.SoundFile.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ describe('p5.SoundFile', function () {
6060
() => done(),
6161
() => {},
6262
(progress) => {
63-
if (progress) {
63+
if (progress && progress !== 'size unknown') {
6464
expect(progress)
6565
.to.be.a('number')
6666
.to.be.greaterThan(0)
@@ -104,7 +104,7 @@ describe('p5.SoundFile', function () {
104104
() => done(),
105105
() => {},
106106
(progress) => {
107-
if (progress) {
107+
if (progress && progress !== 'size unknown') {
108108
expect(progress)
109109
.to.be.a('number')
110110
.to.be.greaterThan(0)
@@ -185,7 +185,7 @@ describe('p5.SoundFile', function () {
185185
setTimeout(() => {
186186
expect(sf._playing).to.be.false;
187187
done();
188-
}, 500); // as play back is 2 & cued 500ms , 500ms is enough to complete playing
188+
}, 550); // as play back is 2 & cued 500ms , 500ms is enough to complete playing
189189
});
190190
});
191191
it('can play with some given duration', function (done) {
@@ -266,8 +266,8 @@ describe('p5.SoundFile', function () {
266266
setTimeout(() => {
267267
expect(sf.bufferSourceNode._playing).to.be.false;
268268
expect(sf._playing).to.be.false;
269+
done();
269270
}, 100);
270-
done();
271271
});
272272
});
273273

test/tests/p5.SoundRecorder.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,23 @@ describe('p5.SoundRecorder', function () {
7272
recorder.setInput(mic);
7373
const outputSoundFile = new p5.SoundFile();
7474
setTimeout(() => {
75-
recorder.record(outputSoundFile, recordingDuration, function () {
76-
expect(outputSoundFile.duration()).to.eq(recordingDuration);
75+
recorder.record(outputSoundFile, 5 * recordingDuration, function () {
76+
expect(outputSoundFile.duration()).to.be.approximately(
77+
5 * recordingDuration,
78+
0.01
79+
);
7780

7881
const outputChannel = outputSoundFile.buffer.getChannelData(0);
79-
expect(outputChannel[0]).to.not.eq(0);
82+
let isAllZero = true;
8083

84+
for (let i = 0; i < outputChannel.length; i++) {
85+
if (outputChannel[i] !== 0) {
86+
isAllZero = false;
87+
break;
88+
}
89+
}
90+
91+
expect(isAllZero).to.be.false;
8192
outputSoundFile.dispose();
8293
mic.dispose();
8394
p5.prototype.outputVolume(0);

0 commit comments

Comments
 (0)