+ SOFTCLIP(p->sample[0]);
+ SOFTCLIP(p->sample[1]);
+ }
+ }
+ else if (nchannels == 1) // 1.0 mono
+ {
+ for (i = 0; i < nbframes; i++, p++)
+ {
+ SOFTCLIP(p->sample[0]);
+ }
+ }
+#undef SOFTCLIP
+ }
+}
+
+static void S_ConvertPaintBuffer(portable_sampleframe_t *painted_ptr, void *rb_ptr, int nbframes, int width, int nchannels)
+{
+ int i;
+ float val;
+ if (width == 4) // 32bit float
+ {
+ float *snd_out = (float*)rb_ptr;
+ if (nchannels == 8) // 7.1 surround
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ *snd_out++ = painted_ptr->sample[0];
+ *snd_out++ = painted_ptr->sample[1];
+ *snd_out++ = painted_ptr->sample[2];
+ *snd_out++ = painted_ptr->sample[3];
+ *snd_out++ = painted_ptr->sample[4];
+ *snd_out++ = painted_ptr->sample[5];
+ *snd_out++ = painted_ptr->sample[6];
+ *snd_out++ = painted_ptr->sample[7];
+ }
+ }
+ else if (nchannels == 6) // 5.1 surround
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ *snd_out++ = painted_ptr->sample[0];
+ *snd_out++ = painted_ptr->sample[1];
+ *snd_out++ = painted_ptr->sample[2];
+ *snd_out++ = painted_ptr->sample[3];
+ *snd_out++ = painted_ptr->sample[4];
+ *snd_out++ = painted_ptr->sample[5];
+ }
+ }
+ else if (nchannels == 4) // 4.0 surround
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ *snd_out++ = painted_ptr->sample[0];
+ *snd_out++ = painted_ptr->sample[1];
+ *snd_out++ = painted_ptr->sample[2];
+ *snd_out++ = painted_ptr->sample[3];
+ }
+ }
+ else if (nchannels == 2) // 2.0 stereo
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ *snd_out++ = painted_ptr->sample[0];
+ *snd_out++ = painted_ptr->sample[1];
+ }
+ }
+ else if (nchannels == 1) // 1.0 mono
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ *snd_out++ = painted_ptr->sample[0];
+ }
+ }
+
+ // noise is really really annoying
+ if (cls.timedemo)
+ memset(rb_ptr, 0, nbframes * nchannels * width);
+ }
+ else if (width == 2) // 16bit
+ {
+ short *snd_out = (short*)rb_ptr;
+ if (nchannels == 8) // 7.1 surround
+ {
+ for (i = 0;i < nbframes;i++, painted_ptr++)
+ {
+ val = (int)(painted_ptr->sample[0] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[1] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[2] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[3] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[4] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[5] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[6] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[7] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ }
+ }
+ else if (nchannels == 6) // 5.1 surround
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ val = (int)(painted_ptr->sample[0] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[1] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[2] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[3] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[4] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[5] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ }
+ }
+ else if (nchannels == 4) // 4.0 surround
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ val = (int)(painted_ptr->sample[0] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[1] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[2] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[3] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ }
+ }
+ else if (nchannels == 2) // 2.0 stereo
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ val = (int)(painted_ptr->sample[0] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ val = (int)(painted_ptr->sample[1] * 32768.0f);*snd_out++ = bound(-32768, val, 32767);
+ }
+ }
+ else if (nchannels == 1) // 1.0 mono
+ {
+ for (i = 0; i < nbframes; i++, painted_ptr++)
+ {
+ val = (int)((painted_ptr->sample[0] + painted_ptr->sample[1]) * 16384.0f);*snd_out++ = bound(-32768, val, 32767);