Skip to content

Commit

Permalink
add some tests for synths and audiovoice
Browse files Browse the repository at this point in the history
  • Loading branch information
therewasaguy committed May 28, 2018
1 parent f0f92fc commit 19acb4b
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 4 deletions.
19 changes: 15 additions & 4 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,21 @@ require.config({
}
});

var allTests = ['tests/p5.SoundFile', 'tests/p5.Amplitude',
'tests/p5.Oscillator', 'tests/p5.Distortion',
'tests/p5.Effect','tests/p5.Filter', 'tests/p5.FFT', 'tests/p5.Compressor',
'tests/p5.EQ', 'tests/p5.AudioIn'];
var allTests = [
'tests/p5.SoundFile',
'tests/p5.Amplitude',
'tests/p5.Oscillator',
'tests/p5.Distortion',
'tests/p5.Effect',
'tests/p5.Filter',
'tests/p5.FFT',
'tests/p5.Compressor',
'tests/p5.EQ',
'tests/p5.AudioIn',
'tests/p5.AudioVoice',
'tests/p5.MonoSynth',
'tests/p5.PolySynth'
];

p5.prototype.masterVolume(0);

Expand Down
21 changes: 21 additions & 0 deletions test/tests/p5.AudioVoice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
define(['chai'],
function(chai) {

var expect = chai.expect;

describe('p5.AudioVoice', function() {

it('can be created and disposed', function() {
var av = new p5.AudioVoice();
av.dispose();
});

it('can convert strings to frequency values', function() {
var av = new p5.AudioVoice();
var freq = av._setNote("A4");
expect(freq).to.equal(440);
av.dispose();
});
});

});
26 changes: 26 additions & 0 deletions test/tests/p5.MonoSynth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
define(['chai'],
function(chai) {

var expect = chai.expect;

describe('p5.MonoSynth', function() {

it('can be created and disposed', function() {
var monoSynth = new p5.MonoSynth();
monoSynth.dispose();
});

it('can play a note string', function(done) {
var monoSynth = new p5.MonoSynth();
monoSynth.play('A2');

// wait for scheduled value to complete
setTimeout(function() {
expect(monoSynth.oscillator.freq().value).to.equal(110);
monoSynth.dispose();
done();
}, 1);
});
});

});
37 changes: 37 additions & 0 deletions test/tests/p5.PolySynth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
define(['chai'],
function(chai) {

var expect = chai.expect;

describe('p5.PolySynth', function() {
var audioContext = p5.prototype.getAudioContext();

it('can be created and disposed', function() {
var polySynth = new p5.PolySynth();
polySynth.dispose();
});

it('keeps track of the number of voicesInUse', function() {
var polySynth = new p5.PolySynth();
var noteDuration = 0.01;

var noteTriggerTime = audioContext.currentTime;
var noteActiveTime = noteTriggerTime + noteDuration/2;
var noteDoneTime = noteTriggerTime + noteDuration;

expect(polySynth._voicesInUse.getValueAtTime(noteTriggerTime)).to.equal(0);

polySynth.play('A2', 0, 0, noteDuration);
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(1);
polySynth.play('A3', 0, 0, noteDuration);
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(2);
polySynth.play('A4', 0, 0, noteDuration);
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(3);

expect(polySynth._voicesInUse.getValueAtTime(noteDoneTime)).to.equal(0);

polySynth.dispose();
});
});

});

0 comments on commit 19acb4b

Please sign in to comment.