libctru  v2.4.1
Data Structures | Macros | Enumerations | Functions | Variables
csnd.h File Reference

CSND service. More...

#include <3ds/types.h>

Go to the source code of this file.

Data Structures

union  CSND_ChnInfo
 Channel info. More...
 
union  CSND_CapInfo
 Capture info. More...
 

Macros

#define CSND_NUM_CHANNELS   32
 Maximum number of CSND channels.
 
#define CSND_TIMER(n)   (0x3FEC3FC / ((u32)(n)))
 Creates a CSND timer value from a sample rate.
 
#define SOUND_CHANNEL(n)   ((u32)(n) & 0x1F)
 Creates a sound channel value from a channel number.
 
#define SOUND_FORMAT(n)   ((u32)(n) << 12)
 Creates a sound format value from an encoding.
 
#define SOUND_LOOPMODE(n)   ((u32)(n) << 10)
 Creates a sound loop mode value from a loop mode.
 

Enumerations

enum  {
  CSND_ENCODING_PCM8 = 0 ,
  CSND_ENCODING_PCM16 ,
  CSND_ENCODING_ADPCM ,
  CSND_ENCODING_PSG
}
 CSND encodings. More...
 
enum  {
  CSND_LOOPMODE_MANUAL = 0 ,
  CSND_LOOPMODE_NORMAL ,
  CSND_LOOPMODE_ONESHOT ,
  CSND_LOOPMODE_NORELOAD
}
 CSND loop modes. More...
 
enum  {
  SOUND_LINEAR_INTERP = BIT(6) ,
  SOUND_REPEAT = SOUND_LOOPMODE(CSND_LOOPMODE_NORMAL) ,
  SOUND_ONE_SHOT = SOUND_LOOPMODE(CSND_LOOPMODE_ONESHOT) ,
  SOUND_FORMAT_8BIT = SOUND_FORMAT(CSND_ENCODING_PCM8) ,
  SOUND_FORMAT_16BIT = SOUND_FORMAT(CSND_ENCODING_PCM16) ,
  SOUND_FORMAT_ADPCM = SOUND_FORMAT(CSND_ENCODING_ADPCM) ,
  SOUND_FORMAT_PSG = SOUND_FORMAT(CSND_ENCODING_PSG) ,
  SOUND_ENABLE = BIT(14)
}
 Sound flags. More...
 
enum  {
  CAPTURE_REPEAT = 0 ,
  CAPTURE_ONE_SHOT = BIT(0) ,
  CAPTURE_FORMAT_16BIT = 0 ,
  CAPTURE_FORMAT_8BIT = BIT(1) ,
  CAPTURE_ENABLE = BIT(15)
}
 Capture modes. More...
 
enum  CSND_DutyCycle {
  DutyCycle_0 = 7 ,
  DutyCycle_12 = 0 ,
  DutyCycle_25 = 1 ,
  DutyCycle_37 = 2 ,
  DutyCycle_50 = 3 ,
  DutyCycle_62 = 4 ,
  DutyCycle_75 = 5 ,
  DutyCycle_87 = 6
}
 Duty cycles for a PSG channel. More...
 

Functions

static u32 CSND_VOL (float vol, float pan)
 Converts a vol-pan pair into a left/right volume pair used by the hardware. More...
 
Result CSND_AcquireCapUnit (u32 *capUnit)
 Acquires a capture unit. More...
 
Result CSND_ReleaseCapUnit (u32 capUnit)
 Releases a capture unit. More...
 
Result CSND_FlushDataCache (const void *adr, u32 size)
 Flushes the data cache of a memory region. More...
 
Result CSND_StoreDataCache (const void *adr, u32 size)
 Stores the data cache of a memory region. More...
 
Result CSND_InvalidateDataCache (const void *adr, u32 size)
 Invalidates the data cache of a memory region. More...
 
Result CSND_Reset (void)
 Resets CSND. More...
 
Result csndInit (void)
 Initializes CSND.
 
void csndExit (void)
 Exits CSND.
 
u32csndAddCmd (int cmdid)
 Adds a command to the list, returning a buffer to write arguments to. More...
 
