Audio Output

class pico_synth_sandbox.audio.Audio(output: object, voice_count: int = 1, channel_count: int = 2, sample_rate: int = None, buffer_size: int = None)[source]

Bases: object

This class helps manage audio output and mixing.

Parameters:
  • output (object) – A supported audio output object.

  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

  • channel_count (int) – The number of channels needed by the audio output. Defaults to 2 (stereo).

  • sample_rate (int) – The sample rate to run the audio output. Defaults to the AUDIO_RATE value of settings.toml or 22050.

  • buffer_size (int) – The size of the audio buffer in number of samples. Defaults to the AUDIO_BUFFFER value of settings.toml or 2048.

configure(voice_count: int = 1, channel_count: int = 2, sample_rate: int = None, buffer_size: int = None, bits_per_sample: int = 16)[source]

Reconfigure the audio mixer using the specified parameters. Will detach and reattach the mixer to the audio output object. Any existing voices will be stopped as well.

Parameters:
  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

  • channel_count (int) – The number of channels needed by the audio output. Defaults to 2 (stereo).

  • sample_rate (int) – The sample rate to run the audio output. Defaults to the AUDIO_RATE value of settings.toml or 22050.

  • buffer_size (int) – The size of the audio buffer in number of samples. Defaults to the AUDIO_BUFFFER value of settings.toml or 2048.

get_bits_per_sample() int[source]

Get the current number of bits per sample in the audio output.

Returns:

bits per sample

Return type:

int

get_buffer_size() int[source]

Get the current buffer size of teh audio output.

Returns:

buffer size in samples

Return type:

int

get_channel_count() int[source]

Get the current number of channels in the audio output.

Returns:

channel count

Return type:

int

get_level(index: int = 0) float[source]

Gets the current level of a designated voice of the audio mixer. Must be within the range of 0 -> (voice count - 1).

Returns:

level (0.0 -> 1.0)

Return type:

float

get_sample_rate() int[source]

Get the current sample rate of the audio output.

Returns:

sample rate in hz

Return type:

int

get_voice_count() int[source]

Get the current number of voices in the audio mixer.

Returns:

voice count

Return type:

int

is_muted() bool[source]

Check whether or not the audio output is muted.

Returns:

audio mute state

Return type:

bool

is_playing(index: int = -1) bool[source]

Check whether a designated mixer voice is playing (if valid index is provided) or if any voice within the audio mixer is playing.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all voices will be checked and will return True if any is playing.

Returns:

voice is playing

Return type:

bool

mute()[source]

Mute the audio output. Mixer voices will continue playing regardless of muted state.

play(source: object, index: int = 0)[source]

Play an audio source through a selected mixer voice.

Parameters:
  • source (class:circuitpython_typing.AudioSample) – The audio source you would like to play

  • index (int) – The voice you would like to play the audio source from.

set_bits_per_sample(value: int)[source]

Change the bit depth of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of bits per sample. Typically a multiple of 8 such as 8, 16, 24, or 32.

set_buffer_size(value: int)[source]

Update the size of the audio output buffer. A larger buffer will use more memory and cause more delay between audio updates, but will allow more processing type between updates and generally better audio output stability. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The size of the audio buffer in number of samples.

set_channel_count(value: int)[source]

Update the number of channels in the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of channels needed by the audio output.

set_level(value: float, index: int = -1)[source]

Set the level of output of all or a single mixer voice.

Parameters:
  • value (float) – The level of the voice from 0.0 to 1.0

  • index (int) – If you are changing the level of a specific mixer voice, provide the index of that voice. If you’d like to change the level of all available voices, leave this parameter unset or provide an integer less than 0.

set_sample_rate(value: int)[source]

Update the sample rate of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The sample rate to run the audio output.

set_voice_count(value: int)[source]

Update the number of voices available on the audio mixer object. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of voices to create for the audio mixer.

stop(index: int = -1)[source]

Stops the designated mixer voice (if valid index is provided) or all currently playing voices of the audio mixer.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all playing voices will be stopped.

toggle_mute()[source]

