summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornotaz2011-09-04 19:41:51 +0300
committernotaz2011-09-04 20:19:07 +0300
commit2455b6a30e7d58cddfa7f196c4553e008996d46a (patch)
treebafc0c6ebdcf574b94c0181b9542f804531f2252
parent0a74ef66e11356f34c80568cca92b6cdc596248c (diff)
downloadpicogpsp-2455b6a30e7d58cddfa7f196c4553e008996d46a.tar.gz
picogpsp-2455b6a30e7d58cddfa7f196c4553e008996d46a.tar.bz2
picogpsp-2455b6a30e7d58cddfa7f196c4553e008996d46a.zip
unify non-psp synchronize(), fix a few sound issues
..like ignoring real buffer size and not stopping sound thread on exit
-rw-r--r--gui.c1
-rw-r--r--main.c88
-rw-r--r--sound.c43
3 files changed, 40 insertions, 92 deletions
diff --git a/gui.c b/gui.c
index 9381d6b..0184a18 100644
--- a/gui.c
+++ b/gui.c
@@ -1756,6 +1756,7 @@ u32 menu(u16 *original_screen)
set_clock_speed();
SDL_PauseAudio(0);
+ num_skipped_frames = 100;
return return_value;
}
diff --git a/main.c b/main.c
index bd66c06..b9606db 100644
--- a/main.c
+++ b/main.c
@@ -758,9 +758,7 @@ void synchronize()
*/
}
-#endif
-
-#ifdef GP2X_BUILD
+#else
u32 real_frame_count = 0;
u32 virtual_frame_count = 0;
@@ -776,14 +774,11 @@ void synchronize()
u64 time_delta;
get_ticks_us(&new_ticks);
- time_delta = new_ticks - last_screen_timestamp;
- last_screen_timestamp = new_ticks;
skip_next_frame = 0;
virtual_frame_count++;
- real_frame_count = ((new_ticks -
- frame_count_initial_timestamp) * 3) / 50000;
+ real_frame_count = (new_ticks * 3) / 50000;
if(real_frame_count >= virtual_frame_count)
{
@@ -800,6 +795,14 @@ void synchronize()
num_skipped_frames = 0;
}
}
+ else if (synchronize_flag)
+ {
+#if defined(PND_BUILD)
+ fb_wait_vsync();
+#elif !defined(GP2X_BUILD) // sleeping on GP2X is a bad idea
+ delay_us((u64)virtual_frame_count * 50000 / 3 - new_ticks + 2);
+#endif
+ }
frames++;
@@ -840,76 +843,11 @@ void synchronize()
interval_skipped_frames += skip_next_frame;
- if(!synchronize_flag)
- print_string("--FF--", 0xFFFF, 0x000, 0, 0);
-}
-
-#endif
-
-
-#ifdef PC_BUILD
-
-u32 ticks_needed_total = 0;
-float us_needed = 0.0;
-u32 frames = 0;
-const u32 frame_interval = 60;
-
-void synchronize()
-{
- u64 new_ticks;
- u64 time_delta;
+#if !defined(GP2X_BUILD) && !defined(PND_BUILD)
char char_buffer[64];
-
- get_ticks_us(&new_ticks);
- time_delta = new_ticks - last_screen_timestamp;
- last_screen_timestamp = new_ticks;
- ticks_needed_total += time_delta;
-
- skip_next_frame = 0;
-
- if((time_delta < frame_speed) && synchronize_flag)
- {
- delay_us(frame_speed - time_delta);
- }
-
- frames++;
-
- if(frames == frame_interval)
- {
- us_needed = (float)ticks_needed_total / frame_interval;
- ticks_needed_total = 0;
- frames = 0;
- }
-
- if(current_frameskip_type == manual_frameskip)
- {
- frameskip_counter = (frameskip_counter + 1) %
- (frameskip_value + 1);
- if(random_skip)
- {
- if(frameskip_counter != (rand() % (frameskip_value + 1)))
- skip_next_frame = 1;
- }
- else
- {
- if(frameskip_counter)
- skip_next_frame = 1;
- }
- }
-
- if(synchronize_flag == 0)
- print_string("--FF--", 0xFFFF, 0x000, 0, 0);
-
- sprintf(char_buffer, "gpSP: %.1fms %.1ffps", us_needed / 1000.0,
- 1000000.0 / us_needed);
+ sprintf(char_buffer, "gpSP: %2d (%2d) fps", fps, frames_drawn);
SDL_WM_SetCaption(char_buffer, "gpSP");
-
-/*
- sprintf(char_buffer, "%02d %02d %06d %07d", frameskip, (u32)ms_needed,
- ram_translation_ptr - ram_translation_cache, rom_translation_ptr -
- rom_translation_cache);
- print_string(char_buffer, 0xFFFF, 0x0000, 0, 0);
-*/
+#endif
}
#endif
diff --git a/sound.c b/sound.c
index 81a0a8d..01d61e2 100644
--- a/sound.c
+++ b/sound.c
@@ -31,10 +31,10 @@ SDL_AudioSpec sound_settings;
SDL_mutex *sound_mutex;
SDL_cond *sound_cv;
-#ifndef PSP_BUILD
-u32 audio_buffer_size_number = 7;
-#else
+#ifdef PSP_BUILD
u32 audio_buffer_size_number = 1;
+#else
+u32 audio_buffer_size_number = 8;
#endif
u32 audio_buffer_size;
@@ -45,6 +45,8 @@ u32 sound_buffer_base = 0;
u32 sound_last_cpu_ticks = 0;
fixed16_16 gbc_sound_tick_step;
+u32 sound_exit_flag;
+
// Queue 1, 2, or 4 samples to the top of the DS FIFO, wrap around circularly
#define sound_timer_queue(size, value) \
@@ -481,13 +483,10 @@ void update_gbc_sound(u32 cpu_ticks)
real_frame_count = 0;
virtual_frame_count = 0;
}
-#endif
-
-/*
-
-#ifdef GP2X_BUILD
+#else
if(current_frameskip_type == auto_frameskip)
{
+/*
u64 current_ticks;
u64 next_ticks;
get_ticks_us(&current_ticks);
@@ -496,12 +495,13 @@ void update_gbc_sound(u32 cpu_ticks)
delay_us(next_ticks - current_ticks);
get_ticks_us(&frame_count_initial_timestamp);
- real_frame_count = 0;
- virtual_frame_count = 0;
+*/
+ /* prevent frameskip, or it will cause more audio,
+ * then more waiting here, then frame skip again, ... */
+ num_skipped_frames = 100;
}
#endif
-*/
}
}
if(sound_on == 1)
@@ -624,7 +624,7 @@ void sound_callback(void *userdata, Uint8 *stream, int length)
SDL_LockMutex(sound_mutex);
while(((gbc_sound_buffer_index - sound_buffer_base) % BUFFER_SIZE) <
- length)
+ length && !sound_exit_flag)
{
SDL_CondWait(sound_cv, sound_mutex);
}
@@ -744,18 +744,18 @@ void sound_exit()
gbc_sound_buffer_index =
(sound_buffer_base + audio_buffer_size) % BUFFER_SIZE;
SDL_PauseAudio(1);
+ sound_exit_flag = 1;
SDL_CondSignal(sound_cv);
+ SDL_CloseAudio();
}
void init_sound()
{
#ifdef PSP_BUILD
audio_buffer_size = (audio_buffer_size_number * 1024) + 3072;
-#elif defined(TAVI_BUILD) || defined(ARM_ARCH)
+#else
audio_buffer_size = 16 << audio_buffer_size_number;
// audio_buffer_size = 16384;
-#else
- audio_buffer_size = 16384;
#endif
SDL_AudioSpec desired_spec =
@@ -779,10 +779,19 @@ void init_sound()
reset_sound();
- SDL_OpenAudio(&desired_spec, &sound_settings);
- sound_frequency = sound_settings.freq;
sound_mutex = SDL_CreateMutex();
sound_cv = SDL_CreateCond();
+
+ SDL_OpenAudio(&desired_spec, &sound_settings);
+ sound_frequency = sound_settings.freq;
+ audio_buffer_size = sound_settings.size;
+ u32 i = audio_buffer_size / 16;
+ for (audio_buffer_size_number = 0; i && (i & 1) == 0; i >>= 1)
+ audio_buffer_size_number++;
+#ifndef PSP_BUILD
+ printf("audio: freq %d, size %d\n", sound_frequency, audio_buffer_size);
+#endif
+
SDL_PauseAudio(0);
}