Skip to content

Commit 19acb4b

Browse files
committed
add some tests for synths and audiovoice
1 parent f0f92fc commit 19acb4b

File tree

4 files changed

+99
-4
lines changed

4 files changed

+99
-4
lines changed

test/test.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,21 @@ require.config({
66
}
77
});
88

9-
var allTests = ['tests/p5.SoundFile', 'tests/p5.Amplitude',
10-
'tests/p5.Oscillator', 'tests/p5.Distortion',
11-
'tests/p5.Effect','tests/p5.Filter', 'tests/p5.FFT', 'tests/p5.Compressor',
12-
'tests/p5.EQ', 'tests/p5.AudioIn'];
9+
var allTests = [
10+
'tests/p5.SoundFile',
11+
'tests/p5.Amplitude',
12+
'tests/p5.Oscillator',
13+
'tests/p5.Distortion',
14+
'tests/p5.Effect',
15+
'tests/p5.Filter',
16+
'tests/p5.FFT',
17+
'tests/p5.Compressor',
18+
'tests/p5.EQ',
19+
'tests/p5.AudioIn',
20+
'tests/p5.AudioVoice',
21+
'tests/p5.MonoSynth',
22+
'tests/p5.PolySynth'
23+
];
1324

1425
p5.prototype.masterVolume(0);
1526

test/tests/p5.AudioVoice.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
define(['chai'],
2+
function(chai) {
3+
4+
var expect = chai.expect;
5+
6+
describe('p5.AudioVoice', function() {
7+
8+
it('can be created and disposed', function() {
9+
var av = new p5.AudioVoice();
10+
av.dispose();
11+
});
12+
13+
it('can convert strings to frequency values', function() {
14+
var av = new p5.AudioVoice();
15+
var freq = av._setNote("A4");
16+
expect(freq).to.equal(440);
17+
av.dispose();
18+
});
19+
});
20+
21+
});

test/tests/p5.MonoSynth.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
define(['chai'],
2+
function(chai) {
3+
4+
var expect = chai.expect;
5+
6+
describe('p5.MonoSynth', function() {
7+
8+
it('can be created and disposed', function() {
9+
var monoSynth = new p5.MonoSynth();
10+
monoSynth.dispose();
11+
});
12+
13+
it('can play a note string', function(done) {
14+
var monoSynth = new p5.MonoSynth();
15+
monoSynth.play('A2');
16+
17+
// wait for scheduled value to complete
18+
setTimeout(function() {
19+
expect(monoSynth.oscillator.freq().value).to.equal(110);
20+
monoSynth.dispose();
21+
done();
22+
}, 1);
23+
});
24+
});
25+
26+
});

test/tests/p5.PolySynth.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
define(['chai'],
2+
function(chai) {
3+
4+
var expect = chai.expect;
5+
6+
describe('p5.PolySynth', function() {
7+
var audioContext = p5.prototype.getAudioContext();
8+
9+
it('can be created and disposed', function() {
10+
var polySynth = new p5.PolySynth();
11+
polySynth.dispose();
12+
});
13+
14+
it('keeps track of the number of voicesInUse', function() {
15+
var polySynth = new p5.PolySynth();
16+
var noteDuration = 0.01;
17+
18+
var noteTriggerTime = audioContext.currentTime;
19+
var noteActiveTime = noteTriggerTime + noteDuration/2;
20+
var noteDoneTime = noteTriggerTime + noteDuration;
21+
22+
expect(polySynth._voicesInUse.getValueAtTime(noteTriggerTime)).to.equal(0);
23+
24+
polySynth.play('A2', 0, 0, noteDuration);
25+
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(1);
26+
polySynth.play('A3', 0, 0, noteDuration);
27+
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(2);
28+
polySynth.play('A4', 0, 0, noteDuration);
29+
expect(polySynth._voicesInUse.getValueAtTime(noteActiveTime)).to.equal(3);
30+
31+
expect(polySynth._voicesInUse.getValueAtTime(noteDoneTime)).to.equal(0);
32+
33+
polySynth.dispose();
34+
});
35+
});
36+
37+
});

0 commit comments

Comments
 (0)