Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
soundFuncs.h File Reference

Detailed Description

Design Philosophy

Swadge hardware may have buzzers or a DAC driven speaker, but not both at the same time. These macros should be used to play songs in a hardware-agnostic way. The configuration may be changed using idf.py menuconfig in the "Swadge Configuration" menu's "Select Sound Output" option.

See sngPlayer.h for the DAC speaker functions that these macros route to.

Go to the source code of this file.

Macros

#define soundPlaySfx(song, channel)
 Play a song as a sound effect. For buzzers, sound effects interrupt background music and may be played on a specific channel. For the DAC speakers, both play at the same time and there is no channel selection.
 
#define soundPlayBgm(song, channel)
 Play a song as background music. For buzzers, background music may be interrupted by sound effects and may be played on a specific channel. For the DAC speakers, both play at the same time and there is no channel selection.
 
#define soundPlaySfxCb(song, channel, cb)
 Just like soundPlaySfx(), but with a callback which is called when the song ends.
 
#define soundPlayBgmCb(song, channel, cb)
 Just like soundPlayBgm(), but with a callback which is called when the song ends.
 
#define soundStop(reset)
 Stop all playing songs.
 
#define soundPause()
 Pause all songs. This stops output and may be resumed from that point in the song later.
 
#define soundResume()
 Resume all songs. This should be called after soundPause()
 
#define soundSave()
 Stop all songs and return a void* containing all the state. The state must be freed or restored with soundRestore() later. This is useful to stop the audio output, play something completely different, and resume the original output later.
 
#define soundRestore(data)
 Restore state and resume audio output.
 
#define soundPlayNote(freq, channel, vol)
 Play a specific note.
 
#define soundStopNote(channel)
 Stop a specific note.
 
#define soundGetPlayerSfx()
 Return the MIDI player used for SFX.
 
#define soundGetPlayerBgm()
 Return the MIDI player used for BGM.
 

Macro Definition Documentation

◆ soundPlaySfx

#define soundPlaySfx ( song,
channel )
Value:
void globalMidiPlayerPlaySong(midiFile_t *song, uint8_t songIdx)
Play a song on one of the system-wide MIDI players, either BGM or SFX.
Definition midiPlayer.c:2499
#define MIDI_SFX
Definition midiPlayer.h:82

Play a song as a sound effect. For buzzers, sound effects interrupt background music and may be played on a specific channel. For the DAC speakers, both play at the same time and there is no channel selection.

Calls spkSongPlay() or bzrPlaySfx()

Parameters
songThe song to play
channelThe channel (L/R/Stereo) to play on, ignored for DAC speakers

◆ soundPlayBgm

#define soundPlayBgm ( song,
channel )
Value:
#define MIDI_BGM
Definition midiPlayer.h:84

Play a song as background music. For buzzers, background music may be interrupted by sound effects and may be played on a specific channel. For the DAC speakers, both play at the same time and there is no channel selection.

Calls spkSongPlay() or bzrPlayBgm()

Parameters
songThe song to play
channelThe channel (L/R/Stereo) to play on, ignored for DAC speakers

◆ soundPlaySfxCb

#define soundPlaySfxCb ( song,
channel,
cb )
Value:
void globalMidiPlayerPlaySongCb(midiFile_t *song, uint8_t songIdx, songFinishedCbFn cb)
Play a song on noe of the system-wide MIDI players, with a callback once the song finishes.
Definition midiPlayer.c:2513

Just like soundPlaySfx(), but with a callback which is called when the song ends.

Calls spkSongPlayCb() or bzrPlaySfxCb()

Parameters
songThe song to play
channelThe channel (L/R/Stereo) to play on, ignored for DAC speakers
cbA callback called when the song finishes

◆ soundPlayBgmCb

#define soundPlayBgmCb ( song,
channel,
cb )
Value:

Just like soundPlayBgm(), but with a callback which is called when the song ends.

Calls spkSongPlayCb() or bzrPlayBgmCb()

Parameters
songThe song to play
channelThe channel (L/R/Stereo) to play on, ignored for DAC speakers
cbA callback called when the song finishes

◆ soundStop

#define soundStop ( reset)
Value:
void globalMidiPlayerStop(bool reset)
Stop all songs currently being played by the system-wide MIDI players, optionally resetting their sta...
Definition midiPlayer.c:2565

Stop all playing songs.

Calls spkSongStop() or bzrStop()

Parameters
resettrue to clear out song data as well

◆ soundPause

#define soundPause ( )
Value:
void globalMidiPlayerPauseAll(void)
Pause all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2543

Pause all songs. This stops output and may be resumed from that point in the song later.

Calls spkSongPause() or bzrPause()

◆ soundResume

#define soundResume ( )
Value:
void globalMidiPlayerResumeAll(void)
Resume all songs currently being played by the system-wide MIDI players.
Definition midiPlayer.c:2554

Resume all songs. This should be called after soundPause()

Calls soundResume() or bzrResume()

◆ soundSave

#define soundSave ( )
Value:
void * globalMidiSave(void)
Stop all MIDI playback and return a pointer containing the full playback state. This state must be pa...
Definition midiFileParser.c:1036

Stop all songs and return a void* containing all the state. The state must be freed or restored with soundRestore() later. This is useful to stop the audio output, play something completely different, and resume the original output later.

Calls globalMidiSave() or bzrSave()

Returns
A void* containing song state

◆ soundRestore

#define soundRestore ( data)
Value:
void globalMidiRestore(void *data)
Resume MIDI playback from the state stored in the given pointer. The data will be freed after this ca...
Definition midiFileParser.c:1071

Restore state and resume audio output.

Calls spkSongRestore() or bzrRestore()

Parameters
dataThe state saved with spkSongSave()

◆ soundPlayNote

#define soundPlayNote ( freq,
channel,
vol )
Value:
midiNoteOn(globalMidiPlayerGet(channel), 0, freq, vol)
midiPlayer_t * globalMidiPlayerGet(uint8_t songIdx)
Return a pointer to the system-wide MIDI player for the given track type, either MIDI_SFX or MIDI_BGM...
Definition midiPlayer.c:2583
void midiNoteOn(midiPlayer_t *player, uint8_t chanId, uint8_t note, uint8_t velocity)
Begin playing a note on a given MIDI channel.
Definition midiPlayer.c:1556

Play a specific note.

Calls midiNoteOn() or bzrPlayNote()

Parameters
freqThe frequency of the note to play
channelThe channel (L/R/Stereo) to play on, ignored for DAC speakers
volThe volume of the note to play

◆ soundStopNote

#define soundStopNote ( channel)
Value:
midiNoteOff(globalMidiPlayerGet(channel), 0, freq, vol)
void midiNoteOff(midiPlayer_t *player, uint8_t channel, uint8_t note, uint8_t velocity)
Stop playing a particular note on a given MIDI channel.
Definition midiPlayer.c:1800

Stop a specific note.

Calls spkStopNote() or bzrStopNote()

Parameters
channelThe channel (L/R/Stereo) to stop, ignored for DAC speakers

◆ soundGetPlayerSfx

#define soundGetPlayerSfx ( )
Value:

Return the MIDI player used for SFX.

◆ soundGetPlayerBgm

#define soundGetPlayerBgm ( )
Value:

Return the MIDI player used for BGM.