AudioChip
The AudioChip can be used together with a Speaker to make your gadgets produce sounds through the usage of AudioSamples.
Sizes
The different sizes of AudioChips determine how many concurrent channels each of them supports:
The small AudioChip supports 4 channels.
The medium AudioChip supports 16 channels.
The large AudioChip supports 32 channels.
Properties
ChannelsCount number read only
Number of available channels for this AudioChip. Each channel can independently play an audio sample.
The global AudioChip volume.
Methods
GetSpectrumData( channel number, samplesCount number ) {number}
Returns the audio spectrum values of a
channel
as a table of number values, each one expressing the value of a different frequency.samplesCount
must be a power of 2 (ie 128/256/512 etc) Min = 64 Max = 8192.
GetDspTime( ) number
Returns the current internal AudioChip's DSP time. It is meant to be used in combination with the PlayScheduled method. The returned number is expressed in seconds.
Play( audioSample AudioSample, channel number )
Immediately plays an AudioSample on a specific
channel
.
PlayScheduled( audioSample AudioSample, channel number, dspTime number )
Schedule the play of and AudioSample at a specific DSP time, expressed in seconds, on the specific
channel
.
PlayLoop( audioSample AudioSample, channel number )
Immediately plays an AudioSample on a specific
channel
, looping it.
PlayLoopScheduled( audioSample AudioSample, channel number, dspTime number )
Schedule the play of and AudioSample at a specific DSP time, expressed in seconds, on the specific
channel
, looping it.
Stops any audio playing on a specific
channel
Pause the audio on a specific
channel
Resumes the audio on a specific
channel
IsPlaying( channel number ) boolean
Returns true if a
channel
is currently playing audio
IsPaused( channel number ) boolean
Returns true if a
channel
is currently paused.
GetPlayTime( channel number ) number
Returns the current play time of a
channel
, expressed in seconds.
SeekPlayTime( time number, channel number )
Sets the current position of the play head, for the specific
channel
, expressed in seconds.
SetChannelVolume( volume number, channel number )
Sets the current
volume
for achannel
, 0-100 range.
GetChannelVolume( channel number ) number
Gets the current volume for a
channel
, 0-100 range.
SetChannelPitch( pitch number, channel number )
Sets the
pitch
for achannel
. Acts as a multiplier. A value of 1 means the defaultpitch
for a sample, a value of 2 plays the sample one octave higher.
GetChannelPitch( channel number ) number
Gets the current pitch of a
channel
.
Events
AudioChipChannelEvent : { Channel number, Type string }
Event sent when a channel has finished playing.
*Channel
is the index of the audio channel.
*Type
is"AudioChipChannelEvent"
.
Examples
See the Sound Board cookbook example for an example on how to play samples with keypad input.
See also the Audio Tutorial video in the official Retro Gadgets YouTube channel.