docs: adding more elaborate examples and explainations

This commit is contained in:
Yotam Mann 2019-10-29 14:51:29 -04:00
parent 1f298914fc
commit bc08a1aea9
2 changed files with 32 additions and 11 deletions

View file

@ -22,14 +22,6 @@ export abstract class AbstractParam<TypeName extends UnitName> {
* Get the signals value at the given time. Subsequent scheduling * Get the signals value at the given time. Subsequent scheduling
* may invalidate the returned value. * may invalidate the returned value.
* @param time When to get the value * @param time When to get the value
*/
abstract getValueAtTime(time: Time): UnitMap[TypeName];
/**
* Creates a schedule point with the current value at the current time.
* This is useful for creating an automation anchor point in order to
* schedule changes from the current value.
* @param time When to add a ramp point.
* @example * @example
* import { now, Oscillator } from "tone"; * import { now, Oscillator } from "tone";
* const osc = new Oscillator().toDestination().start(); * const osc = new Oscillator().toDestination().start();
@ -40,6 +32,22 @@ export abstract class AbstractParam<TypeName extends UnitName> {
* osc.frequency.getValueAtTime(now()); * osc.frequency.getValueAtTime(now());
* }, 100); * }, 100);
*/ */
abstract getValueAtTime(time: Time): UnitMap[TypeName];
/**
* Creates a schedule point with the current value at the current time.
* Automation methods like [[linearRampToValueAtTime]] and [[exponentialRampToValueAtTime]]
* require a starting automation value usually set by [[setValueAtTime]]. This method
* is useful since it will do a `setValueAtTime` with whatever the currently computed
* value at the given time is.
* @param time When to add a ramp point.
* @example
* import { Oscillator } from "tone";
* const osc = new Oscillator().toDestination().start();
* // set the frequency to "G4" in exactly 1 second from now.
* osc.frequency.setRampPoint("+1");
* osc.frequency.linearRampToValueAtTime("C1", "+2");
*/
abstract setRampPoint(time: Time): this; abstract setRampPoint(time: Time): this;
/** /**
@ -67,8 +75,8 @@ export abstract class AbstractParam<TypeName extends UnitName> {
* const delay = new FeedbackDelay(0.5, 0.98).toDestination(); * const delay = new FeedbackDelay(0.5, 0.98).toDestination();
* // a short burst of noise through the feedback delay * // a short burst of noise through the feedback delay
* const noise = new Noise().connect(delay).start().stop("+0.1"); * const noise = new Noise().connect(delay).start().stop("+0.1");
* // exponentially ramp to the value to 2 over 4 seconds. * // making the delay time shorter over time will also make the pitch rise
* delay.delayTime.exponentialRampTo(2, 4); * delay.delayTime.exponentialRampTo(0.01, 20);
*/ */
abstract exponentialRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this; abstract exponentialRampTo(value: UnitMap[TypeName], rampTime: Time, startTime?: Time): this;

View file

@ -31,7 +31,20 @@ export { AMOscillatorOptions } from "./OscillatorInterface";
* @example * @example
* import { AMOscillator } from "tone"; * import { AMOscillator } from "tone";
* // a sine oscillator amplitude-modulated by a square wave * // a sine oscillator amplitude-modulated by a square wave
* const amOsc = new AMOscillator("Ab3", "sine", "square").toDestination().start(); * const amOsc = new AMOscillator("Ab3", "sine", "square").toDestination().start().stop("+6");
* // schedule a series of notes
* amOsc.frequency.setValueAtTime("F3", "+0.25");
* amOsc.frequency.setValueAtTime("C4", "+0.5");
* amOsc.frequency.setValueAtTime("Bb3", "+1");
* amOsc.frequency.setValueAtTime("Ab3", "+2");
* // schedule harmonicity changes along with those notes
* amOsc.harmonicity.setValueAtTime(0.5, "+0.25");
* amOsc.harmonicity.setValueAtTime(2, "+0.5");
* amOsc.harmonicity.setValueAtTime(1.5, "+1");
* amOsc.harmonicity.setValueAtTime(1, "+2");
* amOsc.harmonicity.linearRampTo(1.1, 2, "+2");
* // fade it out all the way at the end
* amOsc.volume.exponentialRampTo(-Infinity, 3, "+3,");
* @category Source * @category Source
*/ */
export class AMOscillator extends Source<AMOscillatorOptions> implements ToneOscillatorInterface { export class AMOscillator extends Source<AMOscillatorOptions> implements ToneOscillatorInterface {