-
Notifications
You must be signed in to change notification settings - Fork 1
End user API
SoundMixer(SoundChNum normal_channels, SoundChNum auto_channels, dac_channel_t dac)
Setup SoundMixer
object.
-
normal_channels
— count of manually-controlled channels. -
auto_channels
— count of auto-selecable channels. -
dac
— ID of dac channel.
SoundMixer mixer(2, 3, DAC_GPIO25_CHANNEL); // Create mixer with two normal channels, three auto channels and output to GPIO 25.
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.
All of that methods is for playback control.
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.
-
channel
— id of channel. Must be less than count ofnormal_channels
. -
sound
- pointer to validSoundProvider
. You should carry about its memory by youself.
mixer.play(0, &provider); // Play on first channel from provider
void stop(SoundChNum channel)
If something is playing on channel
, stop it. If you want to continue from same position later, use pause
-
channel
— id of channel.
mixer.stop(0); // If something is playing on channel 0, stop it
void pause(SoundChNum channel)
If something is playing on channel
, pause it. Unlike stop
, you can later continue playing from same position using resume
.
-
channel
— id of channel.
mixer.pause(0); // If something is playing on channel 0, pause it
void resume(SoundChNum channel)
If something was paused on channel
, continue playing from same position.
-
channel
— id of channel.
mixer.resume(0); // If something was paused on channel 0, pause it
A bit about volume calculation algorithm. In easiest way, it look like:
- Sum all inputs multiplied on their volumes.
- Divide by 255
- Divide by total count of channels
By default all channel's volumes is 255, but you can change it using following methods:
void setVolume(SoundChNum channel, SoundVolume vol)
Set vol
ume of channel
.
-
channel
— id of channel. -
vol
— new volume for channel.
mixer.setVolume(0, 255); // Set volume of channel 0 to default
SoundVolume getVolume(SoundChNum channel)
Get vol
ume of channel
.
-
channel
— id of channel.
SoundVolume vol = mixer.getVolume(0); // Read volume of channel 0 into vol
SoundState state(SoundChNum channel)
Get current state of channel
. It can be: STOPPED
, PAUSED
or PLAYING
.
-
channel
— id of channel.
SoundState st = mixer.state(0) // Read state of channel 0 into st
SoundChNum playAuto(SoundProvider *sound, SoundVolume vol)
Select free auto-channel and start sound
with specified vol
ume. In case of success ID of selected channel will be returned, total count of channels otherwise.
-
sound
- pointer to validSoundProvider
. You should carry about its memory by youself. -
vol
— volume for sound.
All of them have prototype void func(void)
and they just apply selected operation to all channels:
stopAll
pauseAll
resumeAll
Read more about your implementation interface it its documentation.
bool repeat = false
This is standart member variable for all SoundProvider
s. If it is true
, then track will restart when it will reach its end, until you stop it explicitly.