testing instruments

This commit is contained in:
Yotam Mann 2015-08-31 11:37:10 -04:00
parent 5b4ee950c8
commit cff363fb1a
13 changed files with 675 additions and 0 deletions

View file

@ -0,0 +1,79 @@
define(["helper/OutputAudio", "Tone/instrument/Instrument", "helper/OutputAudioStereo", "Test", "helper/Offline", "helper/Meter"],
function (OutputAudio, Instrument, OutputAudioStereo, Test, Offline, Meter) {
return function(Constr, note){
context("Instrument Tests", function(){
it ("extends Tone.Instrument", function(){
var instance = new Constr();
expect(instance).to.be.an.instanceof(Instrument);
instance.dispose();
});
it ("can connect the output", function(){
var instance = new Constr();
instance.connect(Test);
instance.dispose();
});
it ("can set the volume", function(){
var instance = new Constr({
"volume" : -10
});
expect(instance.volume.value).to.be.closeTo(-10, 0.1);
instance.dispose();
});
it("makes a sound", function(done){
var instance;
OutputAudio(function(dest){
instance = new Constr();
instance.connect(dest);
instance.triggerAttack(note);
}, function(){
instance.dispose();
done();
});
});
it("produces sound in both channels", function(done){
var instance;
OutputAudioStereo(function(dest){
instance = new Constr();
instance.connect(dest);
instance.triggerAttack(note);
}, function(){
instance.dispose();
done();
});
});
it("be scheduled to start in the future", function(done){
var instance;
var meter = new Meter(0.3);
meter.before(function(dest){
instance = new Constr();
instance.connect(dest);
if (note){
instance.triggerAttack(note, 0.1);
} else {
instance.triggerAttack(0.1);
}
});
meter.test(function(sample, time){
if (sample > 0){
expect(time).to.be.at.least(0.1);
}
});
meter.after(function(){
instance.dispose();
done();
});
meter.run();
});
});
};
});

View file