Toggle the muted state of the audio output. Mixer voices will continue playing regardless of muted state.

unmute()[source]

Unmute the audio output to return it to normal operation.

class pico_synth_sandbox.audio.I2SAudio(board: object, voice_count: int = 1)[source]

Bases: Audio

This class helps manage audio output and mixing using an audioio.AudioOut object of type audiobusio.I2SOut.

Parameters:
  • board (class:pico_synth_sandbox.board.Board) – The global board instance.

  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

configure(voice_count: int = 1, channel_count: int = 2, sample_rate: int = None, buffer_size: int = None, bits_per_sample: int = 16)

Reconfigure the audio mixer using the specified parameters. Will detach and reattach the mixer to the audio output object. Any existing voices will be stopped as well.

Parameters:
  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

  • channel_count (int) – The number of channels needed by the audio output. Defaults to 2 (stereo).

  • sample_rate (int) – The sample rate to run the audio output. Defaults to the AUDIO_RATE value of settings.toml or 22050.

  • buffer_size (int) – The size of the audio buffer in number of samples. Defaults to the AUDIO_BUFFFER value of settings.toml or 2048.

get_bits_per_sample() int

Get the current number of bits per sample in the audio output.

Returns:

bits per sample

Return type:

int

get_buffer_size() int

Get the current buffer size of teh audio output.

Returns:

buffer size in samples

Return type:

int

get_channel_count() int

Get the current number of channels in the audio output.

Returns:

channel count

Return type:

int

get_level(index: int = 0) float

Gets the current level of a designated voice of the audio mixer. Must be within the range of 0 -> (voice count - 1).

Returns:

level (0.0 -> 1.0)

Return type:

float

get_sample_rate() int

Get the current sample rate of the audio output.

Returns:

sample rate in hz

Return type:

int

get_voice_count() int

Get the current number of voices in the audio mixer.

Returns:

voice count

Return type:

int

is_muted() bool

Check whether or not the audio output is muted.

Returns:

audio mute state

Return type:

bool

is_playing(index: int = -1) bool

Check whether a designated mixer voice is playing (if valid index is provided) or if any voice within the audio mixer is playing.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all voices will be checked and will return True if any is playing.

Returns:

voice is playing

Return type:

bool

mute()

Mute the audio output. Mixer voices will continue playing regardless of muted state.

play(source: object, index: int = 0)

Play an audio source through a selected mixer voice.

Parameters:
  • source (class:circuitpython_typing.AudioSample) – The audio source you would like to play

  • index (int) – The voice you would like to play the audio source from.

set_bits_per_sample(value: int)

Change the bit depth of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of bits per sample. Typically a multiple of 8 such as 8, 16, 24, or 32.

set_buffer_size(value: int)

Update the size of the audio output buffer. A larger buffer will use more memory and cause more delay between audio updates, but will allow more processing type between updates and generally better audio output stability. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The size of the audio buffer in number of samples.

set_channel_count(value: int)

Update the number of channels in the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of channels needed by the audio output.

set_level(value: float, index: int = -1)

Set the level of output of all or a single mixer voice.

Parameters:
  • value (float) – The level of the voice from 0.0 to 1.0

  • index (int) – If you are changing the level of a specific mixer voice, provide the index of that voice. If you’d like to change the level of all available voices, leave this parameter unset or provide an integer less than 0.

set_sample_rate(value: int)

Update the sample rate of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The sample rate to run the audio output.

set_voice_count(value: int)

Update the number of voices available on the audio mixer object. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of voices to create for the audio mixer.

stop(index: int = -1)

Stops the designated mixer voice (if valid index is provided) or all currently playing voices of the audio mixer.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all playing voices will be stopped.

toggle_mute()

Toggle the muted state of the audio output. Mixer voices will continue playing regardless of muted state.

unmute()

Unmute the audio output to return it to normal operation.

class pico_synth_sandbox.audio.PWMAudio(board: object, voice_count: int = 1)[source]

Bases: Audio

This class helps manage audio output and mixing using an audio output object of type audiopwmio.PWMAudioOut.

Parameters:
  • board (class:pico_synth_sandbox.board.Board) – The global board instance.

  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

configure(voice_count: int = 1, channel_count: int = 2, sample_rate: int = None, buffer_size: int = None, bits_per_sample: int = 16)

Reconfigure the audio mixer using the specified parameters. Will detach and reattach the mixer to the audio output object. Any existing voices will be stopped as well.

Parameters:
  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.

  • channel_count (int) – The number of channels needed by the audio output. Defaults to 2 (stereo).

  • sample_rate (int) – The sample rate to run the audio output. Defaults to the AUDIO_RATE value of settings.toml or 22050.

  • buffer_size (int) – The size of the audio buffer in number of samples. Defaults to the AUDIO_BUFFFER value of settings.toml or 2048.

get_bits_per_sample() int

Get the current number of bits per sample in the audio output.

Returns:

bits per sample

Return type:

int

get_buffer_size() int

Get the current buffer size of teh audio output.

Returns:

buffer size in samples

Return type:

int

get_channel_count() int

Get the current number of channels in the audio output.

Returns:

channel count

Return type:

int

get_level(index: int = 0) float

Gets the current level of a designated voice of the audio mixer. Must be within the range of 0 -> (voice count - 1).

Returns:

level (0.0 -> 1.0)

Return type:

float

get_sample_rate() int

Get the current sample rate of the audio output.

Returns:

sample rate in hz

Return type:

int

get_voice_count() int

Get the current number of voices in the audio mixer.

Returns:

voice count

Return type:

int

is_muted() bool

Check whether or not the audio output is muted.

Returns:

audio mute state

Return type:

bool

is_playing(index: int = -1) bool

Check whether a designated mixer voice is playing (if valid index is provided) or if any voice within the audio mixer is playing.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all voices will be checked and will return True if any is playing.

Returns:

voice is playing

Return type:

bool

mute()

Mute the audio output. Mixer voices will continue playing regardless of muted state.

play(source: object, index: int = 0)

Play an audio source through a selected mixer voice.

Parameters:
  • source (class:circuitpython_typing.AudioSample) – The audio source you would like to play

  • index (int) – The voice you would like to play the audio source from.

set_bits_per_sample(value: int)

Change the bit depth of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of bits per sample. Typically a multiple of 8 such as 8, 16, 24, or 32.

set_buffer_size(value: int)

Update the size of the audio output buffer. A larger buffer will use more memory and cause more delay between audio updates, but will allow more processing type between updates and generally better audio output stability. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The size of the audio buffer in number of samples.

set_channel_count(value: int)

Update the number of channels in the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of channels needed by the audio output.

set_level(value: float, index: int = -1)

Set the level of output of all or a single mixer voice.

Parameters:
  • value (float) – The level of the voice from 0.0 to 1.0

  • index (int) – If you are changing the level of a specific mixer voice, provide the index of that voice. If you’d like to change the level of all available voices, leave this parameter unset or provide an integer less than 0.

set_sample_rate(value: int)

Update the sample rate of the audio output. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The sample rate to run the audio output.

set_voice_count(value: int)

Update the number of voices available on the audio mixer object. Will trigger a reconfiguration of the audio output.

Parameters:

value (int) – The number of voices to create for the audio mixer.

stop(index: int = -1)

Stops the designated mixer voice (if valid index is provided) or all currently playing voices of the audio mixer.

Parameters:

index (int) – The selected voice index. Must be from 0 -> (voice count - 1). If negative (such as -1), all playing voices will be stopped.

toggle_mute()

Toggle the muted state of the audio output. Mixer voices will continue playing regardless of muted state.

unmute()

Unmute the audio output to return it to normal operation.

pico_synth_sandbox.audio.get_audio_driver(board: object, voice_count: int = 1) Audio[source]

Automatically generate the proper audio output object based on the board configuration.

Parameters:
  • board (class:pico_synth_sandbox.board.Board) – The global board instance.

  • voice_count (int) – The number of voices to create for the audio mixer. Defaults to 1.