Uses: Connectable Playable

A class that represents an oscillator for a synthesizer. Capable of creating and playing a waveform of specified type at a specified frequency.

All filters from BiquadFilterNode are available and can be enabled by providing a pojo for a given filter.

// 200Hz sine wave w/highpass at 600Hz and lowpass created but not filtering
const osc = audioService.createOscillator({
  frequency: 200,
  highpass: { frequency: 600 },
  lowpass: {}
});

// or
import { Oscillator } from 'ember-audio';
const audioContext = audioService.get('audioContext');
const osc = Oscillator.create({
  audioContext,
  frequency: 200,
  highpass: { frequency: 600 },
  lowpass: {}
});

Property Summary

Public Properties
public

Settings object for the allpass filter. The allpass filter is disabled if this is not provided. Accepts frequency, and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Settings object for the bandpass filter. The bandpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public
public

Determines the frequency of the wave output by the OscillatorNode instance. Corresponds directly to frequency.value from OscillatorNode

public

Determines the gain.value of the GainNode instance in the gain connection instance. Corresponds directly to gain.value from GainNode

public

Settings object for the highpass filter. The highpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Settings object for the highshelf filter. The highshelf filter is disabled if this is not provided. Accepts frequency and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public
public

Settings object for the lowpass filter. The lowpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Settings object for the lowshelf filter. The lowshelf filter is disabled if this is not provided. Accepts frequency and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Settings object for the notch filter. The notch filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Settings object for the peaking filter. The peaking filter is disabled if this is not provided. Accepts frequency, q, and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

public

Determines the type of wave output by the OscillatorNode instance. Corresponds directly to type from OscillatorNode

Private Properties
private

Lists available filter types.

Method Summary

Public Methods
public
public
public
play( )
public
playAt(time)
public
playFor(seconds)
public
playIn(seconds)
public
playInAndStopAfter(playIn, stopAfter)
public
public
stop( )
public
stopAt(time)
public
stopIn(seconds)
public
update(key, value)
Protected Methods
protected

Initializes default connections on Oscillator instantiation. Runs on('init').

protected
Private Methods
private

Creates a Connection instance with a filter of the specified type.

private
_createNode(connection): Connection
private
_play(time)
private
private
_stop(stopAt)
private
private
_wireConnection(connection, idx, connections): Connection

Public Properties

Settings object for the allpass filter. The allpass filter is disabled if this is not provided. Accepts frequency, and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Settings object for the bandpass filter. The bandpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

