libdragon
Defines | Functions | Variables
audio.c File Reference

Audio Subsystem. More...

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#include "libdragon.h"
#include "regsinternal.h"

Defines

#define TV_TYPE_LOC   0x80000300
 Memory location to read which determines the TV type.
#define NUM_BUFFERS   4
 Number of buffers the audio subsytem allocates and manages.
#define CALC_BUFFER(x)   ( ( ( ( x ) / 25 ) >> 3 ) << 3 )
 Macro that calculates the size of a buffer based on frequency.
DAC rates for different regions
#define AI_NTSC_DACRATE   48681812
 NTSC DAC rate.
#define AI_PAL_DACRATE   49656530
 PAL DAC rate.
#define AI_MPAL_DACRATE   48628316
 MPAL DAC rate.
AI Status Register Values
#define AI_STATUS_BUSY   ( 1 << 30 )
 Bit representing that the AI is busy.
#define AI_STATUS_FULL   ( 1 << 31 )
 Bit representing that the AI is full.

Functions

static volatile int __busy ()
 Return whether the AI is currently busy.
static volatile int __full ()
 Return whether the AI is currently full.
static void audio_callback ()
 Send next available chunks of audio data to the AI.
void audio_init (const int frequency, int numbuffers)
 Initialize the audio subsystem.
void audio_init_ex (const int frequency, int numbuffers, int maxsamples, void(*cb)())
 Initialize the audio subsystem (extended)
void audio_close ()
 Close the audio subsystem.
void audio_write (const short *const buffer)
 Write a chunk of audio data.
void audio_write_silence ()
 Write a chunk of silence.
volatile int audio_can_write ()
 Return whether there is an empty buffer to write to.
int audio_get_frequency ()
 Return actual frequency of audio playback.
int audio_get_buffer_length ()
 Get the number of stereo samples that fit into an allocated buffer.
void audio_set_num_samples (int numsamples)
 Change the number of stereo samples to write to each buffer.
short * audio_get_next_buffer (int *lastbuf)
 Return the address of the next buffer to fill.
volatile int audio_send_buffer (int lastbuf)
 Start audio DMA on buffer.

Variables

static void(* _callback )() = NULL
 The actual frequency the AI will run at.
static int _frequency = 0
 The actual frequency the AI will run at.
static int _num_buf = NUM_BUFFERS
 The number of buffers currently allocated.
static int _num_samp = 0
 The number of samples to write into each buffer.
static int _buf_size = 0
 The buffer size in bytes for each buffer allocated.
static short ** buffers = NULL
 Array of pointers to the allocated buffers.
static volatile int now_playing = 0
 Index of the current playing buffer.
static volatile int now_writing = 0
 Index pf the currently being written buffer.
static volatile int buf_full = 0
 Bitmask of buffers indicating which buffers are full.
static struct AI_regs_s *const AI_regs = (struct AI_regs_s *)0xa4500000
 Structure used to interact with the AI registers.

Detailed Description

Audio Subsystem.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines