Skip to content
This repository has been archived by the owner on Feb 19, 2023. It is now read-only.

End user API

Valera edited this page Jul 31, 2018 · 3 revisions

SoundMixer

Constructor

SoundMixer(SoundChNum normal_channels, SoundChNum auto_channels, dac_channel_t dac)

Setup SoundMixer object.

Arguments

  1. normal_channels — count of manually-controlled channels.
  2. auto_channels — count of auto-selecable channels.
  3. dac — ID of dac channel.

Example

SoundMixer mixer(2, 3, DAC_GPIO25_CHANNEL); // Create mixer with two normal channels, three auto channels and output to GPIO 25.

Wait! What does manually-controlled and auto-selecable channels is?!

Well, it is good question.
Manually-controlled channel is easy as cake — you operate on specified channel. It is really good idea for background music, but isn't good for varios sounds.
Auto-selecable channels works via simple wrapper — you specify sound to play and its volume and it selects free channel, sets volume and starts sound on it. For future control you still should use returned channel's ID.

Basic methods

All of that methods is for playback control.

play

void play(SoundChNum channel, SoundProvider *sound)

Play sound on specified channel from SoundProvider at sound. If anything is alreaby playing on this channel, replace it.

Arguments

  1. channel — id of channel. Must be less than count of normal_channels.
  2. sound - pointer to valid SoundProvider. You should carry about its memory by youself.

Example

mixer.play(0, &provider); // Play on first channel from provider

stop

void stop(SoundChNum channel)

If something is playing on channel, stop it. If you want to continue from same position later, use pause

Arguments

  1. channel — id of channel.

Example

mixer.stop(0); // If something is playing on channel 0, stop it

pause

void pause(SoundChNum channel)

If something is playing on channel, pause it. Unlike stop, you can later continue playing from same position using resume.

Arguments

  1. channel — id of channel.

Example

mixer.pause(0); // If something is playing on channel 0, pause it

resume

void resume(SoundChNum channel)

If something was paused on channel, continue playing from same position.

Arguments

  1. channel — id of channel.

Example

mixer.resume(0); // If something was paused on channel 0, pause it

Volume control

A bit about volume calculation algorithm. In easiest way, it look like:

  1. Sum all inputs multiplied on their volumes.
  2. Divide by 255
  3. Divide by total count of channels

By default all channel's volumes is 255, but you can change it using following methods:

setVolume

void setVolume(SoundChNum channel, SoundVolume vol)

Set volume of channel.

Arguments

  1. channel — id of channel.
  2. vol — new volume for channel.

Example

mixer.setVolume(0, 255); // Set volume of channel 0 to default

getVolume

SoundVolume getVolume(SoundChNum channel)

Get volume of channel.

Arguments

  1. channel — id of channel.

Example

SoundVolume vol = mixer.getVolume(0); // Read volume of channel 0 into vol

Read channel's state

state

SoundState state(SoundChNum channel)

Get current state of channel. It can be: STOPPED, PAUSED or PLAYING.

Arguments

  1. channel — id of channel.

Example

SoundState st = mixer.state(0) // Read state of channel 0 into st

Auto-select channel

playAuto

SoundChNum playAuto(SoundProvider *sound, SoundVolume vol)

Select free auto-channel and start sound with specified volume. In case of success ID of selected channel will be returned, total count of channels otherwise.

Arguments

  1. sound - pointer to valid SoundProvider. You should carry about its memory by youself.
  2. vol — volume for sound.

Group methods

All of them have prototype void func(void) and they just apply selected operation to all channels:

  • stopAll
  • pauseAll
  • resumeAll

SoundProvider

Read more about your implementation interface it its documentation.

repeat

bool repeat = false

This is standart member variable for all SoundProviders. If it is true, then track will restart when it will reach its end, until you stop it explicitly.