/* If we exit the loop in the middle, Output[i] has to be inverted */\r
/* and vol[i] incremented only if the exit status of the square */\r
/* wave is 1. */\r
+ left = 0;\r
while (R->Count[i] <= 0)\r
{\r
- R->Count[i] += R->Period[i];\r
+ if (R->Count[i] + R->Period[i]*4 < R->Period[i])\r
+ left+= 4, R->Count[i] += R->Period[i]*4;\r
+ else left++, R->Count[i] += R->Period[i];\r
if (R->Count[i] > 0)\r
{\r
R->Output[i] ^= 1;\r
vol[i] += R->Period[i];\r
}\r
if (R->Output[i]) vol[i] -= R->Count[i];\r
+ /* Cut of anything above the sample freqency. It will only create */\r
+ /* aliasing and hearable distortions anyway. */\r
+ if (left > 1) vol[i] = STEP/2;\r
}\r
\r
left = STEP;\r
int stereo = (PicoIn.opt & 8) >> 3;\r
int fmlen = ((Pico.snd.fm_pos+0x80000) >> 20);\r
int daclen = ((Pico.snd.dac_pos+0x80000) >> 20);\r
+ int psglen = ((Pico.snd.psg_pos+0x8000) >> 16);\r
\r
buf32 = PsndBuffer+(offset<<stereo);\r
\r
Pico.snd.dac_val2 = Pico.snd.dac_val;\r
}\r
\r
+ // Add in parts of the PSG output not yet done\r
+ if (length-psglen > 0) {\r
+ short *psgbuf = PicoIn.sndOut + (psglen << stereo);\r
+ Pico.snd.psg_pos += (length-psglen) << 16;\r
+ if (PicoIn.opt & POPT_EN_PSG)\r
+ SN76496Update(psgbuf, length-psglen, stereo);\r
+ }\r
+\r
// Add in parts of the FM buffer not yet done\r
if (length-fmlen > 0) {\r
int *fmbuf = buf32 + ((fmlen-offset) << stereo);\r
{\r
static int curr_pos = 0;\r
\r
- PsndDoPSG(y - 1);\r
-\r
curr_pos = PsndRender(0, Pico.snd.len_use);\r
\r
if (PicoIn.writeSound)\r
PsndClear();\r
}\r
\r
-PICO_INTERNAL void PsndGetSamplesMS(int y)\r
+static int PsndRenderMS(int offset, int length)\r
{\r
- int length = Pico.snd.len_use;\r
+ int stereo = (PicoIn.opt & 8) >> 3;\r
+ int psglen = ((Pico.snd.psg_pos+0x8000) >> 16);\r
\r
- PsndDoPSG(y - 1);\r
+ pprof_start(sound);\r
+\r
+ // Add in parts of the PSG output not yet done\r
+ if (length-psglen > 0) {\r
+ short *psgbuf = PicoIn.sndOut + (psglen << stereo);\r
+ Pico.snd.psg_pos += (length-psglen) << 16;\r
+ if (PicoIn.opt & POPT_EN_PSG)\r
+ SN76496Update(psgbuf, length-psglen, stereo);\r
+ }\r
\r
// upmix to "stereo" if needed\r
if (PicoIn.opt & POPT_EN_STEREO) {\r
*p |= *p << 16;\r
}\r
\r
+ pprof_end(sound);\r
+\r
+ return length;\r
+}\r
+\r
+PICO_INTERNAL void PsndGetSamplesMS(int y)\r
+{\r
+ static int curr_pos = 0;\r
+\r
+ curr_pos = PsndRenderMS(0, Pico.snd.len_use);\r
+\r
if (PicoIn.writeSound != NULL)\r
- PicoIn.writeSound(length * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));\r
+ PicoIn.writeSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));\r
PsndClear();\r
}\r
\r