void csndWriteCmd (int cmdid, u8 *cmdparams)
 Adds a command to the list, copying its arguments from a buffer. More...
 
Result csndExecCmds (bool waitDone)
 Executes pending CSND commands. More...
 
void CSND_SetPlayStateR (u32 channel, u32 value)
 Sets a channel's play state, resetting registers on stop. More...
 
void CSND_SetPlayState (u32 channel, u32 value)
 Sets a channel's play state. More...
 
void CSND_SetEncoding (u32 channel, u32 value)
 Sets a channel's encoding. More...
 
void CSND_SetBlock (u32 channel, int block, u32 physaddr, u32 size)
 Sets the data of a channel's block. More...
 
void CSND_SetLooping (u32 channel, u32 value)
 Sets whether to loop a channel. More...
 
void CSND_SetBit7 (u32 channel, bool set)
 Sets bit 7 of a channel. More...
 
void CSND_SetInterp (u32 channel, bool interp)
 Sets whether a channel should use interpolation. More...
 
void CSND_SetDuty (u32 channel, CSND_DutyCycle duty)
 Sets a channel's duty. More...
 
void CSND_SetTimer (u32 channel, u32 timer)
 Sets a channel's timer. More...
 
void CSND_SetVol (u32 channel, u32 chnVolumes, u32 capVolumes)
 Sets a channel's volume. More...
 
void CSND_SetAdpcmState (u32 channel, int block, int sample, int index)
 Sets a channel's ADPCM state. More...
 
void CSND_SetAdpcmReload (u32 channel, bool reload)
 Sets a whether channel's ADPCM data should be reloaded when the second block is played. More...
 
void CSND_SetChnRegs (u32 flags, u32 physaddr0, u32 physaddr1, u32 totalbytesize, u32 chnVolumes, u32 capVolumes)
 Sets CSND's channel registers. More...
 
void CSND_SetChnRegsPSG (u32 flags, u32 chnVolumes, u32 capVolumes, CSND_DutyCycle duty)
 Sets CSND's PSG channel registers. More...
 
void CSND_SetChnRegsNoise (u32 flags, u32 chnVolumes, u32 capVolumes)
 Sets CSND's noise channel registers. More...
 
void CSND_CapEnable (u32 capUnit, bool enable)
 Sets whether a capture unit is enabled. More...
 
void CSND_CapSetRepeat (u32 capUnit, bool repeat)
 Sets whether a capture unit should repeat. More...
 
void CSND_CapSetFormat (u32 capUnit, bool eightbit)
 Sets a capture unit's format. More...
 
void CSND_CapSetBit2 (u32 capUnit, bool set)
 Sets a capture unit's second bit. More...
 
void CSND_CapSetTimer (u32 capUnit, u32 timer)
 Sets a capture unit's timer. More...
 
void CSND_CapSetBuffer (u32 capUnit, u32 addr, u32 size)
 Sets a capture unit's buffer. More...
 
void CSND_SetCapRegs (u32 capUnit, u32 flags, u32 addr, u32 size)
 Sets a capture unit's capture registers. More...
 
Result CSND_SetDspFlags (bool waitDone)
 Sets up DSP flags. More...
 
Result CSND_UpdateInfo (bool waitDone)
 Updates CSND information. More...
 
Result csndPlaySound (int chn, u32 flags, u32 sampleRate, float vol, float pan, void *data0, void *data1, u32 size)
 Plays a sound. More...
 
void csndGetDspFlags (u32 *outSemFlags, u32 *outIrqFlags)
 Gets CSND's DSP flags. More...
 
CSND_ChnInfocsndGetChnInfo (u32 channel)
 Gets a channel's information. More...
 
CSND_CapInfocsndGetCapInfo (u32 capUnit)
 Gets a capture unit's information. More...
 
Result csndGetState (u32 channel, CSND_ChnInfo *out)
 Gets a channel's state. More...
 
Result csndIsPlaying (u32 channel, u8 *status)
 Gets whether a channel is playing. More...
 

Variables

vu32csndSharedMem
 CSND shared memory.
 
u32 csndSharedMemSize
 CSND shared memory size.
 
u32 csndChannels
 Bitmask of channels that are allowed for usage.
 

Detailed Description

