addon/classes/oscillator.js:19
Oscillator
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 |
public |
Settings object for the bandpass filter. The bandpass filter is disabled if this is not provided. Accepts |
public |
|
public |
Determines the frequency of the wave output by the OscillatorNode instance. Corresponds directly to |
public |
Determines the |
public |
Settings object for the highpass filter. The highpass filter is disabled if this is not provided. Accepts |
public |
Settings object for the highshelf filter. The highshelf filter is disabled if this is not provided. Accepts |
public |
|
public |
Settings object for the lowpass filter. The lowpass filter is disabled if this is not provided. Accepts |
public |
Settings object for the lowshelf filter. The lowshelf filter is disabled if this is not provided. Accepts |
public |
Settings object for the notch filter. The notch filter is disabled if this is not provided. Accepts |
public |
Settings object for the peaking filter. The peaking filter is disabled if this is not provided. Accepts |
public |
Determines the type of wave output by the OscillatorNode instance. Corresponds directly to |
Private Properties | |
---|---|
private |
Lists available filter types. |
Method Summary
Public Methods | |
---|---|
public |
getConnection(name): Connection
|
public |
getNodeFrom(name): AudioNode
|
public |
play( )
|
public |
playAt(time)
|
public |
playFor(seconds)
|
public |
playIn(seconds)
|
public |
playInAndStopAfter(playIn, stopAfter)
|
public |
removeConnection(name)
|
public |
stop( )
|
public |
stopAt(time)
|
public |
stopIn(seconds)
|
public |
update(key, value)
|
Protected Methods | |
---|---|
protected |
Initializes default connections on Oscillator instantiation. Runs |
protected |
|
Private Methods | |
---|---|
private |
_createFilter(type): Connection
Creates a Connection instance with a filter of the specified type. |
private |
_createNode(connection): Connection
|
private |
_play(time)
|
private |
_setAttrsOnNode(connection): Connection
|
private |
_stop(stopAt)
|
private |
|
private |
_wireConnection(connection, idx, connections): Connection
|
Public Properties
addon/classes/oscillator.js:285
public allpass: Object
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
addon/classes/oscillator.js:230
public bandpass: Object
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
addon/mixins/connectable.js:31
public connections: Ember.MutableArray
null
but set to an array on init
via the
{{#crossLink "Connectable/_initConnections:method"}}{{/crossLink}} method.addon/classes/oscillator.js:63
public frequency: Number
Determines the frequency of the wave output by the OscillatorNode instance.
Corresponds directly to frequency.value
from
OscillatorNode
addon/classes/oscillator.js:74
public gain: Number
Determines the gain.value
of the GainNode instance in the gain
connection instance. Corresponds directly to gain.value
from
GainNode
addon/classes/oscillator.js:219
public highpass: Object
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
addon/classes/oscillator.js:252
public highshelf: Object
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
addon/mixins/playable.js:29
public isPlaying: Boolean
addon/classes/oscillator.js:208
public lowpass: Object
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
addon/classes/oscillator.js:241
public lowshelf: Object
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
addon/classes/oscillator.js:274
public notch: Object
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
addon/classes/oscillator.js:263
public peaking: Object
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
addon/classes/oscillator.js:51
public type: String
Determines the type of wave output by the OscillatorNode instance.
Corresponds directly to type
from
OscillatorNode
Private Properties
addon/classes/oscillator.js:85
private _filters: Array | String
Lists available filter types.
Public Methods
addon/mixins/connectable.js:62
public getConnection(name): Connection
Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the AudioNode that should be returned. |
Return:
addon/mixins/connectable.js:43
public getNodeFrom(name): AudioNode
name
.Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the AudioNode that should be returned. |
Return:
addon/mixins/playable.js:39
public play( )
addon/mixins/playable.js:49
public playAt(time)
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)
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)
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)
playIn
seconds have elapsed, then
stops the audio source stopAfter
seconds after it started playing.addon/mixins/connectable.js:76
public removeConnection(name)
name
and removes it.Parameters:
Name | Type | Attribute | Description |
---|---|---|---|
name | String |
|
The name of the connection that should be removed. |
addon/mixins/playable.js:113
public stop( )
addon/mixins/playable.js:136
public stopAt(time)
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)
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)
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
Return:
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:
A connection with a BiquadFilterNode of the specified type.
addon/mixins/connectable.js:218
private _createNode(connection): Connection
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:
addon/mixins/playable.js:179
private _play(time)
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
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:
addon/mixins/playable.js:151
private _stop(stopAt)
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( )
addon/mixins/connectable.js:300
private _wireConnection(connection, idx, connections): Connection
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. |