NightFox’s Lib
Data Structures | Macros | Functions | Variables
Sound support functions.

Simple helpers to load and play raw PCM sound files. More...

Data Structures

struct  NF_TYPE_RAWSOUND_INFO
 Struct that holds information about the loaded sound files. More...
 

Macros

#define NF_SLOTS_RAWSOUND   32
 Number of slot availables for raw sound effects.
 

Functions

void NF_InitRawSoundBuffers (void)
 Initialize all buffers and variables to load sound files. More...
 
void NF_ResetRawSoundBuffers (void)
 Resets all sound buffers and clears the data in them. More...
 
void NF_LoadRawSound (const char *file, u32 id, u32 freq, u32 format)
 Load a RAW file from the filesystem to RAM. More...
 
void NF_UnloadRawSound (u32 id)
 Deletes from RAM the sound file stored in the specified slot. More...
 
u32 NF_PlayRawSound (u32 id, u32 volume, u32 pan, bool loop, u32 loopfrom)
 Play the sound file loaded in the specified slot. More...
 

Variables

char * NF_BUFFER_RAWSOUND [NF_SLOTS_RAWSOUND]
 Buffers of all loaded sound files.
 
NF_TYPE_RAWSOUND_INFO NF_RAWSOUND [NF_SLOTS_RAWSOUND]
 Information of all sound effects.
 

Detailed Description

Simple helpers to load and play raw PCM sound files.

Function Documentation

◆ NF_InitRawSoundBuffers()

void NF_InitRawSoundBuffers ( void  )

Initialize all buffers and variables to load sound files.

You must use this function once before loading or using any sound file. Remember to initialize the DS sound engine using soundEnable().

◆ NF_LoadRawSound()

void NF_LoadRawSound ( const char *  file,
u32  id,
u32  freq,
u32  format 
)

Load a RAW file from the filesystem to RAM.

To convert sound files to "RAW" format you can use the free program "Switch" http://www.nch.com.au/switch/plus.html. The best parameters for "RAW" files on the DS are: 8 bits signed, mono, 11025 Hz or 22050 Hz.

Example:

// Load "music.raw" to slot 1. This file is encoded as 8 bit at 22050 Hz
NF_LoadRawSound("music", 1, 22050, 0);
void NF_LoadRawSound(const char *file, u32 id, u32 freq, u32 format)
Load a RAW file from the filesystem to RAM.
Definition: nf_sound.c:46
Parameters
fileFile name without extension
idDestination slot number (0 - 31)
freqFrequency of the sample in Hz (11025, 22050, etc)
formatSample format (0 -> 8 bits, 1 -> 16 bits, 2 -> ADPCM).

◆ NF_PlayRawSound()

u32 NF_PlayRawSound ( u32  id,
u32  volume,
u32  pan,
bool  loop,
u32  loopfrom 
)

Play the sound file loaded in the specified slot.

If you want to loop the sound you must also set the sample number where the loop starts.

This fuction also returns the channel number asigned to the playback.

Example:

// Play the sound stored in slot 1 with full volume (127), centered (64),
// with looping enabled from the beginning.
NF_PlayRawSound(1, 127, 64, true, 0);
u32 NF_PlayRawSound(u32 id, u32 volume, u32 pan, bool loop, u32 loopfrom)
Play the sound file loaded in the specified slot.
Definition: nf_sound.c:101

You can use libnds functions to pause, stop and set the volume of the sound while it plays.

Parameters
idSlot number (0 - 31)
volumeVolume (0 - 127)
panPanning. 0: left, 64: center, 127: right.
loopTrue if you want the sound to loop.
loopfromLoop starting point
Returns
Channel number that is playing the sound.

◆ NF_ResetRawSoundBuffers()

void NF_ResetRawSoundBuffers ( void  )

Resets all sound buffers and clears the data in them.

It's useful when you change a level in the game, for example.

◆ NF_UnloadRawSound()

void NF_UnloadRawSound ( u32  id)

Deletes from RAM the sound file stored in the specified slot.

Parameters
idSlot number (0 - 31)