static void *gx_audio_init(const char *device, unsigned rate, unsigned latency) { gx_audio_t *wa = (gx_audio_t*)memalign(32, sizeof(*wa)); if (!wa) return NULL; gx_audio_data = wa; memset(wa, 0, sizeof(*wa)); AUDIO_Init(NULL); AUDIO_RegisterDMACallback(dma_callback); if (rate < 33000) { AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ); g_settings.audio.out_rate = 32000; } else { AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); g_settings.audio.out_rate = 48000; } LWP_InitQueue(&wa->cond); wa->dma_write = BLOCKS - 1; DCFlushRange(wa->data, sizeof(wa->data)); AUDIO_InitDMA((uint32_t)wa->data[wa->dma_next], CHUNK_SIZE); AUDIO_StartDMA(); return wa; }
void GuiElement::LockElement() { // LWP_MutexLock(mutex); for (;;) // loop while element is locked by self { LWP_MutexLock(_lock_mutex); if (_lock_thread == LWP_THREAD_NULL) // element is not locked { _lock_thread = LWP_GetSelf(); // mark as locked _lock_count = 1; // set count of lock to 1 LWP_MutexUnlock(_lock_mutex); return; } else if (_lock_thread == LWP_GetSelf()) // thread is locked by my self { _lock_count++; // inc count of locks; LWP_MutexUnlock(_lock_mutex); return; } else // otherwise the element is locked by an other thread { if (_lock_queue == LWP_TQUEUE_NULL) // no queue - meens it is the first access to the locked element LWP_InitQueue(&_lock_queue); // init queue LWP_MutexUnlock(_lock_mutex); LWP_ThreadSleep(_lock_queue); // and sleep // try lock again; } } }
void __timesystem_init() { if(!exi_wait_inited) { exi_wait_inited = 1; LWP_InitQueue(&time_exi_wait); } }
void ARQ_Init() { u32 level; #ifdef _ARQ_DEBUG printf("ARQ_Init(%02x)\n",__ARQInitFlag); #endif if(__ARQInitFlag) return; _CPU_ISR_Disable(level); __ARQReqPendingLo = NULL; __ARQReqPendingHi = NULL; __ARQCallbackLo = NULL; __ARQCallbackHi = NULL; __ARQChunkSize = ARQ_DEF_CHUNK_SIZE; LWP_InitQueue(&__ARQSyncQueue); __lwp_queue_init_empty(&__ARQReqQueueLo); __lwp_queue_init_empty(&__ARQReqQueueHi); AR_RegisterCallback(__ARInterruptServiceRoutine); __ARQInitFlag = 1; _CPU_ISR_Restore(level); }
static void __usbgecko_init() { u32 i; for(i=0;i<EXI_CHANNEL_2;i++) { LWP_InitQueue(&wait_exi_queue[i]); } usbgecko_inited = 1; }
void SoundHandler::InternalSoundUpdates() { u16 i = 0; LWP_InitQueue(&ThreadQueue); while (!ExitRequested) { LWP_ThreadSleep(ThreadQueue); for(i = 0; i < MAX_DECODERS; ++i) { if(DecoderList[i] == NULL) continue; Decoding = true; DecoderList[i]->Decode(); } Decoding = false; } LWP_CloseQueue(ThreadQueue); ThreadQueue = LWP_TQUEUE_NULL; }
void OSystem_Wii::initSfx() { _mixer = new Audio::MixerImpl(this, 48000); sfx_thread_running = false; sfx_thread_quit = false; sfx_stack = (u8 *) memalign(32, SFX_THREAD_STACKSIZE); if (sfx_stack) { memset(sfx_stack, 0, SFX_THREAD_STACKSIZE); LWP_InitQueue(&sfx_queue); s32 res = LWP_CreateThread(&sfx_thread, sfx_thread_func, _mixer, sfx_stack, SFX_THREAD_STACKSIZE, SFX_THREAD_PRIO); if (res) { printf("ERROR creating sfx thread: %d\n", res); LWP_CloseQueue(sfx_queue); return; } sfx_thread_running = true; } for (u32 i = 0; i < SFX_BUFFERS; ++i) { sound_buffer[i] = (u8 *) memalign(32, SFX_THREAD_FRAG_SIZE); memset(sound_buffer[i], 0, SFX_THREAD_FRAG_SIZE); DCFlushRange(sound_buffer[i], SFX_THREAD_FRAG_SIZE); } _mixer->setReady(true); sb_hw = 0; AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); AUDIO_RegisterDMACallback(audio_switch_buffers); AUDIO_InitDMA((u32) sound_buffer[sb_hw], SFX_THREAD_FRAG_SIZE); AUDIO_StartDMA(); }
static void *gx_audio_init(const char *device, unsigned rate, unsigned latency) { if (g_audio) return g_audio; AUDIO_Init(NULL); AUDIO_RegisterDMACallback(dma_callback); if (rate < 33000) { AUDIO_SetDSPSampleRate(AI_SAMPLERATE_32KHZ); g_settings.audio.out_rate = 32000; } else { AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); g_settings.audio.out_rate = 48000; } if (!g_audio) { g_audio = memalign(32, sizeof(*g_audio)); memset(g_audio, 0, sizeof(*g_audio)); LWP_InitQueue(&g_audio->cond); } else { memset(g_audio->data, 0, sizeof(g_audio->data)); g_audio->dma_busy = g_audio->dma_next = 0; g_audio->write_ptr = 0; g_audio->nonblock = false; } g_audio->dma_write = BLOCKS - 1; DCFlushRange(g_audio->data, sizeof(g_audio->data)); AUDIO_InitDMA((u32)g_audio->data[g_audio->dma_next], CHUNK_SIZE); AUDIO_StartDMA(); return g_audio; }
s32 USBStorage_Initialize() { u32 level; if(__inited) return IPC_OK; _CPU_ISR_Disable(level); LWP_InitQueue(&__usbstorage_waitq); if(!arena_ptr) { arena_ptr = (u8*)ROUNDDOWN32(((u32)SYS_GetArena2Hi() - HEAP_SIZE)); if((u32)arena_ptr < (u32)SYS_GetArena2Lo()) { _CPU_ISR_Restore(level); return IPC_ENOMEM; } SYS_SetArena2Hi(arena_ptr); } __lwp_heap_init(&__heap, arena_ptr, HEAP_SIZE, 32); __inited = true; _CPU_ISR_Restore(level); return IPC_OK; }
static void * ogg_player_thread(private_data_ogg * priv) { int first_time = 1; long ret; //init LWP_InitQueue(&oggplayer_queue); priv[0].vi = ov_info(&priv[0].vf, -1); ASND_Pause(0); priv[0].pcm_indx = 0; priv[0].pcmout_pos = 0; priv[0].eof = 0; priv[0].flag = 0; priv[0].current_section = 0; ogg_thread_running = 1; while (!priv[0].eof && ogg_thread_running) { if (priv[0].flag) LWP_ThreadSleep(oggplayer_queue); // wait only when i have samples to send if (priv[0].flag == 0) // wait to all samples are sent { if (ASND_TestPointer(0, priv[0].pcmout[priv[0].pcmout_pos]) && ASND_StatusVoice(0) != SND_UNUSED) { priv[0].flag |= 64; continue; } if (priv[0].pcm_indx < READ_SAMPLES) { priv[0].flag = 3; if (priv[0].seek_time >= 0) { ov_time_seek(&priv[0].vf, priv[0].seek_time); priv[0].seek_time = -1; } ret = ov_read( &priv[0].vf, (void *) &priv[0].pcmout[priv[0].pcmout_pos][priv[0].pcm_indx], MAX_PCMOUT,/*0,2,1,*/&priv[0].current_section); priv[0].flag &= 192; if (ret == 0) { /* EOF */ if (priv[0].mode & 1) ov_time_seek(&priv[0].vf, 0); // repeat else priv[0].eof = 1; // stops } else if (ret < 0) { /* error in the stream. Not a problem, just reporting it in case we (the app) cares. In this case, we don't. */ if (ret != OV_HOLE) { if (priv[0].mode & 1) ov_time_seek(&priv[0].vf, 0); // repeat else priv[0].eof = 1; // stops } } else { /* we don't bother dealing with sample rate changes, etc, but you'll have to*/ priv[0].pcm_indx += ret >> 1; //get 16 bits samples } } else priv[0].flag = 1; }
static int wii_audio_start(audio_mode_t *am, audio_fifo_t *af) { audio_buf_t *ab; int tbuf = 0, i; uint32_t level; int64_t pts; media_pipe_t *mp; prop_sub_t *s_vol; s_vol = prop_subscribe(PROP_SUB_DIRECT_UPDATE, PROP_TAG_CALLBACK_FLOAT, set_mastervol, NULL, PROP_TAG_ROOT, prop_mastervol, NULL); LWP_InitQueue(&audio_queue); AUDIO_SetDSPSampleRate(AI_SAMPLERATE_48KHZ); AUDIO_RegisterDMACallback(switch_buffers); AUDIO_StartDMA(); while(1) { level = IRQ_Disable(); while(tbuf == cur_buffer) LWP_ThreadSleep(audio_queue); tbuf = cur_buffer; IRQ_Restore(level); ab = af_deq(af, 0); if(am != audio_mode_current) { /* We're not the selected audio output anymore, return. */ if(ab != NULL) ab_free(ab); break; } if(ab != NULL) { const int16_t *src = (const int16_t *)ab->ab_data; int16_t *dst = (int16_t *)buffer[!tbuf]; for(i = 0; i < ADMA_BUFFER_SIZE / 2; i++) *dst++ = (*src++ * audio_vol) >> 16; /* PTS is the time of the first frame of this audio packet */ if((pts = ab->ab_pts) != AV_NOPTS_VALUE && ab->ab_mp != NULL) { #if 0 /* Convert the frame delay into micro seconds */ d = (fr * 1000 / aam->aam_sample_rate) * 1000; /* Subtract it from our timestamp, this will yield the PTS for the sample currently played */ pts -= d; /* Offset with user configure delay */ #endif pts += am->am_audio_delay * 1000; mp = ab->ab_mp; hts_mutex_lock(&mp->mp_clock_mutex); mp->mp_audio_clock = pts; mp->mp_audio_clock_realtime = showtime_get_ts(); mp->mp_audio_clock_epoch = ab->ab_epoch; hts_mutex_unlock(&mp->mp_clock_mutex); } ab_free(ab); } else { memset(buffer[!tbuf], 0, ADMA_BUFFER_SIZE); } DCFlushRange(buffer[!tbuf], ADMA_BUFFER_SIZE); }