2019-01-27 18:05:20 +00:00
|
|
|
import MonoSynth from "Tone/instrument/MonoSynth";
|
|
|
|
import Basic from "helper/Basic";
|
|
|
|
import InstrumentTest from "helper/InstrumentTests";
|
|
|
|
import CompareToFile from "helper/CompareToFile";
|
|
|
|
import Supports from "helper/Supports";
|
|
|
|
import Offline from "helper/Offline";
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
describe("MonoSynth", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
Basic(MonoSynth);
|
|
|
|
InstrumentTest(MonoSynth, "C4");
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
if (Supports.CHROME_AUDIO_RENDERING){
|
|
|
|
it("matches a file", function(){
|
|
|
|
return CompareToFile(function(){
|
|
|
|
var synth = new MonoSynth().toMaster();
|
|
|
|
synth.triggerAttackRelease("C4", 0.1, 0.05);
|
|
|
|
}, "monoSynth.wav", 1.75);
|
|
|
|
});
|
|
|
|
}
|
2018-02-05 18:55:37 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
context("API", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
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();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
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();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
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();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can get and set filterEnvelope attributes", function(){
|
|
|
|
var monoSynth = new MonoSynth();
|
|
|
|
monoSynth.filterEnvelope.baseFrequency = 400;
|
|
|
|
expect(monoSynth.filterEnvelope.baseFrequency).to.equal(400);
|
|
|
|
monoSynth.dispose();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can be constructed with an options object", function(){
|
|
|
|
var monoSynth = new MonoSynth({
|
|
|
|
"envelope" : {
|
|
|
|
"sustain" : 0.3
|
|
|
|
}
|
2015-08-31 15:37:10 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(monoSynth.envelope.sustain).to.equal(0.3);
|
|
|
|
monoSynth.dispose();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("can get/set attributes", function(){
|
|
|
|
var monoSynth = new MonoSynth();
|
|
|
|
monoSynth.set({
|
|
|
|
"envelope.decay" : 0.24
|
2015-08-31 15:37:10 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
expect(monoSynth.get().envelope.decay).to.equal(0.24);
|
|
|
|
monoSynth.dispose();
|
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
|
2019-01-27 18:05:20 +00:00
|
|
|
it("is silent after triggerAttack if sustain is 0", function(){
|
|
|
|
return Offline(function(){
|
|
|
|
var synth = new MonoSynth({
|
|
|
|
envelope : {
|
|
|
|
attack : 0.1,
|
|
|
|
decay : 0.1,
|
|
|
|
sustain : 0,
|
|
|
|
}
|
|
|
|
}).toMaster();
|
|
|
|
synth.triggerAttack("C4", 0);
|
|
|
|
}, 0.5).then(function(buffer){
|
|
|
|
expect(buffer.getLastSoundTime()).to.be.closeTo(0.2, 0.01);
|
2018-03-05 15:57:39 +00:00
|
|
|
});
|
2015-08-31 15:37:10 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|
2015-08-31 15:37:10 +00:00
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|
2019-01-27 18:05:20 +00:00
|
|
|
|