int pos, len;\r
   int dout = ym2612.dacout;\r
 \r
+  // nothing to do if sound is off\r
+  if (!PicoIn.sndOut) return;\r
+\r
   // number of samples to fill in buffer (Q20)\r
   len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.dac_pos;\r
 \r
   int pos, len;\r
   int stereo = 0;\r
 \r
+  // nothing to do if sound is off\r
+  if (!PicoIn.sndOut) return;\r
+\r
   // number of samples to fill in buffer (Q20)\r
   len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.psg_pos;\r
 \r
   int stereo = 0;\r
   short *buf;\r
 \r
+  // nothing to do if sound is off\r
+  if (!PicoIn.sndOut) return;\r
+\r
   // number of samples to fill in buffer (Q20)\r
   len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.ym2413_pos;\r
 \r
   int pos, len;\r
   int stereo = 0;\r
 \r
+  // nothing to do if sound is off\r
+  if (!PicoIn.sndOut) return;\r
+\r
   // Q20, number of samples since last call\r
   len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.fm_pos;\r
 \r
 {\r
   int len = Pico.snd.len;\r
   if (Pico.snd.len_e_add) len++;\r
+\r
+  // drop pos remainder to avoid rounding errors (not entirely correct though)\r
+  Pico.snd.dac_pos = Pico.snd.fm_pos = Pico.snd.psg_pos = Pico.snd.ym2413_pos = 0;\r
+  if (!PicoIn.sndOut) return;\r
+\r
   if (PicoIn.opt & POPT_EN_STEREO)\r
     memset32((int *) PicoIn.sndOut, 0, len); // assume PicoIn.sndOut to be aligned\r
   else {\r
   }\r
   if (!(PicoIn.opt & POPT_EN_FM))\r
     memset32(PsndBuffer, 0, PicoIn.opt & POPT_EN_STEREO ? len*2 : len);\r
-  // drop pos remainder to avoid rounding errors (not entirely correct though)\r
-  Pico.snd.dac_pos = Pico.snd.fm_pos = Pico.snd.psg_pos = Pico.snd.ym2413_pos = 0;\r
 }\r
 \r
 \r
 static int PsndRender(int offset, int length)\r
 {\r
-  int *buf32;\r
+  s32 *buf32;\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
   pprof_start(sound);\r
 \r
   if (PicoIn.AHW & PAHW_PICO) {\r
-    PicoPicoPCMUpdate(PicoIn.sndOut+(offset<<stereo), length-offset, stereo);\r
+    // XXX ugly hack, need to render sound for interrupts\r
+    s16 *buf16 = PicoIn.sndOut ? PicoIn.sndOut : (short *)PsndBuffer;\r
+    PicoPicoPCMUpdate(buf16+(offset<<stereo), length-offset, stereo);\r
     return length;\r
   }\r
 \r
   // Fill up DAC output in case of missing samples (Q rounding errors)\r
-  if (length-daclen > 0) {\r
+  if (length-daclen > 0 && PicoIn.sndOut) {\r
     short *dacbuf = PicoIn.sndOut + (daclen << stereo);\r
     Pico.snd.dac_pos += (length-daclen) << 20;\r
     *dacbuf++ += Pico.snd.dac_val2;\r
   }\r
 \r
   // Add in parts of the PSG output not yet done\r
-  if (length-psglen > 0) {\r
+  if (length-psglen > 0 && PicoIn.sndOut) {\r
     short *psgbuf = PicoIn.sndOut + (psglen << stereo);\r
     Pico.snd.psg_pos += (length-psglen) << 20;\r
     if (PicoIn.opt & POPT_EN_PSG)\r
   }\r
 \r
   // Add in parts of the FM buffer not yet done\r
-  if (length-fmlen > 0) {\r
+  if (length-fmlen > 0 && PicoIn.sndOut) {\r
     int *fmbuf = buf32 + ((fmlen-offset) << stereo);\r
     Pico.snd.fm_pos += (length-fmlen) << 20;\r
     if (PicoIn.opt & POPT_EN_FM)\r
     p32x_pwm_update(buf32, length-offset, stereo);\r
 \r
   // convert + limit to normal 16bit output\r
-  PsndMix_32_to_16l(PicoIn.sndOut+(offset<<stereo), buf32, length-offset);\r
+  if (PicoIn.sndOut)\r
+    PsndMix_32_to_16l(PicoIn.sndOut+(offset<<stereo), buf32, length-offset);\r
 \r
   pprof_end(sound);\r
 \r
 \r
   curr_pos  = PsndRender(0, Pico.snd.len_use);\r
 \r
-  if (PicoIn.writeSound)\r
+  if (PicoIn.writeSound && PicoIn.sndOut)\r
     PicoIn.writeSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));\r
   // clear sound buffer\r
   PsndClear();\r
   int psglen = ((Pico.snd.psg_pos+0x80000) >> 20);\r
   int ym2413len = ((Pico.snd.ym2413_pos+0x80000) >> 20);\r
 \r
+  if (!PicoIn.sndOut)\r
+    return length;\r
+\r
   pprof_start(sound);\r
 \r
   // Add in parts of the PSG output not yet done\r
 \r
   curr_pos  = PsndRenderMS(0, Pico.snd.len_use);\r
 \r
-  if (PicoIn.writeSound != NULL)\r
+  if (PicoIn.writeSound != NULL && PicoIn.sndOut)\r
     PicoIn.writeSound(curr_pos * ((PicoIn.opt & POPT_EN_STEREO) ? 4 : 2));\r
   PsndClear();\r
 }\r