-
-
Notifications
You must be signed in to change notification settings - Fork 682
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add some tests for synths and audiovoice
- Loading branch information
1 parent
f0f92fc
commit 19acb4b
Showing
4 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
}); | ||
|
||
}); |