An array of Connection instances. Determines which AudioNode instances are connected to one-another and the order in which they are connected. Starts as null but set to an array on init via the {{#crossLink "Connectable/_initConnections:method"}}{{/crossLink}} method.

Determines the frequency of the wave output by the OscillatorNode instance. Corresponds directly to frequency.value from OscillatorNode

Determines the gain.value of the GainNode instance in the gain connection instance. Corresponds directly to gain.value from GainNode

Settings object for the highpass filter. The highpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Settings object for the highshelf filter. The highshelf filter is disabled if this is not provided. Accepts frequency and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Whether an audio source is playing or not.

Settings object for the lowpass filter. The lowpass filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Settings object for the lowshelf filter. The lowshelf filter is disabled if this is not provided. Accepts frequency and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Settings object for the notch filter. The notch filter is disabled if this is not provided. Accepts frequency and q. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Settings object for the peaking filter. The peaking filter is disabled if this is not provided. Accepts frequency, q, and gain. https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode

Determines the type of wave output by the OscillatorNode instance. Corresponds directly to type from OscillatorNode

Private Properties

Lists available filter types.

Public Methods

addon/mixins/connectable.js:62

public getConnection(name): Connection

Inherited from Connectable
returns a connection from the connections array by it's name

Parameters:

Name Type Attribute Description
name String
The name of the AudioNode that should be returned.

Return:

Connection The requested Connection.
addon/mixins/connectable.js:43

public getNodeFrom(name): AudioNode

Inherited from Connectable
returns a connection's AudioNode from the connections array by the connection's name.

Parameters:

Name Type Attribute Description
name String
The name of the AudioNode that should be returned.

Return:

AudioNode The requested AudioNode.
Inherited from Playable
Plays the audio source immediately.
addon/mixins/playable.js:49

public playAt(time)

Inherited from Playable
Plays the audio source at the specified moment in time. A "moment in time" is measured in seconds from the moment that the {{#crossLink "AudioContext"}}{{/crossLink}} was instantiated. Functionally equivalent to {{#crossLink "Playable/_play:method"}}{{/crossLink}}.

Parameters:

Name Type Attribute Description
time Number
The moment in time (in seconds, relative to the {{#crossLink "AudioContext"}}AudioContext's{{/crossLink}} "beginning of time") when the audio source should be played.
addon/mixins/playable.js:80

public playFor(seconds)

Inherited from Playable
Starts playing the audio source immediately, but stops after specified seconds have elapsed.

Parameters:

Name Type Attribute Description
seconds Number
The amount of time after which the audio source is stopped.
addon/mixins/playable.js:67

public playIn(seconds)

Inherited from Playable
Plays the audio source in specified amount of seconds from "now".

Parameters:

Name Type Attribute Description
seconds Number
Number of seconds from "now" that the audio source should be played.
addon/mixins/playable.js:95

public playInAndStopAfter(playIn, stopAfter)

Inherited from Playable
Starts playing the audio source after playIn seconds have elapsed, then stops the audio source stopAfter seconds after it started playing.

Parameters:

Name Type Attribute Description
playIn Number
Number of seconds from "now" that the audio source should play.
stopAfter Number
Number of seconds from when the audio source started playing that the audio source should be stopped.
addon/mixins/connectable.js:76

public removeConnection(name)

Inherited from Connectable
Find's a connection in the connections array by it's name and removes it.

Parameters:

Name Type Attribute Description
name String
The name of the connection that should be removed.
Inherited from Playable
Stops the audio source immediately.
addon/mixins/playable.js:136

public stopAt(time)

Inherited from Playable
Stops the audio source at the specified "moment in time" relative to the "beginning of time" according to the audioContext. Functionally equivalent to the _stop method.

Parameters:

Name Type Attribute Description
time Number
The time that the audio source should be stopped.
addon/mixins/playable.js:123

public stopIn(seconds)

Inherited from Playable
Stops the audio source after specified seconds have elapsed.

Parameters:

Name Type Attribute Description
seconds Number
Number of seconds from "now" that the audio source should be stopped.
addon/mixins/connectable.js:88

public update(key, value)

Inherited from Connectable
Updates an AudioNode's property in real time by setting the property on the connectable object (which affects the next play) and also sets it on it's corresponding connection.node (which affects the audio in real time). If a connection is pulling a property from a connectable object via onPlaySetAttrsOnNode[index].relativePath, this method will update that property directly on the Connection's node as well as on the connectable object. Important to note that this only works for properties that are set directly on a connectable object and then proxied/set on a node via onPlaySetAttrsOnNode.

Parameters:

Name Type Attribute Description
key String
The name/path to a property on an Oscillator instance that should be updated.
value String
The value that the property should be set to.

Example:

// With set
const osc = audioService.createOscillator({ frequency: 440 });
osc.play(); // playing at 440Hz
osc.set('frequency', 1000); // still playing at 440Hz
osc.stop();
osc.play(); // now playing at 1000Hz
// With update
const osc = audioService.createOscillator({ frequency: 440 });
osc.play(); // playing at 440Hz
osc.update('frequency', 1000); // playing at 1000Hz

Protected Methods

addon/classes/oscillator.js:103

protected _initConnections( )

Initializes default connections on Oscillator instantiation. Runs on('init').

addon/mixins/connectable.js:197

protected wireConnections( ): Array | Connection

Inherited from Connectable
Gets the array of Connection instances from the connections array and returns the same array, having created any AudioNode instances that needed to be created, and having connected the AudioNode instances to one another in the order in which they were present in the connections array.

Return:

Array | Connection Array of Connection instances collected from the connections array, created, connected, and ready to play.

Private Methods

addon/classes/oscillator.js:171

private _createFilter(type): Connection

Creates a Connection instance with a filter of the specified type.

Parameters:

Name Type Attribute Description
type String

Determines what type of filter will be created.

Return:

Connection

A connection with a BiquadFilterNode of the specified type.

addon/mixins/connectable.js:218

private _createNode(connection): Connection

Inherited from Connectable
Creates an AudioNode instance for a Connection instance and sets it on it's node property. Unless the Connection instance's createdOnPlay property is true, does nothing if the AudioNode instance has already been created. Also sets any properties from a connection's onPlaySetAttrsOnNode array on the node.

Parameters:

Name Type Attribute Description
connection Connection
A Connection instance that should have it's node created (if needed).

Return:

Connection The input Connection instance after having it's node created.
addon/mixins/playable.js:179

private _play(time)

Inherited from Playable
The underlying method that backs all of the play methods. Plays sound and sets isPlaying to true at specified time. Functionally equivalent to playAt.

Parameters:

Name Type Attribute Description
time Number
The moment in time (in seconds, relative to the {{#crossLink "AudioContext"}}AudioContext's{{/crossLink}} "beginning of time") when the audio source should be played.
addon/mixins/connectable.js:253

private _setAttrsOnNode(connection): Connection

Inherited from Connectable
Gets a Connection instance's onPlaySetAttrsOnNode and sets them on it's node.

Parameters:

Name Type Attribute Description
connection Connection
The Connection instance that needs it's node's attrs set.

Return:

Connection The input Connection instance after having it's nodes attrs set.
addon/mixins/playable.js:151

private _stop(stopAt)

Inherited from Playable
The underlying method that backs all of the stop methods. Stops sound and set isPlaying to false at specified time. Functionally equivalent to the stopAt method.

Parameters:

Name Type Attribute Description
stopAt Number
The moment in time (in seconds, relative to the {{#crossLink "AudioContext"}}AudioContext's{{/crossLink}} "beginning of time") when the audio source should be stopped.
addon/mixins/connectable.js:186

private _watchConnectionChanges( )

Inherited from Connectable
Observes the connections array and runs wireConnections each time it changes.
addon/mixins/connectable.js:300

private _wireConnection(connection, idx, connections): Connection

Inherited from Connectable
Meant to be passed to a Array.prototype.map function. Connects a Connection instance's node to the next Connection instance's node.

Parameters:

Name Type Attribute Description
connection Connection
The current Connection instance in the iteration.
idx Number
The index of the current iteration.
connections Array | Connection
The original array of connections.

Return:

Connection The input Connection instance after having it's node connected to the next Connection instance's node.