Skip to content

MiP_Sound

github-actions[bot] edited this page Aug 10, 2026 · 8 revisions

Class MiP_Sound

Manages MiP's sound playback, audio sequence building, and volume levels.

Table of Contents


Public Functions

beginList

Signature: void beginList()

Summary: Starts a new sound list sequence.

Details:

Clears internal sequence indices and prepares the command buffer. Must be called prior to invoking addEntryToList().


addEntryToList

Signature: void addEntryToList(MiPSoundIndex sound, uint16_t delayTime=0, MiPVolume volume=MIP_VOLUME_DEFAULT)

Summary: Adds a sound entry (with optional delay and inline volume modification) to the sequence.

Details:

Appends a sound clip to the sequence buffer. If a custom volume is specified that differs from the sequence volume, an inline volume change command is automatically injected. Up to 8 sound entries can be added per sequence.

Parameters:

Parameter Description
sound Sound index to add.
delayTime Delay in milliseconds before playing the next sound (0 to 7650 ms, converted to 30ms ticks).
volume Inline volume for this sound, or MIP_VOLUME_DEFAULT to maintain active volume.

playList

Signature: void playList(uint8_t repeatCount=0)

Summary: Plays the currently assembled sound list sequence.

Details:

Pads any remaining sequence slots with mute sound codes and transmits the 18-byte play sound command to MiP over UART.

Parameters:

Parameter Description
repeatCount Number of times to repeat the entire sequence (0 = play once).

play

Signature: void play(MiPSoundIndex sound, MiPVolume volume=MIP_VOLUME_DEFAULT)

Summary: Plays a single sound effect at an optional volume level.

Details:

Convenience helper method that internally calls beginList(), addEntryToList(), and playList().

Parameters:

Parameter Description
sound Sound index to play.
volume Volume level for playback (default = MIP_VOLUME_DEFAULT).

writeVolume

Signature: void writeVolume(uint8_t volume)

Summary: Sets MiP's speaker volume level and verifies the change.

Details:

Sends the set volume command and reads back the active volume level to confirm success. Automatically retries on communication failure or mismatch.

Parameters:

Parameter Description
volume Speaker volume level (0 = mute to 7 = maximum volume).

readVolume

Signature: uint8_t readVolume()

Summary: Reads the current speaker volume level from MiP.

Details:

Performs a verified read query with automatic retries on communication failure.

Returns: uint8_t Current speaker volume level (0-7), or 0 on error.


end

Signature: void end()

Summary: Cleans up the sound subsystem when ending communication.

Details:

Restores MiP's default speaker volume (level 7).


Public Variables

MIP_CMD_PLAY_SOUND

Signature: constexpr uint8_t MIP_CMD_PLAY_SOUND

Summary: MiP protocol command byte to play a sound effect or sound sequence.


MIP_CMD_SET_VOLUME

Signature: constexpr uint8_t MIP_CMD_SET_VOLUME

Summary: MiP protocol command byte to set the speaker volume level.


MIP_CMD_GET_VOLUME

Signature: constexpr uint8_t MIP_CMD_GET_VOLUME

Summary: MiP protocol command byte to query the active speaker volume level.


Clone this wiki locally