sgdk
Loading...
Searching...
No Matches
sound.h File Reference

Audio / Sound stuff. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SOUND_PCM_CH_AUTO   0xFF
 Auto select PCM channel to use.
 
#define SOUND_PCM_CH1   Z80_DRV_CH0_SFT
 PCM channel 1.
 
#define SOUND_PCM_CH2   Z80_DRV_CH1_SFT
 PCM channel 2.
 
#define SOUND_PCM_CH3   Z80_DRV_CH2_SFT
 PCM channel 3.
 
#define SOUND_PCM_CH4   Z80_DRV_CH3_SFT
 PCM channel 4.
 
#define SOUND_PCM_CH1_MSK   Z80_DRV_CH0
 PCM channel 1 selection mask.
 
#define SOUND_PCM_CH2_MSK   Z80_DRV_CH1
 PCM channel 2 selection mask.
 
#define SOUND_PCM_CH3_MSK   Z80_DRV_CH2
 PCM channel 3 selection mask.
 
#define SOUND_PCM_CH4_MSK   Z80_DRV_CH3
 PCM channel 4 selection mask.
 
#define SOUND_RATE_32000   0
 PCM sample rate set to 32 Khz.
Best quality but take lot of rom space.
 
#define SOUND_RATE_22050   1
 PCM sample rate set to 22050 Hz.
Best quality but take lot of rom space.
 
#define SOUND_RATE_16000   2
 PCM sample rate set to 16 Khz.

 
#define SOUND_RATE_13400   3
 PCM sample rate set to 13400 Hz.
Good compromise for rom space and quality.
 
#define SOUND_RATE_11025   4
 PCM sample rate set to 11025 Hz.

 
#define SOUND_RATE_8000   5
 PCM sample rate set to 8 Khz.
Worst quality but take less rom place.
 
#define SOUND_PAN_LEFT   0x80
 Left speaker panning.
 
#define SOUND_PAN_RIGHT   0x40
 Right speaker panning.
 
#define SOUND_PAN_CENTER   0xC0
 Center (laft and right) speaker panning.
 
#define SND_isPlaying_4PCM_ENV   SND_isPlaying_4PCM
 
#define SND_startPlay_4PCM_ENV   SND_startPlay_4PCM
 
#define SND_stopPlay_4PCM_ENV   SND_stopPlay_4PCM
 
#define SND_getVolume_4PCM_ENV   SND_getVolume_4PCM
 
#define SND_setVolume_4PCM_ENV   SND_setVolume_4PCM
 
#define SND_isPlaying_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_isPlaying() instead.\"")
 
#define SND_startPlay_XGM(song)   _Pragma("GCC error \"This method is deprecated, use XGM_startPlay(..) instead.\"")
 
#define SND_stopPlay_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_stopPlay() instead.\"")
 
#define SND_pausePlay_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_pausePlay() instead.\"")
 
#define SND_resumePlay_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_resumePlay() instead.\"")
 
#define SND_isPlayingPCM_XGM(channel_mask)   _Pragma("GCC error \"This method is deprecated, use XGM_isPlayingPCM(..) instead.\"")
 
#define SND_setPCM_XGM(id, sample, len)   _Pragma("GCC error \"This method is deprecated, use XGM_setPCM(..) instead.\"")
 
#define SND_setPCMFast_XGM(id, sample, len)   _Pragma("GCC error \"This method is deprecated, use XGM_setPCMFast(..) instead.\"")
 
#define SND_startPlayPCM_XGM(id, prio, ch)   _Pragma("GCC error \"This method is deprecated, use XGM_startPlayPCM(..) instead.\"")
 
#define SND_stopPlayPCM_XGM(channel)   _Pragma("GCC error \"This method is deprecated, use XGM_stopPlayPCM(..) instead.\"")
 
#define SND_getMusicTempo_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_getMusicTempo() instead.\"")
 
#define SND_setMusicTempo_XGM(value)   _Pragma("GCC error \"This method is deprecated, use XGM_setMusicTempo(..) instead.\"")
 
#define SND_getManualSync_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_getManualSync() instead.\"")
 
#define SND_setManualSync_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_setManualSync() instead.\"")
 
#define SND_nextFrame_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_nextFrame() instead.\"")
 
#define SND_nextXFrame_XGM(num)   _Pragma("GCC error \"This method is deprecated, use XGM_nextXFrame(..) instead.\"")
 
#define SND_setLoopNumber_XGM(value)   _Pragma("GCC error \"This method is deprecated, use XGM_setLoopNumber(..) instead.\"")
 
#define SND_set68KBUSProtection_XGM(value)   _Pragma("GCC error \"This method is deprecated, use XGM_set68KBUSProtection(..) instead.\"")
 
