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.
u32 * | csndAddCmd (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_ChnInfo * | csndGetChnInfo (u32 channel)
| Gets a channel's information. More...
CSND_CapInfo * | csndGetCapInfo (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

vu32 * | csndSharedMem
| 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

enum 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

  capUnit | Pointer to output the capture unit to.

## CSND_CapEnable()

void CSND_CapEnable | ( | u32 | capUnit,
|  | bool | enable
| ) |  |

Sets whether a capture unit is enabled.

Parameters

  capUnit | Capture unit to use.
  enable | Whether to enable the capture unit.

## CSND_CapSetBit2()

void CSND_CapSetBit2 | ( | u32 | capUnit,
|  | bool | set
| ) |  |

Sets a capture unit's second bit.

Parameters

  capUnit | Capture unit to use.
  set | Value to set.

## CSND_CapSetBuffer()

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

Sets a capture unit's buffer.

Parameters

  capUnit | Capture unit to use.
  addr | Buffer address to use.
  size | Size of the buffer.

## CSND_CapSetFormat()

void CSND_CapSetFormat | ( | u32 | capUnit,
|  | bool | eightbit
| ) |  |

Sets a capture unit's format.

Parameters

  capUnit | Capture unit to use.
  eightbit | Format to use.

## CSND_CapSetRepeat()

void CSND_CapSetRepeat | ( | u32 | capUnit,
|  | bool | repeat
| ) |  |

Sets whether a capture unit should repeat.

Parameters

  capUnit | Capture unit to use.
  repeat | Whether the capture unit should repeat.

## CSND_CapSetTimer()

void CSND_CapSetTimer | ( | u32 | capUnit,
|  | u32 | timer
| ) |  |

Sets a capture unit's timer.

Parameters

  capUnit | Capture unit to use.
  timer | Timer to set.

## CSND_FlushDataCache()

Result CSND_FlushDataCache | ( | const void * | adr,
|  | u32 | size
| ) |  |

Flushes the data cache of a memory region.

Parameters

  adr | Address of the memory region.
  size | Size of the memory region.

## CSND_InvalidateDataCache()

Result CSND_InvalidateDataCache | ( | const void * | adr,
|  | u32 | size
| ) |  |

Invalidates the data cache of a memory region.

Parameters

  adr | Address of the memory region.
  size | Size of the memory region.

## CSND_ReleaseCapUnit()

Result CSND_ReleaseCapUnit | ( | u32 | capUnit | ) |

Releases a capture unit.

Parameters

  capUnit | Capture 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

  channel | Channel to use.
  reload | Whether to reload ADPCM data.

## CSND_SetAdpcmState()

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

Sets a channel's ADPCM state.

Parameters

  channel | Channel to use.
  block | Current block.
  sample | Current sample.
  index | Current index.

## CSND_SetBit7()

void CSND_SetBit7 | ( | u32 | channel,
|  | bool | set
| ) |  |

Sets bit 7 of a channel.

Parameters

  channel | Channel to use.
  set | Value to set.

## CSND_SetBlock()

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

Sets the data of a channel's block.

Parameters

  channel | Channel to use.
  block | Block to set.
  physaddr | Physical address to set the block to.
  size | Size of the block.

## CSND_SetCapRegs()

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

Sets a capture unit's capture registers.

Parameters

  capUnit | Capture unit to use.
  flags | Capture unit flags.
  addr | Capture unit buffer address.
  size | Buffer size.

## CSND_SetChnRegs()

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

Sets CSND's channel registers.

Parameters

  flags | Flags to set.
  physaddr0 | Physical address of the first buffer to play.
  physaddr1 | Physical address of the second buffer to play.
  totalbytesize | Total size of the data to play.
  chnVolumes | Channel volume data.
  capVolumes | Capture volume data.

## CSND_SetChnRegsNoise()

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

Sets CSND's noise channel registers.

Parameters

  flags | Flags to set.
  chnVolumes | Channel volume data.
  capVolumes | Capture volume data.

## CSND_SetChnRegsPSG()

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

Sets CSND's PSG channel registers.

Parameters

  flags | Flags to set.
  chnVolumes | Channel volume data.
  capVolumes | Capture volume data.
  duty | Duty value to set.

## CSND_SetDspFlags()

Result CSND_SetDspFlags | ( | bool | waitDone | ) |

Sets up DSP flags.

Parameters

  waitDone | Whether to wait for completion.

## CSND_SetDuty()

void CSND_SetDuty | ( | u32 | channel,
|  | CSND_DutyCycle | duty
| ) |  |

Sets a channel's duty.

Parameters

  channel | Channel to use.
  duty | Duty to set.

## CSND_SetEncoding()

void CSND_SetEncoding | ( | u32 | channel,
|  | u32 | value
| ) |  |

Sets a channel's encoding.

Parameters

  channel | Channel to use.
  value | Encoding to set.

## CSND_SetInterp()

void CSND_SetInterp | ( | u32 | channel,
|  | bool | interp
| ) |  |

Sets whether a channel should use interpolation.

Parameters

  channel | Channel to use.
  interp | Whether to use interpolation.

## CSND_SetLooping()

void CSND_SetLooping | ( | u32 | channel,
|  | u32 | value
| ) |  |

Sets whether to loop a channel.

Parameters

  channel | Channel to use.
  value | Whether to loop the channel.

## CSND_SetPlayState()

void CSND_SetPlayState | ( | u32 | channel,
|  | u32 | value
| ) |  |

Sets a channel's play state.

Parameters

  channel | Channel to use.
  value | Play 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

  channel | Channel to use.
  value | Play state to set.

## CSND_SetTimer()

void CSND_SetTimer | ( | u32 | channel,
|  | u32 | timer
| ) |  |

Sets a channel's timer.

Parameters

  channel | Channel to use.
  timer | Timer to set.

## CSND_SetVol()

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

Sets a channel's volume.

Parameters

  channel | Channel to use.
  chnVolumes | Channel volume data to set.
  capVolumes | Capture volume data to set.

## CSND_StoreDataCache()

Result CSND_StoreDataCache | ( | const void * | adr,
|  | u32 | size
| ) |  |

Stores the data cache of a memory region.

Parameters

  adr | Address of the memory region.
  size | Size of the memory region.

## CSND_UpdateInfo()

Result CSND_UpdateInfo | ( | bool | waitDone | ) |

Updates CSND information.

Parameters

  waitDone | Whether 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

  vol | Volume to use.
  pan | Pan 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

  cmdid | ID of the command to add.

Returns
  A buffer to write command arguments to.

## csndExecCmds()

Result csndExecCmds | ( | bool | waitDone | ) |

Executes pending CSND commands.

Parameters

  waitDone | Whether 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

  capUnit | Capture 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

  channel | Channel 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

  outSemFlags | Pointer to write semaphore flags to.
  outIrqFlags | Pointer to write interrupt flags to.

## csndGetState()

Result csndGetState | ( | u32 | channel,
|  | CSND_ChnInfo * | out
| ) |  |

Gets a channel's state.

Parameters

  channel | Channel to get the state of.
  out | Pointer to output channel information to.

## csndIsPlaying()

Result csndIsPlaying | ( | u32 | channel,
|  | u8 * | status
| ) |  |

Gets whether a channel is playing.

Parameters

  channel | Channel to check.
  status | Pointer 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

  chn | Channel to play the sound on.
  flags | Flags containing information about the sound.
  sampleRate | Sample rate of the sound.
  vol | The volume, ranges from 0.0 to 1.0 included.
  pan | The pan, ranges from -1.0 to 1.0 included.
  data0 | First block of sound data.
  data1 | Second block of sound data. This is the block that will be looped over.
  size | Size 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

  cmdid | ID of the command to add.
  cmdparams | Buffer containing the command's parameters.