mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
DrumSynth->MembraneSynth & CymbalSynth->MetalSynth
This commit is contained in:
parent
83591cf95b
commit
2f4d6d07cd
4 changed files with 52 additions and 52 deletions
|
@ -5,11 +5,11 @@ function(Tone){
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* @class Tone.DrumSynth makes kick and tom sounds using a single oscillator
|
||||
* @class Tone.MembraneSynth makes kick and tom sounds using a single oscillator
|
||||
* with an amplitude envelope and frequency ramp. A Tone.Oscillator
|
||||
* is routed through a Tone.AmplitudeEnvelope to the output. The drum
|
||||
* quality of the sound comes from the frequency envelope applied
|
||||
* during during Tone.DrumSynth.triggerAttack(note). The frequency
|
||||
* during during Tone.MembraneSynth.triggerAttack(note). The frequency
|
||||
* envelope starts at <code>note * .octaves</code> and ramps to
|
||||
* <code>note</code> over the duration of <code>.pitchDecay</code>.
|
||||
*
|
||||
|
@ -18,12 +18,12 @@ function(Tone){
|
|||
* @param {Object} [options] the options available for the synth
|
||||
* see defaults below
|
||||
* @example
|
||||
* var synth = new Tone.DrumSynth().toMaster();
|
||||
* var synth = new Tone.MembraneSynth().toMaster();
|
||||
* synth.triggerAttackRelease("C2", "8n");
|
||||
*/
|
||||
Tone.DrumSynth = function(options){
|
||||
Tone.MembraneSynth = function(options){
|
||||
|
||||
options = this.defaultArg(options, Tone.DrumSynth.defaults);
|
||||
options = this.defaultArg(options, Tone.MembraneSynth.defaults);
|
||||
Tone.Instrument.call(this, options);
|
||||
|
||||
/**
|
||||
|
@ -54,13 +54,13 @@ function(Tone){
|
|||
this._readOnly(["oscillator", "envelope"]);
|
||||
};
|
||||
|
||||
Tone.extend(Tone.DrumSynth, Tone.Instrument);
|
||||
Tone.extend(Tone.MembraneSynth, Tone.Instrument);
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @type {Object}
|
||||
*/
|
||||
Tone.DrumSynth.defaults = {
|
||||
Tone.MembraneSynth.defaults = {
|
||||
"pitchDecay" : 0.05,
|
||||
"octaves" : 10,
|
||||
"oscillator" : {
|
||||
|
@ -81,11 +81,11 @@ function(Tone){
|
|||
* @param {Frequency} note the note
|
||||
* @param {Time} [time=now] the time, if not given is now
|
||||
* @param {number} [velocity=1] velocity defaults to 1
|
||||
* @returns {Tone.DrumSynth} this
|
||||
* @returns {Tone.MembraneSynth} this
|
||||
* @example
|
||||
* kick.triggerAttack(60);
|
||||
*/
|
||||
Tone.DrumSynth.prototype.triggerAttack = function(note, time, velocity) {
|
||||
Tone.MembraneSynth.prototype.triggerAttack = function(note, time, velocity) {
|
||||
time = this.toSeconds(time);
|
||||
note = this.toFrequency(note);
|
||||
var maxNote = note * this.octaves;
|
||||
|
@ -99,18 +99,18 @@ function(Tone){
|
|||
* Trigger the release portion of the note.
|
||||
*
|
||||
* @param {Time} [time=now] the time the note will release
|
||||
* @returns {Tone.DrumSynth} this
|
||||
* @returns {Tone.MembraneSynth} this
|
||||
*/
|
||||
Tone.DrumSynth.prototype.triggerRelease = function(time){
|
||||
Tone.MembraneSynth.prototype.triggerRelease = function(time){
|
||||
this.envelope.triggerRelease(time);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Clean up.
|
||||
* @returns {Tone.DrumSynth} this
|
||||
* @returns {Tone.MembraneSynth} this
|
||||
*/
|
||||
Tone.DrumSynth.prototype.dispose = function(){
|
||||
Tone.MembraneSynth.prototype.dispose = function(){
|
||||
Tone.Instrument.prototype.dispose.call(this);
|
||||
this._writable(["oscillator", "envelope"]);
|
||||
this.oscillator.dispose();
|
||||
|
@ -120,5 +120,5 @@ function(Tone){
|
|||
return this;
|
||||
};
|
||||
|
||||
return Tone.DrumSynth;
|
||||
return Tone.MembraneSynth;
|
||||
});
|
|
@ -22,9 +22,9 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
* @param {Object} [options] The options availble for the synth
|
||||
* see defaults below
|
||||
*/
|
||||
Tone.CymbalSynth = function(options){
|
||||
Tone.MetalSynth = function(options){
|
||||
|
||||
options = this.defaultArg(options, Tone.CymbalSynth.defaults);
|
||||
options = this.defaultArg(options, Tone.MetalSynth.defaults);
|
||||
Tone.Instrument.call(this, options);
|
||||
|
||||
/**
|
||||
|
@ -115,7 +115,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
|
||||
};
|
||||
|
||||
Tone.extend(Tone.CymbalSynth, Tone.Instrument);
|
||||
Tone.extend(Tone.MetalSynth, Tone.Instrument);
|
||||
|
||||
/**
|
||||
* default values
|
||||
|
@ -123,7 +123,7 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
* @const
|
||||
* @type {Object}
|
||||
*/
|
||||
Tone.CymbalSynth.defaults = {
|
||||
Tone.MetalSynth.defaults = {
|
||||
"frequency" : 200,
|
||||
"envelope" : {
|
||||
"attack" : 0.0015,
|
||||
|
@ -140,9 +140,9 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
* Trigger the attack.
|
||||
* @param {Time} time When the attack should be triggered.
|
||||
* @param {NormalRange=1} velocity The velocity that the envelope should be triggered at.
|
||||
* @return {Tone.CymbalSynth} this
|
||||
* @return {Tone.MetalSynth} this
|
||||
*/
|
||||
Tone.CymbalSynth.prototype.triggerAttack = function(time, vel) {
|
||||
Tone.MetalSynth.prototype.triggerAttack = function(time, vel) {
|
||||
time = this.toSeconds(time);
|
||||
vel = this.defaultArg(vel, 1);
|
||||
this.envelope.triggerAttack(time, vel);
|
||||
|
@ -152,9 +152,9 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
/**
|
||||
* Trigger the release of the envelope.
|
||||
* @param {Time} time When the release should be triggered.
|
||||
* @return {Tone.CymbalSynth} this
|
||||
* @return {Tone.MetalSynth} this
|
||||
*/
|
||||
Tone.CymbalSynth.prototype.triggerRelease = function(time) {
|
||||
Tone.MetalSynth.prototype.triggerRelease = function(time) {
|
||||
time = this.toSeconds(time);
|
||||
this.envelope.triggerRelease(time);
|
||||
return this;
|
||||
|
@ -166,9 +166,9 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
* @param {Time} duration The duration before triggering the release
|
||||
* @param {Time} time When the attack should be triggered.
|
||||
* @param {NormalRange=1} velocity The velocity that the envelope should be triggered at.
|
||||
* @return {Tone.CymbalSynth} this
|
||||
* @return {Tone.MetalSynth} this
|
||||
*/
|
||||
Tone.CymbalSynth.prototype.triggerAttackRelease = function(duration, time, velocity) {
|
||||
Tone.MetalSynth.prototype.triggerAttackRelease = function(duration, time, velocity) {
|
||||
var now = this.now();
|
||||
time = this.toSeconds(time, now);
|
||||
duration = this.toSeconds(duration, now);
|
||||
|
@ -180,11 +180,11 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
/**
|
||||
* The modulationIndex of the oscillators which make up the source.
|
||||
* see Tone.FMOscillator.modulationIndex
|
||||
* @memberOf Tone.CymbalSynth#
|
||||
* @memberOf Tone.MetalSynth#
|
||||
* @type {Positive}
|
||||
* @name modulationIndex
|
||||
*/
|
||||
Object.defineProperty(Tone.CymbalSynth.prototype, "modulationIndex", {
|
||||
Object.defineProperty(Tone.MetalSynth.prototype, "modulationIndex", {
|
||||
get : function(){
|
||||
return this._oscillators[0].modulationIndex.value;
|
||||
},
|
||||
|
@ -198,11 +198,11 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
/**
|
||||
* The harmonicity of the oscillators which make up the source.
|
||||
* see Tone.FMOscillator.harmonicity
|
||||
* @memberOf Tone.CymbalSynth#
|
||||
* @memberOf Tone.MetalSynth#
|
||||
* @type {Positive}
|
||||
* @name harmonicity
|
||||
*/
|
||||
Object.defineProperty(Tone.CymbalSynth.prototype, "harmonicity", {
|
||||
Object.defineProperty(Tone.MetalSynth.prototype, "harmonicity", {
|
||||
get : function(){
|
||||
return this._oscillators[0].harmonicity.value;
|
||||
},
|
||||
|
@ -215,11 +215,11 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
|
||||
/**
|
||||
* The frequency of the highpass filter attached to the envelope
|
||||
* @memberOf Tone.CymbalSynth#
|
||||
* @memberOf Tone.MetalSynth#
|
||||
* @type {Frequency}
|
||||
* @name resonance
|
||||
*/
|
||||
Object.defineProperty(Tone.CymbalSynth.prototype, "resonance", {
|
||||
Object.defineProperty(Tone.MetalSynth.prototype, "resonance", {
|
||||
get : function(){
|
||||
return this._filterFreqScaler.min;
|
||||
},
|
||||
|
@ -232,11 +232,11 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
/**
|
||||
* The number of octaves above the "resonance" frequency
|
||||
* that the filter ramps during the attack/decay envelope
|
||||
* @memberOf Tone.CymbalSynth#
|
||||
* @memberOf Tone.MetalSynth#
|
||||
* @type {Number}
|
||||
* @name octaves
|
||||
*/
|
||||
Object.defineProperty(Tone.CymbalSynth.prototype, "octaves", {
|
||||
Object.defineProperty(Tone.MetalSynth.prototype, "octaves", {
|
||||
get : function(){
|
||||
return this._octaves;
|
||||
},
|
||||
|
@ -248,9 +248,9 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
|
||||
/**
|
||||
* Clean up
|
||||
* @returns {Tone.CymbalSynth} this
|
||||
* @returns {Tone.MetalSynth} this
|
||||
*/
|
||||
Tone.CymbalSynth.prototype.dispose = function(){
|
||||
Tone.MetalSynth.prototype.dispose = function(){
|
||||
Tone.Instrument.prototype.dispose.call(this);
|
||||
for (var i = 0; i < this._oscillators.length; i++){
|
||||
this._oscillators[i].dispose();
|
||||
|
@ -270,5 +270,5 @@ define(["Tone/core/Tone", "Tone/instrument/Instrument", "Tone/source/FMOscillato
|
|||
this._highpass = null;
|
||||
};
|
||||
|
||||
return Tone.CymbalSynth;
|
||||
return Tone.MetalSynth;
|
||||
});
|
|
@ -1,28 +1,28 @@
|
|||
define(["Tone/instrument/DrumSynth", "helper/Basic", "helper/InstrumentTests"], function (DrumSynth, Basic, InstrumentTest) {
|
||||
define(["Tone/instrument/MembraneSynth", "helper/Basic", "helper/InstrumentTests"], function (MembraneSynth, Basic, InstrumentTest) {
|
||||
|
||||
describe("DrumSynth", function(){
|
||||
describe("MembraneSynth", function(){
|
||||
|
||||
Basic(DrumSynth);
|
||||
InstrumentTest(DrumSynth, "C2");
|
||||
Basic(MembraneSynth);
|
||||
InstrumentTest(MembraneSynth, "C2");
|
||||
|
||||
context("API", function(){
|
||||
|
||||
it ("can get and set oscillator attributes", function(){
|
||||
var drumSynth = new DrumSynth();
|
||||
var drumSynth = new MembraneSynth();
|
||||
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();
|
||||
var drumSynth = new MembraneSynth();
|
||||
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();
|
||||
var drumSynth = new MembraneSynth();
|
||||
drumSynth.octaves = 12;
|
||||
drumSynth.pitchDecay = 0.2;
|
||||
expect(drumSynth.pitchDecay).to.equal(0.2);
|
||||
|
@ -31,7 +31,7 @@ define(["Tone/instrument/DrumSynth", "helper/Basic", "helper/InstrumentTests"],
|
|||
});
|
||||
|
||||
it ("can be constructed with an options object", function(){
|
||||
var drumSynth = new DrumSynth({
|
||||
var drumSynth = new MembraneSynth({
|
||||
"envelope" : {
|
||||
"sustain" : 0.3
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ define(["Tone/instrument/DrumSynth", "helper/Basic", "helper/InstrumentTests"],
|
|||
});
|
||||
|
||||
it ("can get/set attributes", function(){
|
||||
var drumSynth = new DrumSynth();
|
||||
var drumSynth = new MembraneSynth();
|
||||
drumSynth.set({
|
||||
"envelope.decay" : 0.24
|
||||
});
|
|
@ -1,14 +1,14 @@
|
|||
define(["Tone/instrument/CymbalSynth", "helper/Basic", "helper/InstrumentTests"], function (CymbalSynth, Basic, InstrumentTest) {
|
||||
define(["Tone/instrument/MetalSynth", "helper/Basic", "helper/InstrumentTests"], function (MetalSynth, Basic, InstrumentTest) {
|
||||
|
||||
describe("CymbalSynth", function(){
|
||||
describe("MetalSynth", function(){
|
||||
|
||||
Basic(CymbalSynth);
|
||||
InstrumentTest(CymbalSynth);
|
||||
Basic(MetalSynth);
|
||||
InstrumentTest(MetalSynth);
|
||||
|
||||
context("API", function(){
|
||||
|
||||
it ("can be constructed with octave and harmonicity values", function(){
|
||||
var cymbal = new CymbalSynth({
|
||||
var cymbal = new MetalSynth({
|
||||
"octaves" : 0.4,
|
||||
"resonance" : 2300,
|
||||
"harmonicity" : 3.1
|
||||
|
@ -20,7 +20,7 @@ define(["Tone/instrument/CymbalSynth", "helper/Basic", "helper/InstrumentTests"]
|
|||
});
|
||||
|
||||
it ("can get and set envelope attributes", function(){
|
||||
var cymbal = new CymbalSynth();
|
||||
var cymbal = new MetalSynth();
|
||||
cymbal.envelope.attack = 0.024;
|
||||
cymbal.envelope.decay = 0.9;
|
||||
expect(cymbal.envelope.attack).to.equal(0.024);
|
||||
|
@ -29,14 +29,14 @@ define(["Tone/instrument/CymbalSynth", "helper/Basic", "helper/InstrumentTests"]
|
|||
});
|
||||
|
||||
it ("can set the modulationIndex", function(){
|
||||
var cymbal = new CymbalSynth();
|
||||
var cymbal = new MetalSynth();
|
||||
cymbal.modulationIndex = 82;
|
||||
expect(cymbal.modulationIndex).to.be.closeTo(82, 0.01);
|
||||
cymbal.dispose();
|
||||
});
|
||||
|
||||
it ("can get/set attributes", function(){
|
||||
var cymbal = new CymbalSynth();
|
||||
var cymbal = new MetalSynth();
|
||||
cymbal.set({
|
||||
"frequency" : 120
|
||||
});
|
Loading…
Reference in a new issue