Swadge 2024 2.0.0
APIs to develop games for the Magfest Swadge
Loading...
Searching...
No Matches
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)   globalMidiPlayerPlaySong(song, MIDI_SFX)
 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)   globalMidiPlayerPlaySong(song, MIDI_BGM)
 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)   globalMidiPlayerPlaySongCb(song, MIDI_SFX, cb)
 Just like soundPlaySfx(), but with a callback which is called when the song ends.
 
#define soundPlayBgmCb(song, channel, cb)   globalMidiPlayerPlaySongCb(song, MIDI_BGM, cb)
 Just like soundPlayBgm(), but with a callback which is called when the song ends.
 
#define soundStop(reset)   globalMidiPlayerStop(reset)
 Stop all playing songs.
 
#define soundPause()   globalMidiPlayerPauseAll()
 Pause all songs. This stops output and may be resumed from that point in the song later.
 
#define soundResume()   globalMidiPlayerResumeAll()
 Resume all songs. This should be called after soundPause()
 
#define soundSave()   globalMidiSave()
 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)   globalMidiRestore(data)
 Restore state and resume audio output.
 
#define soundPlayNote(freq, channel, vol)   midiNoteOn(globalMidiPlayerGet(channel), 0, freq, vol)
 Play a specific note.
 
#define soundStopNote(channel)   midiNoteOff(globalMidiPlayerGet(channel), 0, freq, vol)
 Stop a specific note.
 
#define soundGetPlayerSfx()   globalMidiPlayerGet(0)
 Return the MIDI player used for SFX.
 
#define soundGetPlayerBgm()   globalMidiPlayerGet(1)
 Return the MIDI player used for BGM.
 

Macro Definition Documentation

◆ soundPlaySfx

#define soundPlaySfx ( song,
channel )   globalMidiPlayerPlaySong(song, MIDI_SFX)

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 )   globalMidiPlayerPlaySong(song, MIDI_BGM)

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 )   globalMidiPlayerPlaySongCb(song, MIDI_SFX, cb)

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 )   globalMidiPlayerPlaySongCb(song, MIDI_BGM, cb)

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)    globalMidiPlayerStop(reset)

Stop all playing songs.

Calls spkSongStop() or bzrStop()

Parameters
resettrue to clear out song data as well

◆ soundPause

#define soundPause ( )    globalMidiPlayerPauseAll()

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

Calls spkSongPause() or bzrPause()

◆ soundResume

#define soundResume ( )    globalMidiPlayerResumeAll()

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

Calls soundResume() or bzrResume()

◆ soundSave

#define soundSave ( )    globalMidiSave()

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)    globalMidiRestore(data)

Restore state and resume audio output.

Calls spkSongRestore() or bzrRestore()

Parameters
dataThe state saved with spkSongSave()

◆ soundPlayNote

#define soundPlayNote ( freq,
channel,
vol )   midiNoteOn(globalMidiPlayerGet(channel), 0, freq, vol)

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)    midiNoteOff(globalMidiPlayerGet(channel), 0, freq, vol)

Stop a specific note.

Calls spkStopNote() or bzrStopNote()

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

◆ soundGetPlayerSfx

#define soundGetPlayerSfx ( )    globalMidiPlayerGet(0)

Return the MIDI player used for SFX.

◆ soundGetPlayerBgm

#define soundGetPlayerBgm ( )    globalMidiPlayerGet(1)

Return the MIDI player used for BGM.