Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Chore): Minor Corrections in some existing tests and src files #732

Merged
merged 4 commits into from
Jan 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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