static int pause_action(int tok, int val) { audio_play(AUD_MENU, 1.0f); switch (tok) { case PAUSE_CONTINUE: audio_pause(0); video_set_grab(0); return goto_state(st_continue); case PAUSE_RESTART: if (progress_same()) { audio_pause(0); video_set_grab(1); return goto_state(&st_play_ready); } break; case PAUSE_EXIT: progress_stat(GAME_NONE); progress_stop(); audio_pause(0); audio_music_stop(); return goto_state(&st_exit); } return 1; }
void pause_action(bool may_fade, bool updatewps) { #if CONFIG_CODEC == SWCODEC /* Do audio first, then update, unless skin were to use its local status in which case, reverse it */ audio_pause(); if (updatewps) update_non_static(); #else if (may_fade && global_settings.fade_on_stop) fade(false, updatewps); else audio_pause(); #endif if (global_settings.pause_rewind) { long newpos; #if (CONFIG_CODEC == SWCODEC) audio_pre_ff_rewind(); #endif newpos = audio_current_track()->elapsed - global_settings.pause_rewind * 1000; audio_ff_rewind(newpos > 0 ? newpos : 0); } (void)may_fade; }
void play_click(int sound) { int snd_bf_pointer; uae_s16 gui_volume; if (!changed_prefs.gui_volume) return; if (changed_prefs.sound_stereo!=1) return; //Only stereo implemented gui_volume = 5-changed_prefs.gui_volume; if (gui_volume<0) gui_volume=0; if (gui_volume>5) gui_volume=5; audio_resume(); for(snd_bf_pointer=0; snd_bf_pointer< (len_click_buffer[sound]-sndbufsize); snd_bf_pointer+=sndbufsize) { memcpy_volume((uae_s16 *)sndbuffer, (uae_s16 *)(click_buffer_pointer[sound]+snd_bf_pointer), sndbufsize, gui_volume); finish_sound_buffer(); } memcpy(sndbuffer, click_buffer_pointer[sound] + snd_bf_pointer, len_click_buffer[sound] - snd_bf_pointer); //The last chunk memset((char *) sndbuffer + len_click_buffer[sound]-snd_bf_pointer,0, sndbufsize -(len_click_buffer[sound]- snd_bf_pointer)); finish_sound_buffer(); clearbuffer(); audio_pause(); }
static int pause_enter(struct state *st, struct state *prev) { st_continue = prev; video_clr_grab(); audio_pause(1); hud_update(0); return pause_gui(); }
void ab_jump_to_A_marker(void) { #if (CONFIG_CODEC != SWCODEC) bool paused = (audio_status() & AUDIO_STATUS_PAUSE) != 0; if ( ! paused ) audio_pause(); #endif audio_ff_rewind(ab_A_marker); #if (CONFIG_CODEC != SWCODEC) if ( ! paused ) audio_resume(); #endif }
/* ----------------------------------------------------------------------- */ bool bookmark_autobookmark(bool prompt_ok) { char* bookmark; bool update; if (!bookmark_is_bookmarkable_state()) return false; audio_pause(); /* first pause playback */ update = (global_settings.autoupdatebookmark && bookmark_exists()); bookmark = create_bookmark(); #if CONFIG_CODEC != SWCODEC /* Workaround for inability to speak when paused: all callers will just do audio_stop() when we return, so we can do it right away. This makes it possible to speak the "Create a Bookmark?" prompt and the "Bookmark Created" splash. */ audio_stop(); #endif if (update) return write_bookmark(true, bookmark); switch (global_settings.autocreatebookmark) { case BOOKMARK_YES: return write_bookmark(true, bookmark); case BOOKMARK_NO: return false; case BOOKMARK_RECENT_ONLY_YES: return write_bookmark(false, bookmark); } #ifdef HAVE_LCD_BITMAP const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY)}; const struct text_message message={lines, 1}; #else const char *lines[]={ID2P(LANG_AUTO_BOOKMARK_QUERY), str(LANG_CONFIRM_WITH_BUTTON)}; const struct text_message message={lines, 2}; #endif if(prompt_ok && gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) { if (global_settings.autocreatebookmark == BOOKMARK_RECENT_ONLY_ASK) return write_bookmark(false, bookmark); else return write_bookmark(true, bookmark); } return false; }
static OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData) { int amt=av_fifo_size(ao->buffer); int req=(inNumFrames)*ao->packetSize; if(amt>req) amt=req; if(amt) read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt); else audio_pause(); ioData->mBuffers[0].mDataByteSize = amt; return noErr; }
/* takes care of seeking to a track in a playlist * returns false if audio isn't playing */ static bool seek(unsigned long pos) { if (!(audio_status() & AUDIO_STATUS_PLAY)) { return false; } else { #if (CONFIG_CODEC == SWCODEC) audio_pre_ff_rewind(); audio_ff_rewind(pos); #else audio_pause(); audio_ff_rewind(pos); audio_resume(); #endif return true; } }
static void *cpu_thread(void *dummyptr) { assert(pthread_self() == cpu_thread_id); LOG("cpu_thread : initialized..."); struct timespec deltat; #if !MOBILE_DEVICE struct timespec disk_motor_time; #endif struct timespec t0; // the target timer struct timespec ti, tj; // actual time samples bool negative = false; long drift_adj_nsecs = 0; // generic drift adjustment between target and actual int debugging_cycles0 = 0; int debugging_cycles = 0; #if DEBUG_TIMING unsigned long dbg_ticks = 0; int speaker_neg_feedback = 0; int speaker_pos_feedback = 0; unsigned int dbg_cycles_executed = 0; #endif do { #ifdef AUDIO_ENABLED LOG("CPUTHREAD %lu LOCKING FOR MAYBE INITIALIZING AUDIO ...", cpu_thread_id); pthread_mutex_lock(&interface_mutex); if (emul_reinitialize_audio) { emul_reinitialize_audio = false; speaker_destroy(); MB_Destroy(); audio_shutdown(); audio_init(); speaker_init(); MB_Initialize(); } pthread_mutex_unlock(&interface_mutex); LOG("UNLOCKING FOR MAYBE INITIALIZING AUDIO ..."); #endif if (emul_reinitialize) { reinitialize(); } LOG("cpu_thread : begin main loop ..."); clock_gettime(CLOCK_MONOTONIC, &t0); do { SCOPE_TRACE_CPU("CPU mainloop"); // -LOCK----------------------------------------------------------------------------------------- SAMPLE ti #ifdef AUDIO_ENABLED if (UNLIKELY(emul_pause_audio)) { emul_pause_audio = false; audio_pause(); } #endif pthread_mutex_lock(&interface_mutex); #ifdef AUDIO_ENABLED if (UNLIKELY(emul_resume_audio)) { emul_resume_audio = false; audio_resume(); } #endif clock_gettime(CLOCK_MONOTONIC, &ti); deltat = timespec_diff(t0, ti, &negative); if (deltat.tv_sec) { if (!is_fullspeed) { TIMING_LOG("NOTE : serious divergence from target time ..."); } t0 = ti; deltat = timespec_diff(t0, ti, &negative); } t0 = timespec_add(t0, EXECUTION_PERIOD_NSECS); // expected interval drift_adj_nsecs = negative ? ~deltat.tv_nsec : deltat.tv_nsec; // set up increment & decrement counters cpu65_cycles_to_execute = (cycles_persec_target / 1000); // cycles_persec_target * EXECUTION_PERIOD_NSECS / NANOSECONDS_PER_SECOND if (!is_fullspeed) { cpu65_cycles_to_execute += cycles_speaker_feedback; } if (cpu65_cycles_to_execute < 0) { cpu65_cycles_to_execute = 0; } #ifdef AUDIO_ENABLED MB_StartOfCpuExecute(); #endif if (is_debugging) { debugging_cycles0 = cpu65_cycles_to_execute; debugging_cycles = cpu65_cycles_to_execute; } do { if (is_debugging) { cpu65_cycles_to_execute = 1; } cpu65_cycle_count = 0; cycles_checkpoint_count = 0; cpu65_run(); // run emulation for cpu65_cycles_to_execute cycles ... if (is_debugging) { debugging_cycles -= cpu65_cycle_count; if (c_debugger_should_break() || (debugging_cycles <= 0)) { int err = 0; if ((err = pthread_cond_signal(&dbg_thread_cond))) { ERRLOG("pthread_cond_signal : %d", err); } if ((err = pthread_cond_wait(&cpu_thread_cond, &interface_mutex))) { ERRLOG("pthread_cond_wait : %d", err); } if (debugging_cycles <= 0) { cpu65_cycle_count = debugging_cycles0 - debugging_cycles/*<=0*/; break; } } } if (emul_reinitialize) { reinitialize(); } } while (is_debugging); #if DEBUG_TIMING dbg_cycles_executed += cpu65_cycle_count; #endif g_dwCyclesThisFrame += cpu65_cycle_count; #ifdef AUDIO_ENABLED MB_UpdateCycles(); // update 6522s (NOTE: do this before updating cycles_count_total) #endif timing_checkpoint_cycles(); #if CPU_TRACING cpu65_trace_checkpoint(); #endif #ifdef AUDIO_ENABLED speaker_flush(); // play audio #endif if (g_dwCyclesThisFrame >= dwClksPerFrame) { g_dwCyclesThisFrame -= dwClksPerFrame; #ifdef AUDIO_ENABLED MB_EndOfVideoFrame(); #endif } clock_gettime(CLOCK_MONOTONIC, &tj); pthread_mutex_unlock(&interface_mutex); // -UNLOCK--------------------------------------------------------------------------------------- SAMPLE tj #if !MOBILE_DEVICE if (timing_shouldAutoAdjustSpeed()) { disk_motor_time = timespec_diff(disk6.motor_time, tj, &negative); assert(!negative); if (!is_fullspeed && #ifdef AUDIO_ENABLED !speaker_isActive() && #endif !video_isDirty() && (!disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS)) ) { TIMING_LOG("auto switching to full speed"); _timing_initialize(CPU_SCALE_FASTEST); } } #endif if (!is_fullspeed) { deltat = timespec_diff(ti, tj, &negative); assert(!negative); long sleepfor = 0; if (!deltat.tv_sec) { sleepfor = EXECUTION_PERIOD_NSECS - drift_adj_nsecs - deltat.tv_nsec; } if (sleepfor <= 0) { // lagging ... static time_t throttle_warning = 0; if (t0.tv_sec - throttle_warning > 0) { TIMING_LOG("not sleeping to catch up ... %ld . %ld", deltat.tv_sec, deltat.tv_nsec); throttle_warning = t0.tv_sec; } } else { deltat.tv_sec = 0; deltat.tv_nsec = sleepfor; TRACE_CPU_BEGIN("sleep"); nanosleep(&deltat, NULL); TRACE_CPU_END(); } #if DEBUG_TIMING // collect timing statistics if (speaker_neg_feedback > cycles_speaker_feedback) { speaker_neg_feedback = cycles_speaker_feedback; } if (speaker_pos_feedback < cycles_speaker_feedback) { speaker_pos_feedback = cycles_speaker_feedback; } dbg_ticks += EXECUTION_PERIOD_NSECS; if ((dbg_ticks % NANOSECONDS_PER_SECOND) == 0) { TIMING_LOG("tick:(%ld.%ld) real:(%ld.%ld) cycles exe: %d ... speaker feedback: %d/%d", t0.tv_sec, t0.tv_nsec, ti.tv_sec, ti.tv_nsec, dbg_cycles_executed, speaker_neg_feedback, speaker_pos_feedback); dbg_cycles_executed = 0; dbg_ticks = 0; speaker_neg_feedback = 0; speaker_pos_feedback = 0; } #endif } #if !MOBILE_DEVICE if (timing_shouldAutoAdjustSpeed()) { if (is_fullspeed && ( #ifdef AUDIO_ENABLED speaker_isActive() || #endif video_isDirty() || (disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS))) ) { double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor; if (speed < CPU_SCALE_FASTEST) { TIMING_LOG("auto switching to configured speed"); _timing_initialize(speed); } } } #endif if (UNLIKELY(emul_reinitialize)) { break; } #ifdef AUDIO_ENABLED if (UNLIKELY(emul_reinitialize_audio)) { break; } #endif if (UNLIKELY(cpu_shutting_down)) { break; } } while (1); if (UNLIKELY(cpu_shutting_down)) { break; } } while (1); #ifdef AUDIO_ENABLED speaker_destroy(); MB_Destroy(); audio_shutdown(); #endif return NULL; }
static javacall_result video_pause(javacall_handle handle) { return audio_pause(handle); }
/* * Here's where all the action takes place! */ void real_main (int argc, char **argv) { show_version (); #if defined (NATMEM_OFFSET) if (NATMEM_OFFSET == 0 && sizeof (void*) < 8) { write_log ("NATMEM_OFFSET is 0; I hope you used 'uae-preloader' to load me, or else ...\n"); } #endif #ifdef FILESYS currprefs.mountinfo = changed_prefs.mountinfo = &options_mountinfo; #endif restart_program = 1; #ifdef _WIN32 sprintf (restart_config, "%sConfigurations\\", start_path); #endif strcat (restart_config, OPTIONSFILENAME); /* Initial state is stopped */ uae_target_state = UAE_STATE_STOPPED; while (uae_target_state != UAE_STATE_QUITTING) { int want_gui; set_state (uae_target_state); do_preinit_machine (argc, argv); /* Should we open the GUI? TODO: This mess needs to go away */ want_gui = currprefs.start_gui; if (restart_program == 2) want_gui = 0; else if (restart_program == 3) want_gui = 1; changed_prefs = currprefs; if (want_gui) { /* Handle GUI at start-up */ int err = gui_open (); if (err >= 0) { do { gui_handle_events (); uae_msleep (10); } while (!uae_state_change_pending ()); } else if (err == - 1) { if (restart_program == 3) { restart_program = 0; uae_quit (); } } else uae_quit (); currprefs = changed_prefs; fix_options (); inputdevice_init (); } restart_program = 0; if (uae_target_state == UAE_STATE_QUITTING) break; uae_target_state = UAE_STATE_COLD_START; /* Start emulator proper. */ if (!do_init_machine ()) break; while (uae_target_state != UAE_STATE_QUITTING && uae_target_state != UAE_STATE_STOPPED) { /* Reset */ set_state (uae_target_state); do_reset_machine (uae_state == UAE_STATE_COLD_START); /* Running */ uae_target_state = UAE_STATE_RUNNING; /* * Main Loop */ do { set_state (uae_target_state); /* Run emulator. */ do_run_machine (); if (uae_target_state == UAE_STATE_PAUSED) { /* Paused */ set_state (uae_target_state); audio_pause (); /* While UAE is paused we have to handle * input events, etc. ourselves. */ do { gui_handle_events (); handle_events (); /* Manually pump input device */ inputdevicefunc_keyboard.read (); inputdevicefunc_mouse.read (); inputdevicefunc_joystick.read (); inputdevice_handle_inputcode (); /* Don't busy wait. */ uae_msleep (10); } while (!uae_state_change_pending ()); audio_resume (); } } while (uae_target_state == UAE_STATE_RUNNING); /* * End of Main Loop * * We're no longer running or paused. */ set_inhibit_frame (IHF_QUIT_PROGRAM); #ifdef FILESYS /* Ensure any cached changes to virtual filesystem are flushed before * resetting or exitting. */ filesys_prepare_reset (); #endif } /* while (!QUITTING && !STOPPED) */ do_exit_machine (); /* TODO: This stuff is a hack. What we need to do is * check whether a config GUI is available. If not, * then quit. */ restart_program = 3; } zfile_exit (); }
int psp_main_menu(void) { gp2xCtrlData c; long new_pad; long old_pad; int last_time; int end_menu; audio_pause(); cap32_save_back_to_blit(); psp_kbd_wait_no_button(); old_pad = 0; last_time = 0; end_menu = 0; while (! end_menu) { psp_display_screen_menu(); psp_sdl_flip(); while (1) { gp2xCtrlReadBufferPositive(&c, 1); c.Buttons &= PSP_ALL_BUTTON_MASK; if (c.Buttons) break; } new_pad = c.Buttons; if ((old_pad != new_pad) || ((c.TimeStamp - last_time) > PSP_MENU_MIN_TIME)) { last_time = c.TimeStamp; old_pad = new_pad; } else continue; if ((c.Buttons & GP2X_CTRL_LTRIGGER) == GP2X_CTRL_LTRIGGER) { psp_settings_menu(); old_pad = new_pad = 0; } else if ((c.Buttons & GP2X_CTRL_RTRIGGER) == GP2X_CTRL_RTRIGGER) { psp_main_menu_reset(); end_menu = 1; } else if ((new_pad == GP2X_CTRL_LEFT ) || (new_pad == GP2X_CTRL_RIGHT) || (new_pad == GP2X_CTRL_CROSS) || (new_pad == GP2X_CTRL_CIRCLE)) { int step = 0; if (new_pad & GP2X_CTRL_RIGHT) { step = 1; } else if (new_pad & GP2X_CTRL_LEFT) { step = -1; } switch (cur_menu_id ) { case MENU_LOAD_SLOT : if (step) psp_main_menu_cur_slot(step); else if (psp_main_menu_load_slot()) end_menu = 1; break; case MENU_SAVE_SLOT : if (step) psp_main_menu_cur_slot(step); else psp_main_menu_save_slot(); break; case MENU_DEL_SLOT : if (step) psp_main_menu_cur_slot(step); else psp_main_menu_del_slot(); break; case MENU_LOAD_SNA : if (psp_main_menu_load(FMGR_FORMAT_SNA, 0)) end_menu = 1; old_pad = new_pad = 0; break; case MENU_LOAD_DSKA : if (psp_main_menu_load(FMGR_FORMAT_DSK, 'A')) { if (CPC.psp_explore_disk == CPC_EXPLORE_LOAD) { if (psp_disk_menu()) { end_menu = 1; } } else if (CPC.psp_explore_disk >= CPC_EXPLORE_AUTO) { if (psp_disk_auto()) { end_menu = 1; } } } old_pad = new_pad = 0; break; case MENU_LOAD_DSKB : psp_main_menu_load(FMGR_FORMAT_DSK, 'B'); old_pad = new_pad = 0; break; case MENU_COMMAND : if (step) psp_main_menu_cur_command(step); else { psp_main_menu_command(); end_menu = 1; } break; case MENU_EDITOR : psp_main_menu_editor(); old_pad = new_pad = 0; break; case MENU_CHEATS : psp_cheat_menu(); old_pad = new_pad = 0; break; case MENU_KEYBOARD : psp_keyboard_menu(); old_pad = new_pad = 0; break; case MENU_JOYSTICK : psp_joystick_menu(); old_pad = new_pad = 0; break; case MENU_SETTINGS : psp_settings_menu(); old_pad = new_pad = 0; break; case MENU_SCREENSHOT : psp_main_menu_screenshot(); end_menu = 1; break; case MENU_RESET : psp_main_menu_reset(); end_menu = 1; break; case MENU_BACK : end_menu = 1; break; case MENU_EXIT : psp_main_menu_exit(); break; case MENU_HELP : psp_help_menu(); old_pad = new_pad = 0; break; } } else if(new_pad & GP2X_CTRL_UP) { if (cur_menu_id > 0) cur_menu_id--; else cur_menu_id = MAX_MENU_ITEM-1; } else if(new_pad & GP2X_CTRL_DOWN) { if (cur_menu_id < (MAX_MENU_ITEM-1)) cur_menu_id++; else cur_menu_id = 0; } else if(new_pad & GP2X_CTRL_SQUARE) { /* Cancel */ end_menu = -1; } else if((new_pad & GP2X_CTRL_SELECT) == GP2X_CTRL_SELECT) { /* Back to CPC */ end_menu = 1; } } psp_kbd_wait_no_button(); psp_sdl_clear_screen( PSP_MENU_BLACK_COLOR ); psp_sdl_flip(); psp_sdl_clear_screen( PSP_MENU_BLACK_COLOR ); psp_sdl_flip(); psp_sdl_clear_blit(0); audio_resume(); return 1; }
static void *cpu_thread(void *dummyptr) { #ifndef NDEBUG // Spamsung Galaxy Y running Gingerbread triggers this, wTf?! ASSERT_ON_CPU_THREAD(); #endif LOG("cpu_thread : initialized..."); struct timespec deltat = { 0 }; struct timespec disk_motor_time = { 0 }; struct timespec t0 = { 0 }; // the target timer struct timespec ti = { 0 }; // actual before time sample struct timespec tj = { 0 }; // actual after time sample bool negative = false; long drift_adj_nsecs = 0; // generic drift adjustment between target and actual int debugging_cycles = 0; unsigned long dbg_ticks = 0; #if DEBUG_TIMING int speaker_neg_feedback = 0; int speaker_pos_feedback = 0; unsigned long dbg_cycles_executed = 0; #endif audio_init(); speaker_init(); MB_Initialize(); run_args.emul_reinitialize = 1; cpu_runloop: do { LOG("CPUTHREAD %lu LOCKING FOR MAYBE INITIALIZING AUDIO ...", (unsigned long)cpu_thread_id); pthread_mutex_lock(&interface_mutex); if (emul_reinitialize_audio) { emul_reinitialize_audio = false; speaker_destroy(); extern void MB_SoftDestroy(void); MB_SoftDestroy(); audio_shutdown(); audio_init(); speaker_init(); extern void MB_SoftInitialize(void); MB_SoftInitialize(); } pthread_mutex_unlock(&interface_mutex); LOG("UNLOCKING FOR MAYBE INITIALIZING AUDIO ..."); if (run_args.emul_reinitialize) { reinitialize(); } LOG("cpu_thread : begin main loop ..."); clock_gettime(CLOCK_MONOTONIC, &t0); do { ////SCOPE_TRACE_CPU("CPU mainloop"); // -LOCK----------------------------------------------------------------------------------------- SAMPLE ti if (UNLIKELY(emul_pause_audio)) { emul_pause_audio = false; audio_pause(); } pthread_mutex_lock(&interface_mutex); if (UNLIKELY(emul_resume_audio)) { emul_resume_audio = false; audio_resume(); } if (UNLIKELY(emul_video_dirty)) { emul_video_dirty = false; video_setDirty(A2_DIRTY_FLAG); } clock_gettime(CLOCK_MONOTONIC, &ti); deltat = timespec_diff(t0, ti, &negative); if (deltat.tv_sec) { if (!is_fullspeed) { TIMING_LOG("NOTE : serious divergence from target time ..."); } t0 = ti; deltat = timespec_diff(t0, ti, &negative); } t0 = timespec_add(t0, EXECUTION_PERIOD_NSECS); // expected interval drift_adj_nsecs = negative ? ~deltat.tv_nsec : deltat.tv_nsec; // set up increment & decrement counters run_args.cpu65_cycles_to_execute = (cycles_persec_target / 1000); // cycles_persec_target * EXECUTION_PERIOD_NSECS / NANOSECONDS_PER_SECOND if (!is_fullspeed) { run_args.cpu65_cycles_to_execute += cycles_speaker_feedback; } if (run_args.cpu65_cycles_to_execute < 0) { run_args.cpu65_cycles_to_execute = 0; } MB_StartOfCpuExecute(); if (is_debugging) { debugging_cycles = run_args.cpu65_cycles_to_execute; } do { if (is_debugging) { run_args.cpu65_cycles_to_execute = 1; } run_args.cpu65_cycle_count = 0; cycles_checkpoint_count = 0; cpu65_run(&run_args); // run emulation for cpu65_cycles_to_execute cycles ... #if DEBUG_TIMING dbg_cycles_executed += run_args.cpu65_cycle_count; #endif if (is_debugging) { debugging_cycles -= run_args.cpu65_cycle_count; timing_checkpointCycles(); if (c_debugger_should_break() || (debugging_cycles <= 0)) { int err = 0; if ((err = pthread_cond_signal(&dbg_thread_cond))) { LOG("pthread_cond_signal : %d", err); } if ((err = pthread_cond_wait(&cpu_thread_cond, &interface_mutex))) { LOG("pthread_cond_wait : %d", err); } if (debugging_cycles <= 0) { break; } } if (run_args.emul_reinitialize) { pthread_mutex_unlock(&interface_mutex); goto cpu_runloop; } } } while (is_debugging); MB_UpdateCycles(); // TODO : modularize MB and other peripheral card cycles/interrupts ... speaker_flush(); // play audio TRACE_CPU_BEGIN("advance scanner"); video_scannerUpdate(); TRACE_CPU_END(); clock_gettime(CLOCK_MONOTONIC, &tj); pthread_mutex_unlock(&interface_mutex); // -UNLOCK--------------------------------------------------------------------------------------- SAMPLE tj if (timing_shouldAutoAdjustSpeed() && !is_fullspeed) { disk_motor_time = timespec_diff(disk6.motor_time, tj, &negative); if (UNLIKELY(negative)) { LOG("WHOA... time went backwards #1! Did you just cross a timezone?"); disk_motor_time.tv_sec = 1; } if (!speaker_isActive() && !video_isDirty(A2_DIRTY_FLAG) && (disk6.disk[disk6.drive].file_name != NULL) && !disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS) ) { TIMING_LOG("auto switching to full speed"); _timing_initialize(CPU_SCALE_FASTEST); } } if (!is_fullspeed) { deltat = timespec_diff(ti, tj, &negative); if (UNLIKELY(negative)) { LOG("WHOA... time went backwards #2! Did you just cross a timezone?"); deltat.tv_sec = 1; } long sleepfor = 0; if (LIKELY(!deltat.tv_sec)) { sleepfor = EXECUTION_PERIOD_NSECS - drift_adj_nsecs - deltat.tv_nsec; } if (sleepfor <= 0) { // lagging ... static time_t throttle_warning = 0; if (t0.tv_sec - throttle_warning > 0) { TIMING_LOG("not sleeping to catch up ... %ld . %ld", deltat.tv_sec, deltat.tv_nsec); throttle_warning = t0.tv_sec; } } else { deltat.tv_sec = 0; deltat.tv_nsec = sleepfor; ////TRACE_CPU_BEGIN("sleep"); nanosleep(&deltat, NULL); ////TRACE_CPU_END(); } #if DEBUG_TIMING // collect timing statistics if (speaker_neg_feedback > cycles_speaker_feedback) { speaker_neg_feedback = cycles_speaker_feedback; } if (speaker_pos_feedback < cycles_speaker_feedback) { speaker_pos_feedback = cycles_speaker_feedback; } if ((dbg_ticks % NANOSECONDS_PER_SECOND) == 0) { TIMING_LOG("tick:(%ld.%ld) real:(%ld.%ld) cycles exe: %d ... speaker feedback: %d/%d", t0.tv_sec, t0.tv_nsec, ti.tv_sec, ti.tv_nsec, dbg_cycles_executed, speaker_neg_feedback, speaker_pos_feedback); dbg_cycles_executed = 0; speaker_neg_feedback = 0; speaker_pos_feedback = 0; } #endif if ((dbg_ticks % NANOSECONDS_PER_SECOND) == 0) { dbg_ticks = 0; } } if (timing_shouldAutoAdjustSpeed() && is_fullspeed) { disk_motor_time = timespec_diff(disk6.motor_time, tj, &negative); if (UNLIKELY(negative)) { LOG("WHOA... time went backwards #3! Did you just cross a timezone?"); disk_motor_time.tv_sec = 1; } if (speaker_isActive() || video_isDirty(A2_DIRTY_FLAG) || (disk6.motor_off && (disk_motor_time.tv_sec || disk_motor_time.tv_nsec > DISK_MOTOR_QUIET_NSECS)) ) { double speed = alt_speed_enabled ? cpu_altscale_factor : cpu_scale_factor; if (speed <= CPU_SCALE_FASTEST_PIVOT) { TIMING_LOG("auto switching to configured speed"); _timing_initialize(speed); } } } if (UNLIKELY(run_args.emul_reinitialize)) { break; } if (UNLIKELY(emul_reinitialize_audio)) { break; } if (UNLIKELY(cpu_shutting_down)) { break; } } while (1); if (UNLIKELY(cpu_shutting_down)) { break; } } while (1); speaker_destroy(); MB_Destroy(); audio_shutdown(); cpu_thread_id = 0; cpu_pause(); disk6_eject(0); disk6_eject(1); return NULL; }
void SACM_Pause(void) { audio_pause(&__gaudio); }
/* Receive a command from the client and execute it. */ static void handle_command (const int client_id) { int cmd; int err = 0; struct client *cli = &clients[client_id]; if (!get_int(cli->socket, &cmd)) { logit ("Failed to get command from the client"); close (cli->socket); del_client (cli); return; } switch (cmd) { case CMD_QUIT: logit ("Exit request from the client"); close (cli->socket); del_client (cli); server_quit = 1; break; case CMD_LIST_CLEAR: logit ("Clearing the list"); audio_plist_clear (); break; case CMD_LIST_ADD: if (!req_list_add(cli)) err = 1; break; case CMD_PLAY: if (!req_play(cli)) err = 1; break; case CMD_DISCONNECT: logit ("Client disconnected"); close (cli->socket); del_client (cli); break; case CMD_PAUSE: audio_pause (); break; case CMD_UNPAUSE: audio_unpause (); break; case CMD_STOP: audio_stop (); break; case CMD_GET_CTIME: if (!send_data_int(cli, MAX(0, audio_get_time()))) err = 1; break; case CMD_SEEK: if (!req_seek(cli)) err = 1; break; case CMD_JUMP_TO: if (!req_jump_to(cli)) err = 1; break; case CMD_GET_SNAME: if (!send_sname(cli)) err = 1; break; case CMD_GET_STATE: if (!send_data_int(cli, audio_get_state())) err = 1; break; case CMD_GET_BITRATE: if (!send_data_int(cli, sound_info.bitrate)) err = 1; break; case CMD_GET_AVG_BITRATE: if (!send_data_int(cli, sound_info.avg_bitrate)) err = 1; break; case CMD_GET_RATE: if (!send_data_int(cli, sound_info.rate)) err = 1; break; case CMD_GET_CHANNELS: if (!send_data_int(cli, sound_info.channels)) err = 1; break; case CMD_NEXT: audio_next (); break; case CMD_PREV: audio_prev (); break; case CMD_PING: if (!send_int(cli->socket, EV_PONG)) err = 1; break; case CMD_GET_OPTION: if (!send_option(cli)) err = 1; break; case CMD_SET_OPTION: if (!get_set_option(cli)) err = 1; break; case CMD_GET_MIXER: if (!send_data_int(cli, audio_get_mixer())) err = 1; break; case CMD_SET_MIXER: if (!set_mixer(cli)) err = 1; break; case CMD_DELETE: if (!delete_item(cli)) err = 1; break; case CMD_SEND_PLIST_EVENTS: cli->wants_plist_events = 1; logit ("Request for events"); break; case CMD_GET_PLIST: if (!get_client_plist(cli)) err = 1; break; case CMD_SEND_PLIST: if (!req_send_plist(cli)) err = 1; break; case CMD_CAN_SEND_PLIST: cli->can_send_plist = 1; break; case CMD_CLI_PLIST_ADD: case CMD_CLI_PLIST_DEL: case CMD_CLI_PLIST_CLEAR: case CMD_CLI_PLIST_MOVE: if (!plist_sync_cmd(cli, cmd)) err = 1; break; case CMD_LOCK: if (!client_lock(cli)) err = 1; break; case CMD_UNLOCK: if (!client_unlock(cli)) err = 1; break; case CMD_GET_SERIAL: if (!send_serial(cli)) err = 1; break; case CMD_PLIST_GET_SERIAL: if (!req_plist_get_serial(cli)) err = 1; break; case CMD_PLIST_SET_SERIAL: if (!req_plist_set_serial(cli)) err = 1; break; case CMD_GET_TAGS: if (!req_get_tags(cli)) err = 1; break; case CMD_TOGGLE_MIXER_CHANNEL: req_toggle_mixer_channel (); break; case CMD_TOGGLE_SOFTMIXER: req_toggle_softmixer (); break; case CMD_GET_MIXER_CHANNEL_NAME: if (!req_get_mixer_channel_name(cli)) err = 1; break; case CMD_GET_FILE_TAGS: if (!get_file_tags(client_id)) err = 1; break; case CMD_ABORT_TAGS_REQUESTS: if (!abort_tags_requests(client_id)) err = 1; break; case CMD_LIST_MOVE: if (!req_list_move(cli)) err = 1; break; case CMD_TOGGLE_EQUALIZER: req_toggle_equalizer(); break; case CMD_EQUALIZER_REFRESH: req_equalizer_refresh(); break; case CMD_EQUALIZER_PREV: req_equalizer_prev(); break; case CMD_EQUALIZER_NEXT: req_equalizer_next(); break; case CMD_TOGGLE_MAKE_MONO: req_toggle_make_mono(); break; case CMD_QUEUE_ADD: if (!req_queue_add(cli)) err = 1; break; case CMD_QUEUE_DEL: if (!req_queue_del(cli)) err = 1; break; case CMD_QUEUE_CLEAR: logit ("Clearing the queue"); audio_queue_clear (); add_event_all (EV_QUEUE_CLEAR, NULL); break; case CMD_QUEUE_MOVE: if (!req_queue_move(cli)) err = 1; break; case CMD_GET_QUEUE: if (!req_send_queue(cli)) err = 1; break; default: logit ("Bad command (0x%x) from the client", cmd); err = 1; } if (err) { logit ("Closing client connection due to error"); close (cli->socket); del_client (cli); } }
unsigned long kb_action(unsigned short fkey, struct setting_key *kcol, int kcount) { unsigned short kp = keypurpose_null; int i; for(i=0; i<kcount; i++) { if(kcol[i].kcomb == fkey) { kp = kcol[i].kaction; break; }else if(kcol[i].kcomb == 0 && kcol[i].kaction == keypurpose_null){ return 0; } } if(kp == keypurpose_null)return 0; switch(kp) { case keypurpose_play: audio_play(); break; case keypurpose_pause: audio_pause(); break; case keypurpose_stop: audio_stop(); break; case keypurpose_load: GlobalFunction(Function_OpenFileDialog); break; case keypurpose_rewind: GlobalFunction(Function_Rewind); break; case keypurpose_forward: GlobalFunction(Function_Forward); break; case keypurpose_previous: audio_playlist_previous(); break; case keypurpose_next: audio_playlist_next(); break; case keypurpose_eject: if(settings.player.selected_drive) { if(audio_playlist_getsource(audio_playlist_getcurrentindex())[0] == settings.player.selected_drive)audio_stop(); audio_input_drive_eject((char)settings.player.selected_drive); } break; case keypurpose_select: if(settings.player.selected_drive) { int i, c = audio_input_drive_gettracks((char)settings.player.selected_drive); letter buf[128]; letter buf2[32]; if(c > 0) { audio_playlist_clear(); for(i=0; i<c; i++) { buf[0] = (letter)settings.player.selected_drive; str_cpy(buf + 1, uni(":\\Track")); memset(buf2, 0, sizeof(buf2)); str_itos(i + 1, buf2, 10); str_cat(buf, buf2); str_cat(buf, uni(".cda")); audio_playlist_add(buf, 0, 0); } fennec_refresh(fennec_v_refresh_force_high); } } break; case keypurpose_panelsw_main: GlobalFunction(Function_MainPanel); break; case keypurpose_panelsw_color: GlobalFunction(Function_SelectThemePanel); break; case keypurpose_panelsw_visualization: //Display_ShowPanel(PanelID_Visualization); break; case keypurpose_panelsw_equalizer: GlobalFunction(Function_EqualizerPanel); break; case keypurpose_panelsw_mediainfo: break; case keypurpose_panelsw_playlist: break; case keypurpose_panelnext: //Display_ShowPanel_Next(); break; case keypurpose_panelprevious: //Display_ShowPanel_Back(); break; case keypurpose_exit: fennec_power_set(fennec_power_mode_default); break; case keypurpose_sleep: fennec_power_sleep(); break; case keypurpose_minimize: ShowWindow(window_main,SW_MINIMIZE); break; case keypurpose_refresh: fennec_refresh(fennec_v_refresh_force_full); break; case keypurpose_conversion: basewindows_show_conversion(0); break; case keypurpose_ripping: basewindows_show_ripping(1); break; case keypurpose_joining: BaseWindows_ShowJoining(1); break; case keypurpose_visualization: break; case keypurpose_playlist: break; case keypurpose_volumeup: { double vl = 0.0f, vr = 0.0f; audio_getvolume(&vl, &vr); vl += 0.05; vr += 0.05; if(vl > 1.0f)vl = 1.0f; if(vr > 1.0f)vr = 1.0f; audio_setvolume(vl, vr); fennec_refresh(fennec_v_refresh_force_not); } break; case keypurpose_volumedown: { double vl = 0.0f, vr = 0.0f; audio_getvolume(&vl, &vr); vl -= 0.05; vr -= 0.05; if(vl < 0.0f)vl = 0.0f; if(vr < 0.0f)vr = 0.0f; audio_setvolume(vl, vr); fennec_refresh(fennec_v_refresh_force_not); } break; case keypurpose_volumeup_auto: Menu_MainProc(menu_vol_autoinc); break; case keypurpose_volumedown_auto: Menu_MainProc(menu_vol_autodec); break; case keypurpose_volumemin: audio_setvolume(0.0f, 0.0f); fennec_refresh(fennec_v_refresh_force_not); break; case keypurpose_volumemax: audio_setvolume(1.0f, 1.0f); fennec_refresh(fennec_v_refresh_force_not); break; case keypurpose_addfile: GlobalFunction(Function_AddFileDialog); break; case keypurpose_fast_load: break; case keypurpose_fast_addfile: break; case keypurpose_preferences: settings_ui_show(); break; case keypurpose_keyboardviewer: break; case keypurpose_currenttagging: basewindows_show_tagging(0, audio_playlist_getsource(audio_playlist_getcurrentindex())); break; case keypurpose_switch_main: SetFocus(window_main); break; case keypurpose_switch_playlist: if(GetFocus() != window_main) { SetFocus(window_main); }else{ HWND plwnd; skins_function_getdata(get_window_playlist, &plwnd, 0); if(plwnd) { SetFocus(plwnd); break; } } break; case keypurpose_playlist_autoswitching: settings.player.auto_switching ^= 1; break; case keypurpose_playlist_shuffle: if(settings.player.playlist_shuffle) audio_playlist_setshuffle(0, 1); else audio_playlist_setshuffle(1, 1); break; case keypurpose_playlist_information: /* [todo] wrong!! */ basewindows_show_tagging(0, audio_playlist_getsource(audio_playlist_getcurrentindex())); break; case keypurpose_playlist_repeatall: settings.player.playlist_repeat_list ^= 1; break; case keypurpose_playlist_repeatsingle: settings.player.playlist_repeat_single ^= 1; break; case keypurpose_playlist_insert: GlobalFunction(Function_AddFileDialog); fennec_refresh(fennec_v_refresh_force_high); break; case keypurpose_playlist_insertdir: { letter fpath[v_sys_maxpath]; BROWSEINFO bi; LPITEMIDLIST lpi; fpath[0] = 0; bi.hwndOwner = window_main; bi.lpszTitle = uni("Add to playlist."); bi.pszDisplayName = fpath; bi.lpfn = 0; bi.iImage = 0; bi.lParam = 0; bi.pidlRoot = 0; bi.ulFlags = BIF_RETURNONLYFSDIRS; lpi = SHBrowseForFolder(&bi); SHGetPathFromIDList(lpi, fpath); if(str_len(fpath)) { AddDirectory(fpath); } fennec_refresh(fennec_v_refresh_force_high); } break; case keypurpose_playlist_remove: break; } return 1; }
/* set variables and buffer to initial state */ static void reset(void) { audio_pause(); av_fifo_reset(ao->buffer); }