#define SND_getForceDelayDMA_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_getForceDelayDMA() instead.\"")
 
#define SND_setForceDelayDMA_XGM(value)   _Pragma("GCC error \"This method is deprecated, use XGM_setForceDelayDMA(..) instead.\"")
 
#define SND_getCPULoad_XGM()   _Pragma("GCC error \"This method is deprecated, use XGM_getCPULoad() instead.\"")
 

Functions

u8 SND_isPlaying_PCM (void)
 Return play status (Single channel PCM player driver).
 
void SND_startPlay_PCM (const u8 *sample, const u32 len, const u8 rate, const u8 pan, const u8 loop)
 Start playing a sample (Single channel PCM player driver).
If a sample was currently playing then it's stopped and the new sample is played instead.
 
void SND_stopPlay_PCM (void)
 Stop playing (Single channel PCM player driver).
No effect if no sample was currently playing.
 
u8 SND_isPlaying_2ADPCM (const u16 channel_mask)
 Return play status of specified channel (2 channels ADPCM player driver).
 
void SND_startPlay_2ADPCM (const u8 *sample, const u32 len, const u16 channel, const u8 loop)
 Start playing a sample on specified channel (2 channels ADPCM player driver).
If a sample was currently playing on this channel then it's stopped and the new sample is played instead.
 
void SND_stopPlay_2ADPCM (const u16 channel)
 Stop playing the specified channel (2 channels ADPCM player driver).
No effect if no sample was currently playing on this channel.
 
u8 SND_isPlaying_4PCM (const u16 channel_mask)
 Return play status of specified channel (4 channels PCM player driver).
 
void SND_startPlay_4PCM (const u8 *sample, const u32 len, const u16 channel, const u8 loop)
 Start playing a sample on specified channel (4 channels PCM player driver).
If a sample was currently playing on this channel then it's stopped and the new sample is played instead.
 
void SND_stopPlay_4PCM (const u16 channel)
 Stop playing the specified channel (4 channels PCM player driver).
No effect if no sample was currently playing on this channel.
 
void SND_setVolume_4PCM (const u16 channel, const u8 volume)
 Change envelop / volume of specified channel (4 channels PCM player driver).
 
u8 SND_getVolume_4PCM (const u16 channel)
 Return envelop / volume level of specified channel (4 channels PCM player driver).
 

Detailed Description

Audio / Sound stuff.

Author
Stephane Dallongeville
Date
08/2011

This unit provides advanced sound playback methods through differents Z80 drivers.

Z80_DRIVER_PCM
Single channel 8 bits signed sample driver.
It can play a sample (8 bit signed) from 8 Khz up to 32 Khz rate.

Z80_DRIVER_2ADPCM
2 channels 4 bits ADPCM sample driver.
It can mix up to 2 ADCPM samples at a fixed 22050 Hz Khz rate.
Address and size of samples have to be 256 bytes boundary.

Z80_DRIVER_4PCM
4 channels 8 bits signed sample driver with volume support.
It can mix up to 4 samples (8 bit signed) at a fixed 16 Khz rate.
with volume support (16 levels du to memory limitation).
Address and size of samples have to be 256 bytes boundary.
The driver does support "cutoff" when mixing so you can use true 8 bits samples :)

Z80_DRIVER_XGM
eXtended VGM music player driver.
Moved to xgm.h unit
Note that SGDK sound drivers may not fit your needs so it's important to know
that some alternatives sound drivers exist (see SGDK readme.md for more info)

Macro Definition Documentation

◆ SND_getCPULoad_XGM

#define SND_getCPULoad_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_getCPULoad() instead.\"")
Deprecated:
use XGM_getCPULoad(..) instead

◆ SND_getForceDelayDMA_XGM

#define SND_getForceDelayDMA_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_getForceDelayDMA() instead.\"")
Deprecated:
use XGM_getForceDelayDMA(..) instead

◆ SND_getManualSync_XGM

#define SND_getManualSync_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_getManualSync() instead.\"")
Deprecated:
use XGM_getManualSync(..) instead

◆ SND_getMusicTempo_XGM

#define SND_getMusicTempo_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_getMusicTempo() instead.\"")
Deprecated:
use XGM_getMusicTempo(..) instead

◆ SND_isPlaying_XGM

#define SND_isPlaying_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_isPlaying() instead.\"")
Deprecated:
use XGM_isPlaying() instead

◆ SND_isPlayingPCM_XGM

#define SND_isPlayingPCM_XGM (   channel_mask)    _Pragma("GCC error \"This method is deprecated, use XGM_isPlayingPCM(..) instead.\"")
Deprecated:
use XGM_isPlayingPCM(..) instead

◆ SND_nextFrame_XGM

