16 static gSem playComplete;
17 static gU16 playFlags;
18 #define PLAYFLG_USEEVENTS 0x0001
19 #define PLAYFLG_PLAYING 0x0002
20 #define PLAYFLG_ISINIT 0x0004
23 static void PlayTimerCallback(
void *param);
27 #if GAUDIO_NEED_RECORD
30 static gfxQueueGSync recordList;
31 static gU16 recordFlags;
32 #define RECORDFLG_USEEVENTS 0x0001
33 #define RECORDFLG_RECORDING 0x0002
34 #define RECORDFLG_STALLED 0x0004
35 #define RECORDFLG_ISINIT 0x0008
38 static void RecordTimerCallback(
void *param);
43 void _gaudioInit(
void)
46 gfxQueueASyncInit(&playList);
52 #if GAUDIO_NEED_RECORD
53 gfxQueueGSyncInit(&recordList);
60 void _gaudioDeinit(
void)
63 gfxQueueASyncDeinit(&playList);
69 #if GAUDIO_NEED_RECORD
70 gfxQueueGSyncDeinit(&recordList);
81 playFlags &= ~PLAYFLG_ISINIT;
84 playFlags |= PLAYFLG_ISINIT;
89 if (!(playFlags & PLAYFLG_ISINIT)) {
100 playFlags |= PLAYFLG_PLAYING;
105 if ((playFlags & (PLAYFLG_ISINIT|PLAYFLG_PLAYING)) == (PLAYFLG_ISINIT|PLAYFLG_PLAYING))
112 if (playFlags & PLAYFLG_PLAYING)
114 while((pd = (
GDataBuffer *)gfxQueueASyncGet(&playList)))
115 gfxBufferRelease(pd);
123 if (!(playFlags & PLAYFLG_PLAYING))
129 static void PlayTimerCallback(
void *param) {
131 GSourceListener *psl;
142 pe->
type = GEVENT_AUDIO_PLAY;
143 pe->
flags = psl->srcflags;
145 if ((playFlags & PLAYFLG_PLAYING))
147 if (gfxBufferIsAvailable())
155 gtimerStart(&playTimer, PlayTimerCallback, 0, gTrue, gDelayForever);
156 playFlags |= PLAYFLG_USEEVENTS;
157 return (GSourceHandle)&playTimer;
166 return (
GDataBuffer *)gfxQueueASyncGetI(&playList);
170 gfxBufferReleaseI(pd);
172 if (playFlags & PLAYFLG_USEEVENTS)
178 playFlags &= ~PLAYFLG_PLAYING;
180 if (playFlags & PLAYFLG_USEEVENTS)
187 #if GAUDIO_NEED_RECORD
190 recordFlags &= ~RECORDFLG_ISINIT;
193 recordFlags |= RECORDFLG_ISINIT;
198 if (!(recordFlags & RECORDFLG_ISINIT))
201 recordFlags |= RECORDFLG_RECORDING;
202 recordFlags &= ~RECORDFLG_STALLED;
209 if ((recordFlags & (RECORDFLG_RECORDING|RECORDFLG_STALLED)) == RECORDFLG_RECORDING)
211 recordFlags &= ~(RECORDFLG_RECORDING|RECORDFLG_STALLED);
212 while((pd = (
GDataBuffer *)gfxQueueGSyncGet(&recordList, gDelayNone)))
213 gfxBufferRelease(pd);
217 return (
GDataBuffer *)gfxQueueGSyncGet(&recordList, ms);
221 static void RecordTimerCallback(
void *param) {
223 GSourceListener *psl;
233 pe->
type = GEVENT_AUDIO_RECORD;
234 pe->
flags = psl->srcflags;
236 if ((recordFlags & RECORDFLG_RECORDING))
238 if ((recordFlags & RECORDFLG_STALLED))
240 if (!gfxQueueGSyncIsEmpty(&recordList))
248 gtimerStart(&recordTimer, RecordTimerCallback, 0, gTrue, gDelayForever);
249 recordFlags |= RECORDFLG_USEEVENTS;
250 return (GSourceHandle)&recordTimer;
261 if (recordFlags & RECORDFLG_USEEVENTS)
267 recordFlags |= RECORDFLG_STALLED;
269 if (recordFlags & RECORDFLG_USEEVENTS)
#define GAUDIO_RECORD_LOSTEVENT
The event flag values.
#define GAUDIO_PLAY_LOSTEVENT
The event flag values.
#define GAUDIO_PLAY_FREEBLOCK
An audio buffer has been freed.
#define GAUDIO_PLAY_PLAYING
The audio out system is currently playing.
#define GAUDIO_RECORD_STALL
The recording process has stalled due to no free buffers.
#define GAUDIO_RECORD_RECORDING
The audio recording system is currently recording.
#define GAUDIO_RECORD_GOTBUFFER
An audio buffer is ready for processing.
GAUDIO - Audio play driver header file.
GAUDIO - Audio Recording driver header file.
void gaudioPlayReleaseDataBlockI(GDataBuffer *paud)
Release a block of audio data to the free list.
gBool gaudio_play_lld_set_volume(gU8 vol)
Set the output volume.
GDataBuffer * gaudioPlayGetDataBlockI(void)
Get a block of audio data to play.
void gaudioPlayDoneI(void)
Signal that all playing has now stopped.
gBool gaudio_play_lld_init(gU16 channel, gU32 frequency, ArrayDataFormat format)
Initialise the play driver.
void gaudio_play_lld_start(void)
Start the audio output playing.
void gaudio_play_lld_stop(void)
Stop the audio output playing.
void gaudio_record_lld_stop(void)
Stop the audio recording.
void gaudioRecordSaveDataBlockI(GDataBuffer *paud)
Save a block of recorded audio data ready for the application.
void gaudioRecordDoneI(void)
Signal that all recording has now stopped.
void gaudio_record_lld_start(void)
Start the audio recording.
gBool gaudio_record_lld_init(gU16 channel, gU32 frequency, ArrayDataFormat format)
Initialise the record driver.
void gaudioPlayStop(void)
Stop any currently playing sounds.
GSourceHandle gaudioPlayGetSource(void)
Turn on sending results to the GEVENT sub-system.
void gaudioRecordStart(void)
Start the audio recording.
gBool gaudioPlaySetVolume(gU8 vol)
Set the output volume.
GDataBuffer * gaudioRecordGetData(gDelay ms)
Get a filled audio buffer from the recording list.
void gaudioRecordStop(void)
Stop the audio recording.
gBool gaudioPlayInit(gU16 channel, gU32 frequency, ArrayDataFormat format)
Set the audio device to play on the specified channel and with the specified sample frequency.
gBool gaudioRecordInit(gU16 channel, gU32 frequency, ArrayDataFormat format)
Initialise (but not start) the Audio Recording sub-system.
void gaudioPlayPause(void)
Pause any currently playing sounds.
void gaudioPlay(GDataBuffer *paud)
Play the specified sample data.
GSourceHandle gaudioRecordGetSource(void)
Turn on sending results to the GEVENT sub-system.
gBool gaudioPlayWait(gDelay ms)
Wait for any currently playing sounds to complete.
GEvent * geventGetEventBuffer(GSourceListener *psl)
Get the event buffer from the GSourceListener.
void geventSendEvent(GSourceListener *psl)
Called by a source to indicate the listener's event buffer has been filled.
GSourceListener * geventGetSourceListener(GSourceHandle gsh, GSourceListener *lastlr)
Called by a source with a possible event to get a listener record.
enum ArrayDataFormat_e ArrayDataFormat
Sample data formats.
void gfxYield(void)
Yield the current thread.
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxSemDestroy(gSem *psem)
Destroy a Counted Semaphore.
void gfxSemInit(gSem *psem, gSemcount val, gSemcount limit)
Initialise a Counted Semaphore.
void gfxSemSignalI(gSem *psem)
Signal a semaphore.
void gtimerJabI(GTimer *pt)
Jab a timer causing the current period to immediate expire.
void gtimerStart(GTimer *pt, GTimerFunction fn, void *param, gBool periodic, gDelay millisec)
Set a timer going or alter its properties if it is already going.
void gtimerInit(GTimer *pt)
Initialise a timer.
void gtimerDeinit(GTimer *pt)
Deinitialise a timer.
gBool gtimerIsActive(GTimer *pt)
Test if a timer is currently active.
The Audio play event structure.
gU16 flags
The event flags.
GEventType type
The type of this event (GEVENT_AUDIO_PLAY)
The Audio record event structure.
gU16 flags
The event flags.
GEventType type
The type of this event (GEVENT_AUDIO_RECORD)