The main difference with sound and music is that the main CPU does not implement the effect; they are generated by a separate board. The main CPU sends commands to the secondary board to request that a particular sound be played. Because of this, no running task is required for the effect. (Platforms other than WPC may differ in this regard.)
Sounds and music may also overlap, depending on the capabilities of the sound board. Each platform defines a set of independent channels. When a sound needs to be played, you can specify a subset of channels that it can be played on. If one of them is free, the sound can be played. The system tracks which channels are free or in use.
There is no easy way to know when the sound has finished playing. The sound board is capable of sending responses back to the CPU board, but this has not been explored thoroughly yet. For now, sound calls need to specify how long the sound will take to complete, so that the channels can be deallocated. Exact precision is not really necessary here, unless trying to string together a sequence of speech calls.
The music channel is treated special, because it is the one used for the running background track. All other sounds are transient, whereas the music plays in a constant loop.
Some sound effects need to preempt the background music, so that both are not heard simultaneously. When a sound effect allocates the music channel, that kills the background music first; when the temporary sound finishes, the background is automatically restarted.
music_update
sound_start
sound_send
,
which is the low-level API to send a command to the sound board.
This API handles priority, channel allocation, and tracks the duration
of effects.
sample_start
speech_start
music_effect_start
music_disable
music_enable
music_timed_disable