#define SND_nextFrame_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_nextFrame() instead.\"")
Deprecated:
use XGM_nextFrame(..) instead

◆ SND_nextXFrame_XGM

#define SND_nextXFrame_XGM (   num)    _Pragma("GCC error \"This method is deprecated, use XGM_nextXFrame(..) instead.\"")
Deprecated:
use XGM_nextXFrame(..) instead

◆ SND_pausePlay_XGM

#define SND_pausePlay_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_pausePlay() instead.\"")
Deprecated:
use XGM_pausePlay(..) instead

◆ SND_resumePlay_XGM

#define SND_resumePlay_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_resumePlay() instead.\"")
Deprecated:
use XGM_resumePlay(..) instead

◆ SND_set68KBUSProtection_XGM

#define SND_set68KBUSProtection_XGM (   value)    _Pragma("GCC error \"This method is deprecated, use XGM_set68KBUSProtection(..) instead.\"")
Deprecated:
use XGM_set68KBUSProtection(..) instead

◆ SND_setForceDelayDMA_XGM

#define SND_setForceDelayDMA_XGM (   value)    _Pragma("GCC error \"This method is deprecated, use XGM_setForceDelayDMA(..) instead.\"")
Deprecated:
use XGM_setForceDelayDMA(..) instead

◆ SND_setLoopNumber_XGM

#define SND_setLoopNumber_XGM (   value)    _Pragma("GCC error \"This method is deprecated, use XGM_setLoopNumber(..) instead.\"")
Deprecated:
use XGM_setLoopNumber(..) instead

◆ SND_setManualSync_XGM

#define SND_setManualSync_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_setManualSync() instead.\"")
Deprecated:
use XGM_setManualSync(..) instead

◆ SND_setMusicTempo_XGM

#define SND_setMusicTempo_XGM (   value)    _Pragma("GCC error \"This method is deprecated, use XGM_setMusicTempo(..) instead.\"")
Deprecated:
use XGM_setMusicTempo(..) instead

◆ SND_setPCM_XGM

#define SND_setPCM_XGM (   id,
  sample,
  len 
)    _Pragma("GCC error \"This method is deprecated, use XGM_setPCM(..) instead.\"")
Deprecated:
use XGM_setPCM(..) instead

◆ SND_setPCMFast_XGM

#define SND_setPCMFast_XGM (   id,
  sample,
  len 
)    _Pragma("GCC error \"This method is deprecated, use XGM_setPCMFast(..) instead.\"")
Deprecated:
use XGM_setPCMFast(..) instead

◆ SND_startPlay_XGM

#define SND_startPlay_XGM (   song)    _Pragma("GCC error \"This method is deprecated, use XGM_startPlay(..) instead.\"")
Deprecated:
use XGM_startPlay(..) instead

◆ SND_startPlayPCM_XGM

#define SND_startPlayPCM_XGM (   id,
  prio,
  ch 
)    _Pragma("GCC error \"This method is deprecated, use XGM_startPlayPCM(..) instead.\"")
Deprecated:
use XGM_startPlayPCM(..) instead

◆ SND_stopPlay_XGM

#define SND_stopPlay_XGM ( )    _Pragma("GCC error \"This method is deprecated, use XGM_stopPlay() instead.\"")
Deprecated:
use XGM_stopPlay(..) instead

◆ SND_stopPlayPCM_XGM

#define SND_stopPlayPCM_XGM (   channel)    _Pragma("GCC error \"This method is deprecated, use XGM_stopPlayPCM(..) instead.\"")
Deprecated:
use XGM_stopPlayPCM(..) instead

Function Documentation

◆ SND_getVolume_4PCM()

u8 SND_getVolume_4PCM ( const u16  channel)

Return envelop / volume level of specified channel (4 channels PCM player driver).

Parameters
channelChannel we want to retrieve envelop level.
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2
SOUND_PCM_CH3 = channel 3
SOUND_PCM_CH4 = channel 4
Returns
Envelop of specified channel.
The returned value is comprised between 0 (quiet) to 15 (loud).

◆ SND_isPlaying_2ADPCM()

u8 SND_isPlaying_2ADPCM ( const u16  channel_mask)

Return play status of specified channel (2 channels ADPCM player driver).

Parameters
channel_maskChannel(s) we want to retrieve play state.
SOUND_PCM_CH1_MSK = channel 1
SOUND_PCM_CH2_MSK = channel 2

You can combine mask to retrieve state of severals channels at once:
isPlaying_2ADPCM(SOUND_PCM_CH1_MSK | SOUND_PCM_CH2_MSK)
will actually return play state for channel 1 and channel 2.
Returns
Return non zero if specified channel(s) is(are) playing.

◆ SND_isPlaying_4PCM()