CSND service.

Usage of this service is deprecated in favor of NDSP.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

CSND encodings.

Enumerator
CSND_ENCODING_PCM8 

PCM8.

CSND_ENCODING_PCM16 

PCM16.

CSND_ENCODING_ADPCM 

IMA-ADPCM.

CSND_ENCODING_PSG 

PSG (Similar to DS?)

◆ anonymous enum

anonymous enum

CSND loop modes.

Enumerator
CSND_LOOPMODE_MANUAL 

Manual loop.

CSND_LOOPMODE_NORMAL 

Normal loop.

CSND_LOOPMODE_ONESHOT 

Do not loop.

CSND_LOOPMODE_NORELOAD 

Don't reload.

◆ anonymous enum

anonymous enum

Sound flags.

Enumerator
SOUND_LINEAR_INTERP 

Linear interpolation.

SOUND_REPEAT 

Repeat the sound.

SOUND_ONE_SHOT 

Play the sound once.

SOUND_FORMAT_8BIT 

PCM8.

SOUND_FORMAT_16BIT 

PCM16.

SOUND_FORMAT_ADPCM 

ADPCM.

SOUND_FORMAT_PSG 

PSG.

SOUND_ENABLE 

Enable sound.

◆ anonymous enum

anonymous enum

Capture modes.

Enumerator
CAPTURE_REPEAT 

Repeat capture.

CAPTURE_ONE_SHOT 

Capture once.

CAPTURE_FORMAT_16BIT 

PCM16.

CAPTURE_FORMAT_8BIT 

PCM8.

CAPTURE_ENABLE 

Enable capture.

◆ CSND_DutyCycle

Duty cycles for a PSG channel.

Enumerator
DutyCycle_0 

0.0% duty cycle

DutyCycle_12 

12.5% duty cycle

DutyCycle_25 

25.0% duty cycle

DutyCycle_37 

37.5% duty cycle

DutyCycle_50 

50.0% duty cycle

DutyCycle_62 

62.5% duty cycle

DutyCycle_75 

75.0% duty cycle

DutyCycle_87 

87.5% duty cycle

Function Documentation

◆ CSND_AcquireCapUnit()

Result CSND_AcquireCapUnit ( u32 capUnit)

Acquires a capture unit.

Parameters
capUnitPointer to output the capture unit to.

◆ CSND_CapEnable()

void CSND_CapEnable ( u32  capUnit,
bool  enable 
)

Sets whether a capture unit is enabled.

Parameters
capUnitCapture unit to use.
enableWhether to enable the capture unit.

◆ CSND_CapSetBit2()

void CSND_CapSetBit2 ( u32  capUnit,
bool  set 
)

Sets a capture unit's second bit.

Parameters
capUnitCapture unit to use.
setValue to set.

◆ CSND_CapSetBuffer()

void CSND_CapSetBuffer ( u32  capUnit,
u32  addr,
u32  size 
)

Sets a capture unit's buffer.

Parameters
capUnitCapture unit to use.
addrBuffer address to use.
sizeSize of the buffer.

◆ CSND_CapSetFormat()

void CSND_CapSetFormat ( u32  capUnit,
bool  eightbit 
)

Sets a capture unit's format.

Parameters
capUnitCapture unit to use.
eightbitFormat to use.

◆ CSND_CapSetRepeat()

void CSND_CapSetRepeat ( u32  capUnit,
bool  repeat 
)

Sets whether a capture unit should repeat.

Parameters
capUnitCapture unit to use.
repeatWhether the capture unit should repeat.

◆ CSND_CapSetTimer()

void CSND_CapSetTimer ( u32  capUnit,
u32  timer 
)

Sets a capture unit's timer.

Parameters
capUnitCapture unit to use.
timerTimer to set.

◆ CSND_FlushDataCache()

Result CSND_FlushDataCache ( const void *  adr,
u32  size 
)

Flushes the data cache of a memory region.

Parameters
adrAddress of the memory region.
sizeSize of the memory region.

◆ CSND_InvalidateDataCache()

Result CSND_InvalidateDataCache ( const void *  adr,
u32  size 
)

Invalidates the data cache of a memory region.

