41 u32 outputRate, frameSize;
49 outputRate = osAiSetFrequency(32000);
50 frameSize = (nusched.retraceCount * outputRate + 59) / 60;
67 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootTextStart;
68 nuAuTasks[i].list.t.ucode_boot_size = (u32) rspbootTextEnd - (u32) rspbootTextStart;
70 nuAuTasks[i].list.t.ucode_boot = (u64*) rspbootUcodeBuffer;
71 nuAuTasks[i].list.t.ucode_boot_size = 0x100;
75 nuAuTasks[i].list.t.ucode_data_size = SP_UCODE_DATA_SIZE;
80 nuAuTasks[i].list.t.yield_data_ptr = NULL;
104 OSIntMask mask = osSetIntMask(OS_IM_NONE);
113 OSMesg auMsgBuf[NU_AU_MESG_MAX];
114 OSMesgQueue auRtnMesgQ;
118 Acmd* cmdListAfter_ptr;
127 osCreateMesgQueue(&auMesgQ, auMsgBuf, NU_AU_MESG_MAX);
128 osCreateMesgQueue(&auRtnMesgQ, &auRtnMesgBuf, 1);
129 nuScAddClient(&auClient, &auMesgQ, NU_SC_RETRACE_MSG | NU_SC_PRENMI_MSG);
138 osRecvMesg(&auMesgQ, (OSMesg*)&mesg_type, OS_MESG_BLOCK);
139 switch (*mesg_type) {
140 case NU_SC_RETRACE_MSG:
141 if (cmdList_len != 0 &&
nuAuTaskStop == NU_AU_TASK_RUN) {
142 nuAuTasks[cmdListIndex].msgQ = &auRtnMesgQ;
143 nuAuTasks[cmdListIndex].list.t.data_ptr = (u64*)cmdListBuf;
144 nuAuTasks[cmdListIndex].list.t.data_size = (cmdListAfter_ptr - cmdListBuf) *
sizeof(Acmd);
146 osSendMesg(&nusched.audioRequestMQ, &
nuAuTasks[cmdListIndex], OS_MESG_BLOCK);
149 osRecvMesg(&auRtnMesgQ, NULL, 1);
150 if (++bufferIndex == 3) {
153 if (++cmdListIndex == 3) {
158 if (osAiGetStatus() & AI_STATUS_FIFO_FULL) {
163 sampleSize = osAiGetLength() >> 2;
164 if (cmdList_len != 0 &&
nuAuTaskStop == NU_AU_TASK_RUN) {
165 osAiSetNextBuffer(bufferPtr, samples * 4);
176 cmdListAfter_ptr =
alAudioFrame(cmdListBuf, &cmdList_len, (s16*)osVirtualToPhysical(bufferPtr), samples);
183 case NU_SC_PRENMI_MSG:
196 NUDMABuffer* freeBuffer;
200 s32 addrEnd, buffEnd;
201 NUDMABuffer* lastDmaPtr;
204 return osVirtualToPhysical((
void*)addr);
209 addrEnd = addr + len;
211 while (dmaPtr != NULL) {
212 startAddr = dmaPtr->startAddr;
213 buffEnd = dmaPtr->startAddr + 0x500;
214 if (addr >= startAddr && buffEnd >= addrEnd) {
216 freeBuffer = (NUDMABuffer*)(dmaPtr->ptr + addr - dmaPtr->startAddr);
217 return osVirtualToPhysical(freeBuffer);
218 }
else if (addr < startAddr) {
222 dmaPtr = (NUDMABuffer*)dmaPtr->node.next;
226 if (dmaPtr == NULL) {
230 nuAuDmaState.firstFree = (NUDMABuffer*)dmaPtr->node.next;
233 if (lastDmaPtr != NULL) {
234 alLink(&dmaPtr->node, &lastDmaPtr->node);
238 dmaPtr->node.next = &lastDmaPtr->node;
239 dmaPtr->node.prev = NULL;
240 lastDmaPtr->node.prev = &dmaPtr->node;
243 dmaPtr->node.next = NULL;
244 dmaPtr->node.prev = NULL;
247 freeBuffer = (NUDMABuffer*)dmaPtr->ptr;
250 dmaPtr->startAddr = addr;
254 mesg->hdr.pri = OS_MESG_PRI_NORMAL;
256 mesg->dramAddr = freeBuffer;
257 mesg->devAddr = addr;
259 osEPiStartDma(nuPiCartHandle, mesg, 0);
260 return osVirtualToPhysical(freeBuffer) + delta;
277 NUDMABuffer* dmaPtr = state->firstUsed;
278 NUDMABuffer* nextPtr;
281 while (dmaPtr != NULL) {
282 nextPtr = (NUDMABuffer*)dmaPtr->node.next;
285 if (state->firstUsed == dmaPtr) {
286 state->firstUsed = nextPtr;
291 if (state->firstFree != 0) {
292 alLink(&dmaPtr->node, &state->firstFree->node);
294 state->firstFree = dmaPtr;
295 dmaPtr->node.next = 0;
296 dmaPtr->node.prev = 0;
313 case NU_SC_PRENMI_MSG:
317 case NU_SC_RETRACE_MSG:
319 vol = maxVol - (maxVol / 20) * frameCounter;
335void alLink(ALLink* element, ALLink* after) {
336 element->next = after->next;
337 element->prev = after;
339 if (after->next != NULL) {
340 after->next->prev = element;
342 after->next = element;
346 if (element->next != NULL) {
347 element->next->prev = element->prev;
350 if (element->prev != NULL) {
351 element->prev->next = element->next;
BSS OSThread nuAuMgrThread
u8 AuHeapBase[AUDIO_HEAP_SIZE]
s32 nuAuDmaCallBack(s32 addr, s32 len, void *state, u8 arg3)
BSS NUDMABuffer nuAuDmaBufList[50]
void nuAuPreNMIFuncSet(NUAuPreNMIFunc func)
void alLink(ALLink *element, ALLink *after)
BSS NUDMAState nuAuDmaState
BSS NUScTask nuAuTasks[3]
void nuAuPreNMIProc(NUScMsg mesg_type, u32 frameCounter)
void alUnlink(ALLink *element)
BSS u16 AuInitialGlobalVolume
void create_audio_system(void)
BSS OSMesg nuAuDmaMesgBuf[50]
BSS u64 AuStack[NU_AU_STACK_SIZE/sizeof(u64)]
u8 volatile AuSynUseStereo
void nuAuCleanDMABuffers(void)
ALDMAproc nuAuDmaNew(NUDMAState **state)
NUAuPreNMIFunc nuAuPreNMIFunc
BSS Acmd * AlCmdListBuffers[3]
BSS OSIoMesg nuAuDmaIOMesgBuf[50]
BSS OSMesgQueue nuAuDmaMesgQ
void au_engine_init(s32 outputRate)
void au_set_global_volume(s16 arg0)
void au_use_global_volume(void)
void au_driver_init(AuSynDriver *driver, ALConfig *config)
Acmd * alAudioFrame(Acmd *cmdList, s32 *cmdLen, s16 *outBuf, s32 outLen)
void alHeapInit(ALHeap *hp, u8 *base, s32 len)
void * alHeapAlloc(ALHeap *heap, s32 count, s32 size)
s16 au_get_global_volume(void)
#define AUDIO_COMMAND_LIST_BUFFER_SIZE
#define profiler_rsp_started(which)
#define profiler_rsp_completed(which)
#define profiler_audio_completed()
#define profiler_audio_started()