new Player(url)
Audio Player
Audio file player with start, loop, stop.
Parameters:
Name | Type | Description |
---|---|---|
url |
string |
Extends
Members
-
<private> _buffer :AudioBuffer
-
the buffer
Type:
- AudioBuffer
-
<private> _playbackRate :number
-
the playback rate
Type:
- number
-
<private> _source :AudioBufferSourceNode
-
Type:
- AudioBufferSourceNode
-
bufferSize :number
-
the default buffer size
Type:
- number
- Inherited From:
- Source:
-
context :AudioContext
-
A static pointer to the audio context
Type:
- AudioContext
- Inherited From:
- Source:
-
duration :number
-
the duration of the buffer once it's been loaded
Type:
- number
-
input :GainNode
-
default input of the ToneNode
Type:
- GainNode
- Inherited From:
- Source:
-
isFrequency
-
true if the input is in the format number+hz i.e.: 10hz
- Inherited From:
- Source:
-
isNotation
-
tests if a string is musical notation i.e.: 4n = quarter note 2m = two measures 8t = eighth-note triplet
- Inherited From:
- Source:
-
isTransportTime
-
tests if a string is transportTime i.e. : 1:2:0 = 1 measure + two quarter notes + 0 sixteenth notes
- Inherited From:
- Source:
-
output :GainNode
-
unlike most ToneNodes, Sources only have an output and no input
Type:
- GainNode
- Inherited From:
- Source:
-
retrigger :boolean
-
enabling retrigger will allow a player to be restarted before the it's is done playing
Type:
- boolean
-
state :Tone.Source.State
-
Type:
- Inherited From:
- Source:
-
url :string
-
the url to load
Type:
- string
-
waveShaperResolution :number
-
the default resolution for WaveShaperNodes
Type:
- number
- Inherited From:
- Source:
Methods
-
<private> _onended()
-
internal call when the buffer is done playing
-
chain()
-
connect together all of the arguments in series
Parameters:
Type Argument Description AudioParam | Tone <repeatable>
- Inherited From:
- Source:
-
connect(unit)
-
connect the output of a ToneNode to an AudioParam, AudioNode, or ToneNode
Parameters:
Name Type Description unit
Tone | AudioParam | AudioNode - Inherited From:
- Source:
-
dbToGain(db) → {number}
-
convert db scale to gain scale (0-1)
Parameters:
Name Type Description db
number - Inherited From:
- Source:
Returns:
- Type
- number
-
defaultArg(given, fallback) → {*}
-
if a the given is undefined, use the fallback
Parameters:
Name Type Description given
* fallback
* - Inherited From:
- Source:
Returns:
- Type
- *
-
disconnect()
-
disconnect the output
- Inherited From:
- Source:
-
dispose()
-
dispose and disconnect
-
equalPowerScale(percent) → {number}
-
equal power gain scale good for cross-fading
Parameters:
Name Type Description percent
number (0-1) - Inherited From:
- Source:
Returns:
output gain (0-1)- Type
- number
-
expScale(gain) → {number}
-
Parameters:
Name Type Description gain
number (0-1) - Inherited From:
- Source:
Returns:
gain (decibel scale but betwee 0-1)- Type
- number
-
fadeTo(value, time)
-
Parameters:
Name Type Description value
number time
Tone.Time (relative to 'now') - Inherited From:
- Source:
-
frequencyToSeconds(freq) → {number}
-
convert a frequency into seconds accepts both numbers and strings i.e. 10hz or 10 both equal .1
Parameters:
Name Type Description freq
number | string - Inherited From:
- Source:
Returns:
- Type
- number
-
gainToDb(gain) → {number}
-
convert gain scale to decibels
Parameters:
Name Type Description gain
number (0-1) - Inherited From:
- Source:
Returns:
- Type
- number
-
interpolate(input, outputMin, outputMax) → {number}
-
interpolate the input value (0-1) to be between outputMin and outputMax
Parameters:
Name Type Description input
number outputMin
number outputMax
number - Inherited From:
- Source:
Returns:
- Type
- number
-
load(callback)
-
makes an xhr reqest for the selected url Load the audio file as an audio buffer. Decodes the audio asynchronously and invokes the callback once the audio buffer loads.
Parameters:
Name Type Description callback
function -
logScale(gain) → {number}
-
Parameters:
Name Type Description gain
number (0-1) - Inherited From:
- Source:
Returns:
gain (decibel scale but betwee 0-1)- Type
- number
-
loop(startTime, loopStart, loopEnd, offset, duration)
-
Loop the buffer from start to finish at a time
Parameters:
Name Type Argument Description startTime
Tone.Time <optional>
loopStart
Tone.Time <optional>
loopEnd
Tone.Time <optional>
offset
Tone.Time <optional>
duration
Tone.Time <optional>
-
noGC()
-
makes a connection to ensure that the node will not be garbage collected until 'dispose' is explicitly called use carefully. circumvents JS and WebAudio's normal Garbage Collection behavior
-
normalize(input, inputMin, inputMax) → {number}
-
normalize the input to 0-1 from between inputMin to inputMax
Parameters:
Name Type Description input
number inputMin
number inputMax
number - Inherited From:
- Source:
Returns:
- Type
- number
-
notationToSeconds(notation, bpm, timeSignature) → {number}
-
convert notation format strings to seconds
Parameters:
Name Type Argument Description notation
string bpm
number <optional>
timeSignature
number <optional>
- Inherited From:
- Source:
Returns:
- Type
- number
-
now() → {number}
-
Returns:
the currentTime from the AudioContext- Type
- number
-
onended()
-
set a callback function to invoke when the sample is over
-
<abstract> pause(time)
-
Parameters:
Name Type Description time
Tone.Time - Inherited From:
- Source:
-
receive(channelName)
-
recieve the input from the desired channelName to the input gain of 'this' node.
Parameters:
Name Type Description channelName
string - Inherited From:
- Source:
-
samplesToSeconds(samples) → {number}
-
convert a sample count to seconds
Parameters:
Name Type Description samples
number - Inherited From:
- Source:
Returns:
- Type
- number
-
secondsToFrequency(seconds) → {number}
-
convert a number in seconds to a frequency
Parameters:
Name Type Description seconds
number - Inherited From:
- Source:
Returns:
- Type
- number
-
send(channelName, amount) → {GainNode}
-
send signal to a channel name
Parameters:
Name Type Description channelName
string amount
number Returns:
- Type
- GainNode
-
setPlaybackRate(rate, rampTime)
-
set the rate at which the file plays
Parameters:
Name Type Argument Description rate
number rampTime
Tone.Time <optional>
(optional) the amount of time it takes to reach the rate -
setVolume(value)
-
Parameters:
Name Type Description value
number - Inherited From:
- Source:
-
start(startTime, offset, duration)
-
play the buffer between the desired positions
Parameters:
Name Type Argument Description startTime
Tone.Time <optional>
offset
Tone.Time <optional>
duration
Tone.Time <optional>
-
stop(time)
-
Stop playback.
Parameters:
Name Type Description time
Tone.Time -
sync()
-
sync the source to the Transport
- Inherited From:
- Source:
-
toFrequency(time) → {number}
-
convert a time to a frequency
Parameters:
Name Type Description time
Tone.Time - Inherited From:
- Source:
Returns:
the time in hertz- Type
- number
-
toMaster()
-
connect 'this' to the master output
- Inherited From:
- Source:
-
toSamples(time) → {number}
-
convert a time into samples
Parameters:
Name Type Description time
Tone.time - Inherited From:
- Source:
Returns:
- Type
- number
-
toSeconds(time) → {number}
-
convert Tone.Time to seconds this is a simplified version which only handles numbers and 'now' relative numbers. If the Transport is included this method is overridden to include many other features including notationTime, Frequency, and transportTime
Parameters:
Name Type Description time
Tone.Time - Inherited From:
- Source:
Returns:
- Type
- number
-
toSeconds(time, bpm, timeSignature) → {number}
-
convert Tone.Time into seconds. unlike the method which it overrides, this takes into account transporttime and musical notation
Parameters:
Name Type Argument Description time
Tone.Time bpm
number <optional>
timeSignature
number <optional>
- Inherited From:
- Source:
Returns:
- Type
- number
-
toTransportTime(seconds, bpm, timeSignature) → {string}
-
Convert seconds to the closest transportTime in the form measures:quarters:sixteenths
Parameters:
Name Type Argument Description seconds
Tone.Time bpm
number <optional>
timeSignature
number <optional>
- Inherited From:
- Source:
Returns:
- Type
- string
-
transportTimeToSeconds(transportTime, bpm, timeSignature) → {number}
-
convert transportTime into seconds i.e.: 4:2:3 == 4 measures + 2 quarters + 3 sixteenths
Parameters:
Name Type Argument Description transportTime
string bpm
number <optional>
timeSignature
number <optional>
- Inherited From:
- Source:
Returns:
seconds- Type
- number
-
unsync()
-
unsync the source to the Transport
- Inherited From:
- Source: