Tone.js/test/effect/Tremolo.js

80 lines
2.2 KiB
JavaScript
Raw Normal View History

import Tremolo from "Tone/effect/Tremolo";
import Basic from "helper/Basic";
import EffectTests from "helper/EffectTests";
import Offline from "helper/Offline";
2017-12-29 18:48:16 +00:00
describe("Tremolo", function(){
Basic(Tremolo);
EffectTests(Tremolo);
2015-08-26 14:29:35 +00:00
context("API", function(){
2015-08-26 14:29:35 +00:00
it("can pass in options in the constructor", function(){
var tremolo = new Tremolo({
"depth" : 0.2,
"type" : "sawtooth",
"spread" : 160,
});
expect(tremolo.depth.value).to.be.closeTo(0.2, 0.001);
expect(tremolo.type).to.equal("sawtooth");
expect(tremolo.spread).to.equal(160);
tremolo.dispose();
});
2015-08-26 14:29:35 +00:00
it("can be started and stopped", function(){
var tremolo = new Tremolo();
tremolo.start().stop("+0.2");
tremolo.dispose();
});
2015-08-26 14:29:35 +00:00
it("can get/set the options", function(){
var tremolo = new Tremolo();
tremolo.set({
"frequency" : 2.4,
"type" : "triangle"
});
expect(tremolo.get().frequency).to.be.closeTo(2.4, 0.01);
expect(tremolo.get().type).to.equal("triangle");
tremolo.dispose();
});
2015-08-26 14:29:35 +00:00
it("can set the frequency and depth", function(){
var tremolo = new Tremolo();
tremolo.depth.value = 0.4;
tremolo.frequency.value = 0.4;
expect(tremolo.depth.value).to.be.closeTo(0.4, 0.01);
expect(tremolo.frequency.value).to.be.closeTo(0.4, 0.01);
tremolo.dispose();
});
2017-12-29 18:48:16 +00:00
it("can sync the frequency to the Transport", function(){
2017-12-29 18:48:16 +00:00
return Offline(function(Transport){
var tremolo = new Tremolo(2);
tremolo.sync();
tremolo.frequency.toMaster();
Transport.bpm.setValueAtTime(Transport.bpm.value * 2, 0.05);
// Transport.start(0)
}, 0.1).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
expect(buffer.getValueAtTime(0.05)).to.be.closeTo(4, 0.1);
});
});
2017-12-29 18:48:16 +00:00
it("can unsync the frequency to the Transport", function(){
2017-12-29 18:48:16 +00:00
return Offline(function(Transport){
var tremolo = new Tremolo(2);
tremolo.sync();
tremolo.frequency.toMaster();
Transport.bpm.setValueAtTime(Transport.bpm.value * 2, 0.05);
tremolo.unsync();
}, 0.1).then(function(buffer){
expect(buffer.getValueAtTime(0)).to.be.closeTo(2, 0.1);
expect(buffer.getValueAtTime(0.05)).to.be.closeTo(2, 0.1);
2017-12-29 18:48:16 +00:00
});
2015-08-26 14:29:35 +00:00
});
});
});