Parameters
adrAddress of the memory region.
sizeSize of the memory region.

◆ CSND_ReleaseCapUnit()

Result CSND_ReleaseCapUnit ( u32  capUnit)

Releases a capture unit.

Parameters
capUnitCapture unit to release.

◆ CSND_Reset()

Result CSND_Reset ( void  )

Resets CSND.

Note: Currently breaks sound, don't use for now!

◆ CSND_SetAdpcmReload()

void CSND_SetAdpcmReload ( u32  channel,
bool  reload 
)

Sets a whether channel's ADPCM data should be reloaded when the second block is played.

Parameters
channelChannel to use.
reloadWhether to reload ADPCM data.

◆ CSND_SetAdpcmState()

void CSND_SetAdpcmState ( u32  channel,
int  block,
int  sample,
int  index 
)

Sets a channel's ADPCM state.

Parameters
channelChannel to use.
blockCurrent block.
sampleCurrent sample.
indexCurrent index.

◆ CSND_SetBit7()

void CSND_SetBit7 ( u32  channel,
bool  set 
)

Sets bit 7 of a channel.

Parameters
channelChannel to use.
setValue to set.

◆ CSND_SetBlock()

void CSND_SetBlock ( u32  channel,
int  block,
u32  physaddr,
u32  size 
)

Sets the data of a channel's block.

Parameters
channelChannel to use.
blockBlock to set.
physaddrPhysical address to set the block to.
sizeSize of the block.

◆ CSND_SetCapRegs()

void CSND_SetCapRegs ( u32  capUnit,
u32  flags,
u32  addr,
u32  size 
)

Sets a capture unit's capture registers.

Parameters
capUnitCapture unit to use.
flagsCapture unit flags.
addrCapture unit buffer address.
sizeBuffer size.

◆ CSND_SetChnRegs()

void CSND_SetChnRegs ( u32  flags,
u32  physaddr0,
u32  physaddr1,
u32  totalbytesize,
u32  chnVolumes,
u32  capVolumes 
)

Sets CSND's channel registers.

Parameters
flagsFlags to set.
physaddr0Physical address of the first buffer to play.
physaddr1Physical address of the second buffer to play.
totalbytesizeTotal size of the data to play.
chnVolumesChannel volume data.
capVolumesCapture volume data.

◆ CSND_SetChnRegsNoise()

void CSND_SetChnRegsNoise ( u32  flags,
u32  chnVolumes,
u32  capVolumes 
)

Sets CSND's noise channel registers.

Parameters
flagsFlags to set.
chnVolumesChannel volume data.
capVolumesCapture volume data.

◆ CSND_SetChnRegsPSG()

void CSND_SetChnRegsPSG ( u32  flags,
u32  chnVolumes,
u32  capVolumes,
CSND_DutyCycle  duty 
)

Sets CSND's PSG channel registers.

Parameters
flagsFlags to set.
chnVolumesChannel volume data.
capVolumesCapture volume data.
dutyDuty value to set.

◆ CSND_SetDspFlags()

Result CSND_SetDspFlags ( bool  waitDone)

Sets up DSP flags.

Parameters
waitDoneWhether to wait for completion.

◆ CSND_SetDuty()

void CSND_SetDuty ( u32  channel,
CSND_DutyCycle  duty 
)

Sets a channel's duty.

Parameters
channelChannel to use.
dutyDuty to set.

◆ CSND_SetEncoding()

void CSND_SetEncoding ( u32  channel,
u32  value 
)

Sets a channel's encoding.

Parameters
channelChannel to use.
valueEncoding to set.

◆ CSND_SetInterp()

void CSND_SetInterp ( u32  channel,
bool  interp 
)

Sets whether a channel should use interpolation.

Parameters
channelChannel to use.
interpWhether to use interpolation.

◆ CSND_SetLooping()

void CSND_SetLooping ( u32  channel,
u32  value 
)

Sets whether to loop a channel.

Parameters
channelChannel to use.
valueWhether to loop the channel.

◆ CSND_SetPlayState()

void CSND_SetPlayState ( u32  channel,
u32  value 
)

Sets a channel's play state.

Parameters
channelChannel to use.
valuePlay state to set.
Examples
audio/mic/source/main.c.

