Skip to content
Tone.js

ToneBufferSource

class Source ↳ extends OneShotSource<ToneBufferSourceOptions>

Wrapper around the native BufferSourceNode.

new ToneBufferSource(url?: string | ToneAudioBuffer | AudioBuffer, onload?: () => void)

Parameters

  • url string | ToneAudioBuffer | AudioBuffer optional

    The buffer to play or url to load

  • onload () => void optional

    The callback to invoke when the buffer is done playing.

new ToneBufferSource(options?: Partial<ToneBufferSourceOptions>)

Parameters

↳ inherited from OneShotSource

input: undefined

Sources do not have input nodes

read-only

name: string

The name of the class

Default: "ToneBufferSource"

↳ inherited from OneShotSource

The callback to invoke after the source is done playing.

Default: noOp

↳ inherited from OneShotSource

output: Gain

The public output node

read-only

playbackRate: Param<"positive">

The frequency of the oscillator

The audio buffer belonging to the player.

The curve applied to the fades, either “linear” or “exponential”

fadeIn: Time

The fadeIn time of the amplitude envelope.

fadeOut: Time

The fadeOut time of the amplitude envelope.

loop: boolean

If the buffer should loop once its over.

loopEnd: Time

If loop is true, the loop will end at this position.

loopStart: Time

If loop is true, the loop will start at this position.

read-only ↳ inherited from OneShotSource

Get the playback state at the current time

↳ inherited from OneShotSource

cancelStop(): this

Cancel a scheduled stop event

Returns this

dispose(): this

Clean up.

Returns this

↳ inherited from OneShotSource

getStateAtTime(time: Time): BasicPlaybackState

Get the playback state at the given time

Parameters

Returns BasicPlaybackState

start(time?: Time, offset?: Time, duration?: Time, gain?: number): this

Start the buffer

Parameters

  • time Time optional

    When the player should start.

  • offset Time optional

    The offset from the beginning of the sample to start at.

  • duration Time optional

    How long the sample should play. If no duration is given, it will default to the full length of the sample (minus any offset)

  • gain number optional default 1

    The gain to play the buffer back at.

Returns this

↳ inherited from OneShotSource

stop(time?: Time): this

Stop the source node at the given time.

Parameters

  • time Time optional

    When to stop the source

Returns this

static

Returns all of the default options belonging to the class.

Returns ToneBufferSourceOptions