u8 SND_isPlaying_4PCM ( const u16  channel_mask)

Return play status of specified channel (4 channels PCM player driver).

Parameters
channel_maskChannel(s) we want to retrieve play state.
SOUND_PCM_CH1_MSK = channel 1
SOUND_PCM_CH2_MSK = channel 2
SOUND_PCM_CH3_MSK = channel 3
SOUND_PCM_CH4_MSK = channel 4

You can combine mask to retrieve state of severals channels at once:
isPlaying_2ADPCM(SOUND_PCM_CH1_MSK | SOUND_PCM_CH2_MSK)
will actually return play state for channel 1 and channel 2.
Returns
Return non zero if specified channel(s) is(are) playing.

◆ SND_isPlaying_PCM()

u8 SND_isPlaying_PCM ( void  )

Return play status (Single channel PCM player driver).

Returns
Return non zero if PCM player is currently playing a sample

◆ SND_setVolume_4PCM()

void SND_setVolume_4PCM ( const u16  channel,
const u8  volume 
)

Change envelop / volume of specified channel (4 channels PCM player driver).

Parameters
channelChannel we want to set envelop.
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2
SOUND_PCM_CH3 = channel 3
SOUND_PCM_CH4 = channel 4
volumeVolume to set : 16 possible level from 0 (minimum) to 15 (maximum).

◆ SND_startPlay_2ADPCM()

void SND_startPlay_2ADPCM ( const u8 sample,
const u32  len,
const u16  channel,
const u8  loop 
)

Start playing a sample on specified channel (2 channels ADPCM player driver).
If a sample was currently playing on this channel then it's stopped and the new sample is played instead.

Parameters
sampleSample address, should be 128 bytes boundary aligned
SGDK automatically align resource as needed
lenSize of sample in bytes, should be a multiple of 128
SGDK automatically adjust resource size as needed
channelChannel where we want to play sample.
SOUND_PCM_CH_AUTO = auto selection from current channel usage
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2
loopLoop flag.
If non zero then the sample will be played in loop (else sample is played only once).

◆ SND_startPlay_4PCM()

void SND_startPlay_4PCM ( const u8 sample,
const u32  len,
const u16  channel,
const u8  loop 
)

Start playing a sample on specified channel (4 channels PCM player driver).
If a sample was currently playing on this channel then it's stopped and the new sample is played instead.

Parameters
sampleSample address, should be 256 bytes boundary aligned
SGDK automatically align resource as needed
lenSize of sample in bytes, should be a multiple of 256
SGDK automatically adjust resource size as needed
channelChannel where we want to play sample.
SOUND_PCM_CH_AUTO = auto selection from current channel usage
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2
SOUND_PCM_CH3 = channel 3
SOUND_PCM_CH4 = channel 4
loopLoop flag.
If non zero then the sample will be played in loop (else sample is played only once).

◆ SND_startPlay_PCM()

void SND_startPlay_PCM ( const u8 sample,
const u32  len,
const u8  rate,
const u8  pan,
const u8  loop 
)

Start playing a sample (Single channel PCM player driver).
If a sample was currently playing then it's stopped and the new sample is played instead.

Parameters
sampleSample address, should be 256 bytes boundary aligned
SGDK automatically align resource as needed
lenSize of sample in bytes, should be a multiple of 256
SGDK automatically adjust resource size as needed
ratePlayback rate :
SOUND_RATE_32000 = 32 Khz (best quality but take lot of rom space)
SOUND_RATE_22050 = 22 Khz
SOUND_RATE_16000 = 16 Khz
SOUND_RATE_13400 = 13.4 Khz
SOUND_RATE_11025 = 11 Khz
SOUND_RATE_8000 = 8 Khz (worst quality but take less rom place)
panPanning :
SOUND_PAN_LEFT = play on left speaker
SOUND_PAN_RIGHT = play on right speaker
SOUND_PAN_CENTER = play on both speaker
loopLoop flag.
If non zero then the sample will be played in loop (else sample is played only once).

◆ SND_stopPlay_2ADPCM()

void SND_stopPlay_2ADPCM ( const u16  channel)

Stop playing the specified channel (2 channels ADPCM player driver).
No effect if no sample was currently playing on this channel.

Parameters
channelChannel we want to stop.
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2

◆ SND_stopPlay_4PCM()

void SND_stopPlay_4PCM ( const u16  channel)

Stop playing the specified channel (4 channels PCM player driver).
No effect if no sample was currently playing on this channel.

Parameters
channelChannel we want to stop.
SOUND_PCM_CH1 = channel 1
SOUND_PCM_CH2 = channel 2
SOUND_PCM_CH3 = channel 3
SOUND_PCM_CH4 = channel 4