◆ CSND_SetPlayStateR()

void CSND_SetPlayStateR ( u32  channel,
u32  value 
)

Sets a channel's play state, resetting registers on stop.

Parameters
channelChannel to use.
valuePlay state to set.

◆ CSND_SetTimer()

void CSND_SetTimer ( u32  channel,
u32  timer 
)

Sets a channel's timer.

Parameters
channelChannel to use.
timerTimer to set.

◆ CSND_SetVol()

void CSND_SetVol ( u32  channel,
u32  chnVolumes,
u32  capVolumes 
)

Sets a channel's volume.

Parameters
channelChannel to use.
chnVolumesChannel volume data to set.
capVolumesCapture volume data to set.

◆ CSND_StoreDataCache()

Result CSND_StoreDataCache ( const void *  adr,
u32  size 
)

Stores the data cache of a memory region.

Parameters
adrAddress of the memory region.
sizeSize of the memory region.

◆ CSND_UpdateInfo()

Result CSND_UpdateInfo ( bool  waitDone)

Updates CSND information.

Parameters
waitDoneWhether to wait for completion.
Examples
audio/mic/source/main.c.

◆ CSND_VOL()

static u32 CSND_VOL ( float  vol,
float  pan 
)
inlinestatic

Converts a vol-pan pair into a left/right volume pair used by the hardware.

Parameters
volVolume to use.
panPan to use.
Returns
A left/right volume pair for use by hardware.

◆ csndAddCmd()

u32* csndAddCmd ( int  cmdid)

Adds a command to the list, returning a buffer to write arguments to.

Parameters
cmdidID of the command to add.
Returns
A buffer to write command arguments to.

◆ csndExecCmds()

Result csndExecCmds ( bool  waitDone)

Executes pending CSND commands.

Parameters
waitDoneWhether to wait until the commands have finished executing.

◆ csndGetCapInfo()

CSND_CapInfo* csndGetCapInfo ( u32  capUnit)

Gets a capture unit's information.

Note: Requires previous CSND_UpdateInfo()

Parameters
capUnitCapture unit to get information for.
Returns
The capture unit's information.

◆ csndGetChnInfo()

CSND_ChnInfo* csndGetChnInfo ( u32  channel)

Gets a channel's information.

Note: Requires previous CSND_UpdateInfo()

Parameters
channelChannel to get information for.
Returns
The channel's information.

◆ csndGetDspFlags()

void csndGetDspFlags ( u32 outSemFlags,
u32 outIrqFlags 
)

Gets CSND's DSP flags.

Note: Requires previous CSND_UpdateInfo()

Parameters
outSemFlagsPointer to write semaphore flags to.
outIrqFlagsPointer to write interrupt flags to.

◆ csndGetState()

Result csndGetState ( u32  channel,
CSND_ChnInfo out 
)

Gets a channel's state.

Parameters
channelChannel to get the state of.
outPointer to output channel information to.

◆ csndIsPlaying()

Result csndIsPlaying ( u32  channel,
u8 status 
)

Gets whether a channel is playing.

Parameters
channelChannel to check.
statusPointer to output the channel status to.

◆ csndPlaySound()

Result csndPlaySound ( int  chn,
u32  flags,
u32  sampleRate,
float  vol,
float  pan,
void *  data0,
void *  data1,
u32  size 
)

Plays a sound.

Parameters
chnChannel to play the sound on.
flagsFlags containing information about the sound.
sampleRateSample rate of the sound.
volThe volume, ranges from 0.0 to 1.0 included.
panThe pan, ranges from -1.0 to 1.0 included.
data0First block of sound data.
data1Second block of sound data. This is the block that will be looped over.
sizeSize of the sound data.

In this implementation if the loop mode is used, data1 must be in the range [data0 ; data0 + size]. Sound will be played once from data0 to data0 + size and then loop between data1 and data0+size.

Examples
audio/mic/source/main.c.

◆ csndWriteCmd()

void csndWriteCmd ( int  cmdid,
u8 cmdparams 
)

Adds a command to the list, copying its arguments from a buffer.

Parameters
cmdidID of the command to add.
cmdparamsBuffer containing the command's parameters.