redo OSS frag setup. Compute real pollux rate
[libpicofe.git] / gp2x / emu.c
index 625f481..659d3a7 100644 (file)
@@ -17,6 +17,7 @@
 \r
 #include "plat_gp2x.h"\r
 #include "soc.h"\r
+#include "soc_pollux.h"\r
 #include "../common/plat.h"\r
 #include "../common/menu.h"\r
 #include "../common/arm_utils.h"\r
@@ -733,21 +734,22 @@ void pemu_sound_start(void)
        if (currentConfig.EmuOpt & EOPT_EN_SOUND)\r
        {\r
                int is_stereo = (PicoOpt & POPT_EN_STEREO) ? 1 : 0;\r
-               int target_fps = Pico.m.pal ? 50 : 60;\r
-               int frame_samples, snd_excess_add;\r
                int snd_rate_oss = PsndRate;\r
                gp2x_soc_t soc;\r
 \r
+               memset(sndBuffer, 0, sizeof(sndBuffer));\r
+               PsndOut = sndBuffer;\r
+               PicoWriteSound = updateSound;\r
+               plat_update_volume(0, 0);\r
+\r
+               printf("starting audio: %i len: %i stereo: %i, pal: %i\n",\r
+                       PsndRate, PsndLen, is_stereo, Pico.m.pal);\r
+               sndout_oss_start(snd_rate_oss, is_stereo, 1);\r
+               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
+\r
                soc = soc_detect();\r
-               if (soc == SOCID_POLLUX) {\r
-                       /* POLLUX pain: DPLL1 / mclk_div / bitclk_div / 4 */\r
-                       switch (PsndRate) {\r
-                       case 44100: PsndRate = 44171; break; // 44170.673077\r
-                       case 22050: PsndRate = 22086; break; // 22085.336538\r
-                       case 11025: PsndRate = 11043; break; // 11042.668269\r
-                       default: break;\r
-                       }\r
-               }\r
+               if (soc == SOCID_POLLUX)\r
+                       PsndRate = pollux_get_real_snd_rate(PsndRate);\r
 \r
                #define SOUND_RERATE_FLAGS (POPT_EN_FM|POPT_EN_PSG|POPT_EN_STEREO|POPT_EXT_FM|POPT_EN_MCD_CDDA)\r
                if (PsndRate != PsndRate_old || Pico.m.pal != pal_old || ((PicoOpt & POPT_EXT_FM) && crashed_940) ||\r
@@ -755,40 +757,25 @@ void pemu_sound_start(void)
                        PsndRerate(Pico.m.frame_count ? 1 : 0);\r
                }\r
 \r
-               memset(sndBuffer, 0, sizeof(sndBuffer));\r
-               PsndOut = sndBuffer;\r
-               PicoWriteSound = updateSound;\r
                PsndRate_old = PsndRate;\r
                PicoOpt_old  = PicoOpt;\r
                pal_old = Pico.m.pal;\r
-               plat_update_volume(0, 0);\r
-\r
-               frame_samples = PsndLen;\r
-               snd_excess_add = ((PsndRate - PsndLen * target_fps)<<16) / target_fps;\r
-               if (snd_excess_add != 0)\r
-                       frame_samples++;\r
-               if (soc == SOCID_POLLUX)\r
-                       frame_samples *= 2;     /* force larger buffer */\r
-\r
-               printf("starting audio: %i len: %i (ex: %04x) stereo: %i, pal: %i\n",\r
-                       PsndRate, PsndLen, snd_excess_add, is_stereo, Pico.m.pal);\r
-               sndout_oss_setvol(currentConfig.volume, currentConfig.volume);\r
-               sndout_oss_start(snd_rate_oss, frame_samples, is_stereo);\r
-\r
-               /* Wiz's sound hardware needs more prebuffer */\r
-               if (soc == SOCID_POLLUX)\r
-                       updateSound(frame_samples);\r
        }\r
 }\r
 \r
+static const int sound_rates[] = { 44100, 32000, 22050, 16000, 11025, 8000 };\r
+\r
 void pemu_sound_stop(void)\r
 {\r
-       /* get back from Wiz pain */\r
-       switch (PsndRate) {\r
-               case 44171: PsndRate = 44100; break;\r
-               case 22086: PsndRate = 22050; break;\r
-               case 11043: PsndRate = 11025; break;\r
-               default: break;\r
+       int i;\r
+\r
+       /* get back from Pollux pain */\r
+       PsndRate += 1000;\r
+       for (i = 0; i < ARRAY_SIZE(sound_rates); i++) {\r
+               if (PsndRate >= sound_rates[i]) {\r
+                       PsndRate = sound_rates[i];\r
+                       break;\r
+               }\r
        }\r
 }\r
 \r
@@ -801,7 +788,6 @@ void pemu_forced_frame(int no_scale, int do_emu)
 {\r
        int po_old = PicoOpt;\r
 \r
-       doing_bg_frame = 1;\r
        PicoOpt &= ~POPT_ALT_RENDERER;\r
        PicoOpt |= POPT_ACC_SPRITES;\r
        if (!no_scale)\r
@@ -815,13 +801,14 @@ void pemu_forced_frame(int no_scale, int do_emu)
        PicoDrawSetCallbacks(NULL, NULL);\r
        Pico.m.dirtyPal = 1;\r
 \r
+       doing_bg_frame = 1;\r
        if (do_emu)\r
                PicoFrame();\r
        else\r
                PicoFrameDrawOnly();\r
+       doing_bg_frame = 0;\r
 \r
        g_menubg_src_ptr = g_screen_ptr;\r
-       doing_bg_frame = 0;\r
        PicoOpt = po_old;\r
 }\r
 \r