2018-02-05 18:55:37 +00:00
|
|
|
define(["Tone/instrument/FMSynth", "helper/Basic",
|
2018-02-05 19:59:40 +00:00
|
|
|
"helper/InstrumentTests", "helper/CompareToFile", "helper/Supports"],
|
2018-04-25 14:51:46 +00:00
|
|
|
function(FMSynth, Basic, InstrumentTest, CompareToFile, Supports){
|
2015-08-31 15:37:10 +00:00
|
|
|
|
|
|
|
describe("FMSynth", function(){
|
|
|
|
|
|
|
|
Basic(FMSynth);
|
|
|
|
InstrumentTest(FMSynth, "C4");
|
|
|
|
|
2018-02-05 19:59:40 +00:00
|
|
|
if (Supports.CHROME_AUDIO_RENDERING){
|
|
|
|
it("matches a file", function(){
|
|
|
|
return CompareToFile(function(){
|
2018-06-02 02:02:05 +00:00
|
|
|
var synth = new FMSynth().toMaster();
|
2018-02-05 19:59:40 +00:00
|
|
|
synth.triggerAttackRelease("G4", 0.1, 0.05);
|
2018-05-28 22:01:03 +00:00
|
|
|
}, "fmSynth.wav", 0.1);
|
2018-02-05 19:59:40 +00:00
|
|
|
});
|
|
|
|
}
|
2018-02-05 18:55:37 +00:00
|
|
|
|
2015-08-31 15:37:10 +00:00
|
|
|
context("API", function(){
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can get and set carrier attributes", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
var fmSynth = new FMSynth();
|
2016-01-30 20:53:40 +00:00
|
|
|
fmSynth.oscillator.type = "triangle";
|
|
|
|
expect(fmSynth.oscillator.type).to.equal("triangle");
|
2015-08-31 15:37:10 +00:00
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can get and set modulator attributes", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
var fmSynth = new FMSynth();
|
2016-01-30 20:53:40 +00:00
|
|
|
fmSynth.modulationEnvelope.attack = 0.24;
|
|
|
|
expect(fmSynth.modulationEnvelope.attack).to.equal(0.24);
|
2015-08-31 15:37:10 +00:00
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can get and set harmonicity", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
var fmSynth = new FMSynth();
|
|
|
|
fmSynth.harmonicity.value = 2;
|
|
|
|
expect(fmSynth.harmonicity.value).to.equal(2);
|
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can be constructed with an options object", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
var fmSynth = new FMSynth({
|
2016-01-30 20:53:40 +00:00
|
|
|
"envelope" : {
|
|
|
|
"release" : 0.3
|
2015-08-31 15:37:10 +00:00
|
|
|
}
|
|
|
|
});
|
2016-01-30 20:53:40 +00:00
|
|
|
expect(fmSynth.envelope.release).to.equal(0.3);
|
2015-08-31 15:37:10 +00:00
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
2017-12-30 16:26:29 +00:00
|
|
|
it("can get/set attributes", function(){
|
2015-08-31 15:37:10 +00:00
|
|
|
var fmSynth = new FMSynth();
|
|
|
|
fmSynth.set({
|
2016-05-15 00:10:31 +00:00
|
|
|
"harmonicity" : 1.5,
|
|
|
|
"detune" : 1200,
|
2015-08-31 15:37:10 +00:00
|
|
|
});
|
|
|
|
expect(fmSynth.get().harmonicity).to.equal(1.5);
|
2016-05-15 00:10:31 +00:00
|
|
|
expect(fmSynth.get().detune).to.be.closeTo(1200, 1);
|
2015-08-31 15:37:10 +00:00
|
|
|
fmSynth.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
2017-12-30 16:26:29 +00:00
|
|
|
});
|