@ -0,0 +1,54 @@
define(["Tone/instrument/AMSynth", "helper/Basic", "helper/InstrumentTests"], function (AMSynth, Basic, InstrumentTest) {
describe("AMSynth", function(){
Basic(AMSynth);
InstrumentTest(AMSynth, "C4");
context("API", function(){
it ("can get and set carrier attributes", function(){
var amSynth = new AMSynth();
amSynth.carrier.oscillator.type = "triangle";
expect(amSynth.carrier.oscillator.type).to.equal("triangle");
amSynth.dispose();
});
it ("can get and set modulator attributes", function(){
var amSynth = new AMSynth();
amSynth.modulator.envelope.attack = 0.24;
expect(amSynth.modulator.envelope.attack).to.equal(0.24);
amSynth.dispose();
});
it ("can get and set harmonicity", function(){
var amSynth = new AMSynth();
amSynth.harmonicity.value = 2;
expect(amSynth.harmonicity.value).to.equal(2);
amSynth.dispose();
});
it ("can be constructed with an options object", function(){
var amSynth = new AMSynth({
"carrier" : {
"filter" : {
"rolloff" : -24
}
}
});
expect(amSynth.carrier.filter.rolloff).to.equal(-24);
amSynth.dispose();
});
it ("can get/set attributes", function(){
var amSynth = new AMSynth();
amSynth.set({
"harmonicity" : 1.5
});
expect(amSynth.get().harmonicity).to.equal(1.5);
amSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,54 @@
define(["Tone/instrument/DrumSynth", "helper/Basic", "helper/InstrumentTests"], function (DrumSynth, Basic, InstrumentTest) {
describe("DrumSynth", function(){
Basic(DrumSynth);
InstrumentTest(DrumSynth, "C2");
context("API", function(){
it ("can get and set oscillator attributes", function(){
var drumSynth = new DrumSynth();
drumSynth.oscillator.type = "triangle";
expect(drumSynth.oscillator.type).to.equal("triangle");
drumSynth.dispose();
});
it ("can get and set envelope attributes", function(){
var drumSynth = new DrumSynth();
drumSynth.envelope.attack = 0.24;
expect(drumSynth.envelope.attack).to.equal(0.24);
drumSynth.dispose();
});
it ("can get and set the octaves and pitch decay", function(){
var drumSynth = new DrumSynth();
drumSynth.octaves = 12;
drumSynth.pitchDecay = 0.2;
expect(drumSynth.pitchDecay).to.equal(0.2);
expect(drumSynth.octaves).to.equal(12);
drumSynth.dispose();
});
it ("can be constructed with an options object", function(){
var drumSynth = new DrumSynth({
"envelope" : {
"sustain" : 0.3
}
});
expect(drumSynth.envelope.sustain).to.equal(0.3);
drumSynth.dispose();
});
it ("can get/set attributes", function(){
var drumSynth = new DrumSynth();
drumSynth.set({
"envelope.decay" : 0.24
});
expect(drumSynth.get().envelope.decay).to.equal(0.24);
drumSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,61 @@
define(["Tone/instrument/DuoSynth", "helper/Basic", "helper/InstrumentTests"], function (DuoSynth, Basic, InstrumentTest) {
describe("DuoSynth", function(){
Basic(DuoSynth);
InstrumentTest(DuoSynth, "C4");
context("API", function(){
it ("can get and set voice0 attributes", function(){
var duoSynth = new DuoSynth();
duoSynth.voice0.oscillator.type = "triangle";
expect(duoSynth.voice0.oscillator.type).to.equal("triangle");
duoSynth.dispose();
});
it ("can get and set voice1 attributes", function(){
var duoSynth = new DuoSynth();
duoSynth.voice1.envelope.attack = 0.24;
expect(duoSynth.voice1.envelope.attack).to.equal(0.24);
duoSynth.dispose();
});
it ("can get and set harmonicity", function(){
var duoSynth = new DuoSynth();
duoSynth.harmonicity.value = 2;
expect(duoSynth.harmonicity.value).to.equal(2);
duoSynth.dispose();
});
it ("can get and set vibratoRate", function(){
var duoSynth = new DuoSynth();
duoSynth.vibratoRate.value = 2;
expect(duoSynth.vibratoRate.value).to.equal(2);
duoSynth.dispose();
});
it ("can be constructed with an options object", function(){
var duoSynth = new DuoSynth({
"voice0" : {
"filter" : {
"rolloff" : -24
}
}
});
expect(duoSynth.voice0.filter.rolloff).to.equal(-24);
duoSynth.dispose();
});
it ("can get/set attributes", function(){
var duoSynth = new DuoSynth();
duoSynth.set({
"harmonicity" : 1.5
});
expect(duoSynth.get().harmonicity).to.equal(1.5);
duoSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,54 @@
define(["Tone/instrument/FMSynth", "helper/Basic", "helper/InstrumentTests"], function (FMSynth, Basic, InstrumentTest) {
describe("FMSynth", function(){
Basic(FMSynth);
InstrumentTest(FMSynth, "C4");
context("API", function(){
it ("can get and set carrier attributes", function(){
var fmSynth = new FMSynth();
fmSynth.carrier.oscillator.type = "triangle";
expect(fmSynth.carrier.oscillator.type).to.equal("triangle");
fmSynth.dispose();
});
it ("can get and set modulator attributes", function(){
var fmSynth = new FMSynth();
fmSynth.modulator.envelope.attack = 0.24;
expect(fmSynth.modulator.envelope.attack).to.equal(0.24);
fmSynth.dispose();
});
it ("can get and set harmonicity", function(){
var fmSynth = new FMSynth();
fmSynth.harmonicity.value = 2;
expect(fmSynth.harmonicity.value).to.equal(2);
fmSynth.dispose();
});
it ("can be constructed with an options object", function(){
var fmSynth = new FMSynth({
"carrier" : {
"filter" : {
"rolloff" : -24
}
}
});
expect(fmSynth.carrier.filter.rolloff).to.equal(-24);
fmSynth.dispose();
});
it ("can get/set attributes", function(){
var fmSynth = new FMSynth();
fmSynth.set({
"harmonicity" : 1.5
});
expect(fmSynth.get().harmonicity).to.equal(1.5);
fmSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,27 @@
define(["Tone/instrument/Instrument", "helper/Basic"], function (Instrument, Basic) {
describe("Instrument", function(){
Basic(Instrument);
context("API", function(){
it ("can be constructed with an options object", function(){
var instr = new Instrument({
"volume" : -12
});
expect(instr.volume.value).to.be.closeTo(-12, 0.1);
instr.dispose();
});
it ("can get/set attributes", function(){
var instr = new Instrument();
instr.set({
"volume" : 2
});
expect(instr.get().volume).to.be.closeTo(2, 0.1);
});
});
});
});

View file

@ -0,0 +1,59 @@
define(["Tone/instrument/MonoSynth", "helper/Basic", "helper/InstrumentTests"], function (MonoSynth, Basic, InstrumentTest) {
describe("MonoSynth", function(){
Basic(MonoSynth);
InstrumentTest(MonoSynth, "C4");
context("API", function(){
it ("can get and set oscillator attributes", function(){
var monoSynth = new MonoSynth();
monoSynth.oscillator.type = "triangle";
expect(monoSynth.oscillator.type).to.equal("triangle");
monoSynth.dispose();
});
it ("can get and set envelope attributes", function(){
var monoSynth = new MonoSynth();
monoSynth.envelope.attack = 0.24;
expect(monoSynth.envelope.attack).to.equal(0.24);
monoSynth.dispose();
});
it ("can get and set filter attributes", function(){
var monoSynth = new MonoSynth();
monoSynth.filter.Q.value = 0.4;
expect(monoSynth.filter.Q.value).to.be.closeTo(0.4, 0.001);
monoSynth.dispose();
});
it ("can get and set filterEnvelope attributes", function(){
var monoSynth = new MonoSynth();
monoSynth.filterEnvelope.min = 400;
expect(monoSynth.filterEnvelope.min).to.equal(400);
monoSynth.dispose();
});
it ("can be constructed with an options object", function(){
var monoSynth = new MonoSynth({
"envelope" : {
"sustain" : 0.3
}
});
expect(monoSynth.envelope.sustain).to.equal(0.3);
monoSynth.dispose();
});
it ("can get/set attributes", function(){
var monoSynth = new MonoSynth();
monoSynth.set({
"envelope.decay" : 0.24
});
expect(monoSynth.get().envelope.decay).to.equal(0.24);
monoSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,26 @@
define(["Tone/instrument/Monophonic", "helper/Basic"], function (Monophonic, Basic) {
describe("Monophonic", function(){
Basic(Monophonic);
context("API", function(){
it ("can be constructed with an options object", function(){
var instr = new Monophonic({
"portamento" : 0.2
});
expect(instr.portamento).to.equal(0.2);
instr.dispose();
});
it ("set the portamento", function(){
var instr = new Monophonic();
instr.portamento = 0.4;
expect(instr.portamento).to.equal(0.4);
instr.dispose();
});
});
});
});

View file

@ -0,0 +1,59 @@
define(["Tone/instrument/NoiseSynth", "helper/Basic", "helper/InstrumentTests"], function (NoiseSynth, Basic, InstrumentTest) {
describe("NoiseSynth", function(){
Basic(NoiseSynth);
InstrumentTest(NoiseSynth);
context("API", function(){
it ("can get and set noise type", function(){
var noiseSynth = new NoiseSynth();
noiseSynth.noise.type = "pink";
expect(noiseSynth.noise.type).to.equal("pink");
noiseSynth.dispose();
});
it ("can get and set envelope attributes", function(){
var noiseSynth = new NoiseSynth();
noiseSynth.envelope.attack = 0.24;
expect(noiseSynth.envelope.attack).to.equal(0.24);
noiseSynth.dispose();
});
it ("can get and set filter attributes", function(){
var noiseSynth = new NoiseSynth();
noiseSynth.filter.Q.value = 0.4;
expect(noiseSynth.filter.Q.value).to.be.closeTo(0.4, 0.001);
noiseSynth.dispose();
});
it ("can get and set filterEnvelope attributes", function(){
var noiseSynth = new NoiseSynth();
noiseSynth.filterEnvelope.min = 400;
expect(noiseSynth.filterEnvelope.min).to.equal(400);
noiseSynth.dispose();
});
it ("can be constructed with an options object", function(){
var noiseSynth = new NoiseSynth({
"envelope" : {
"sustain" : 0.3
}
});
expect(noiseSynth.envelope.sustain).to.equal(0.3);
noiseSynth.dispose();
});
it ("can get/set attributes", function(){
var noiseSynth = new NoiseSynth();
noiseSynth.set({
"envelope.decay" : 0.24
});
expect(noiseSynth.get().envelope.decay).to.equal(0.24);
noiseSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,49 @@
define(["Tone/instrument/PluckSynth", "helper/Basic", "helper/InstrumentTests"], function (PluckSynth, Basic, InstrumentTest) {
describe("PluckSynth", function(){
Basic(PluckSynth);
InstrumentTest(PluckSynth, "C3");
context("API", function(){
it ("can get and set resonance", function(){
var pluck = new PluckSynth();
pluck.resonance.value = 0.4;
expect(pluck.resonance.value).to.be.closeTo(0.4, 0.001);
pluck.dispose();
});
it ("can get and set dampening", function(){
var pluck = new PluckSynth();
pluck.dampening.value = 2000;
expect(pluck.dampening.value).to.be.closeTo(2000, 0.1);
pluck.dispose();
});
it ("can get and set the attackNoise", function(){
var pluck = new PluckSynth();
pluck.attackNoise = 0.2;
expect(pluck.attackNoise).to.be.closeTo(0.2, 0.1);
pluck.dispose();
});
it ("can be constructed with an options object", function(){
var pluck = new PluckSynth({
"dampening" : 300
});
expect(pluck.dampening.value).to.be.closeTo(300, 0.1);
pluck.dispose();
});
it ("can be constructed with an options object", function(){
var pluck = new PluckSynth({
"resonance" : 0.5
});
expect(pluck.resonance.value).to.be.closeTo(0.5, 0.001);
pluck.dispose();
});
});
});
});

View file

@ -0,0 +1,54 @@
define(["Tone/instrument/SimpleAM", "helper/Basic", "helper/InstrumentTests"], function (SimpleAM, Basic, InstrumentTest) {
describe("SimpleAM", function(){
Basic(SimpleAM);
InstrumentTest(SimpleAM, "C4");
context("API", function(){
it ("can get and set carrier attributes", function(){
var amSynth = new SimpleAM();
amSynth.carrier.oscillator.type = "triangle";
expect(amSynth.carrier.oscillator.type).to.equal("triangle");
amSynth.dispose();
});
it ("can get and set modulator attributes", function(){
var amSynth = new SimpleAM();
amSynth.modulator.envelope.attack = 0.24;
expect(amSynth.modulator.envelope.attack).to.equal(0.24);
amSynth.dispose();
});
it ("can get and set harmonicity", function(){
var amSynth = new SimpleAM();
amSynth.harmonicity.value = 2;
expect(amSynth.harmonicity.value).to.equal(2);
amSynth.dispose();
});
it ("can be constructed with an options object", function(){
var amSynth = new SimpleAM({
"carrier" : {
"oscillator" : {
"type" : "square2"
}
}
});
expect(amSynth.carrier.oscillator.type).to.equal("square2");
amSynth.dispose();
});
it ("can get/set attributes", function(){
var amSynth = new SimpleAM();
amSynth.set({
"harmonicity" : 1.5
});
expect(amSynth.get().harmonicity).to.equal(1.5);
amSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,54 @@
define(["Tone/instrument/SimpleFM", "helper/Basic", "helper/InstrumentTests"], function (SimpleFM, Basic, InstrumentTest) {
describe("SimpleFM", function(){
Basic(SimpleFM);
InstrumentTest(SimpleFM, "C4");
context("API", function(){
it ("can get and set carrier attributes", function(){
var fmSynth = new SimpleFM();
fmSynth.carrier.oscillator.type = "triangle";
expect(fmSynth.carrier.oscillator.type).to.equal("triangle");
fmSynth.dispose();
});
it ("can get and set modulator attributes", function(){
var fmSynth = new SimpleFM();
fmSynth.modulator.envelope.attack = 0.24;
expect(fmSynth.modulator.envelope.attack).to.equal(0.24);
fmSynth.dispose();
});
it ("can get and set harmonicity", function(){
var fmSynth = new SimpleFM();
fmSynth.harmonicity.value = 2;
expect(fmSynth.harmonicity.value).to.equal(2);
fmSynth.dispose();
});
it ("can be constructed with an options object", function(){
var fmSynth = new SimpleFM({
"carrier" : {
"oscillator" : {
"type" : "square2"
}
}
});
expect(fmSynth.carrier.oscillator.type).to.equal("square2");
fmSynth.dispose();
});
it ("can get/set attributes", function(){
var fmSynth = new SimpleFM();
fmSynth.set({
"harmonicity" : 1.5
});
expect(fmSynth.get().harmonicity).to.equal(1.5);
fmSynth.dispose();
});
});
});
});

View file

@ -0,0 +1,45 @@
define(["Tone/instrument/SimpleSynth", "helper/Basic", "helper/InstrumentTests"], function (SimpleSynth, Basic, InstrumentTest) {
describe("SimpleSynth", function(){
Basic(SimpleSynth);
InstrumentTest(SimpleSynth, "C4");
context("API", function(){
it ("can get and set oscillator attributes", function(){
var simple = new SimpleSynth();
simple.oscillator.type = "triangle";
expect(simple.oscillator.type).to.equal("triangle");
simple.dispose();
});
it ("can get and set envelope attributes", function(){
var simple = new SimpleSynth();
simple.envelope.attack = 0.24;
expect(simple.envelope.attack).to.equal(0.24);
simple.dispose();
});
it ("can be constructed with an options object", function(){
var simple = new SimpleSynth({
"envelope" : {
"sustain" : 0.3
}
});
expect(simple.envelope.sustain).to.equal(0.3);
simple.dispose();
});
it ("can get/set attributes", function(){
var simple = new SimpleSynth();
simple.set({
"envelope.decay" : 0.24
});
expect(simple.get().envelope.decay).to.equal(0.24);
simple.dispose();
});
});
});
});