libnds
Functions
audio.h File Reference

Functions to use the audio channels and microphone from the ARM7. More...

#include <nds/arm7/serial.h>
#include <nds/system.h>
#include <nds/timers.h>

Functions

void disableSound (void)
 Disable sound hardware.
 
void enableSound (void)
 Enable sound hardware and clear sound registers.
 
void installSoundFIFO (void)
 Install the libnds sound FIFO handler.
 
static void micOff (void)
 Turn the microphone OFF.
 
static void micOn (void)
 Turn the microphone ON.
 
u16 micReadData12 (void)
 Read a 12-bit unsigned value from the microphone. More...
 
s16 micReadData16 (void)
 Read a 16-bit signed value from the microphone. More...
 
u8 micReadData8 (void)
 Read a 8-bit unsigned value from the microphone. More...
 
void micSetAmp (u8 control, u8 gain)
 Turn amplifier on or off and set the gain in db. More...
 
void micStartRecording (u8 *buffer, int length, int freq, int timer, bool eightBitSample, MIC_BUF_SWAP_CB bufferSwapCallback)
 Start recording data from the microphone. More...
 
int micStopRecording (void)
 Stop recording data, and return the length of data recorded. More...
 
void micTimerHandler (void)
 Routine that must be called from a timer interrupt to get samples from the microphone.
 
bool soundExtSetFrequencyTWL (unsigned int freq_khz)
 Set extended sound hardware frequency. More...
 

Detailed Description

Functions to use the audio channels and microphone from the ARM7.

Function Documentation

◆ micReadData12()

u16 micReadData12 ( void  )

Read a 12-bit unsigned value from the microphone.

Returns
The 12 bit value.

◆ micReadData16()

s16 micReadData16 ( void  )

Read a 16-bit signed value from the microphone.

Returns
The 16 bit signed value.

◆ micReadData8()

u8 micReadData8 ( void  )

Read a 8-bit unsigned value from the microphone.

Returns
The 8 bit unsigned value.

◆ micSetAmp()

void micSetAmp ( u8  control,
u8  gain 
)

Turn amplifier on or off and set the gain in db.

Parameters
controlUse PM_AMP_ON or PM_AMP_OFF.
gainUse one of PM_GAIN_20, PM_GAIN_40, PM_GAIN_80 or PM_GAIN_160.

◆ micStartRecording()

void micStartRecording ( u8 buffer,
int  length,
int  freq,
int  timer,
bool  eightBitSample,
MIC_BUF_SWAP_CB  bufferSwapCallback 
)

Start recording data from the microphone.

Fills the buffer with data from the microphone. The buffer will be signed sound data at 16 kHz. Once the length of the buffer is reached, no more data will be stored. It uses the specified ARM7 timer.

Parameters
bufferDestination buffer.
lengthDestination buffer length in bytes.
freqFrequency of the recording.
timerHardware timer to use to get samples from the microphone.
eightBitSampleSet to true to record 8 bit samples instead of 12 bit.
bufferSwapCallbackCallback called whenver the buffer is filled.

◆ micStopRecording()

int micStopRecording ( void  )

Stop recording data, and return the length of data recorded.

Returns
Returns the length in bytes.

◆ soundExtSetFrequencyTWL()

bool soundExtSetFrequencyTWL ( unsigned int  freq_khz)

Set extended sound hardware frequency.

Parameters
freq_khzFrequency in KHz. The default is 32, but 47 is allowed too.
Returns
Returns true if the change was successful.