diff src/adplug/core/emuopl.cxx @ 955:4709ce4e209e trunk

[svn] Run indent -ts4 -nut -bli0 -cdw on this messy lot. Upstream is not consistent with whitespace anyway, no loss there.
author chainsaw
date Sat, 14 Apr 2007 15:23:50 -0700
parents 3da1b8942b8b
children
line wrap: on
line diff
--- a/src/adplug/core/emuopl.cxx	Sat Apr 14 08:48:41 2007 -0700
+++ b/src/adplug/core/emuopl.cxx	Sat Apr 14 15:23:50 2007 -0700
@@ -21,39 +21,47 @@
 
 #include "emuopl.h"
 
-CEmuopl::CEmuopl(int rate, bool bit16, bool usestereo)
-  : use16bit(bit16), stereo(usestereo), mixbufSamples(0)
+CEmuopl::CEmuopl (int rate, bool bit16, bool usestereo):use16bit (bit16), stereo (usestereo),
+mixbufSamples (0)
 {
-  opl[0] = OPLCreate(OPL_TYPE_YM3812, 3579545, rate);
-  opl[1] = OPLCreate(OPL_TYPE_YM3812, 3579545, rate);
+  opl[0] = OPLCreate (OPL_TYPE_YM3812, 3579545, rate);
+  opl[1] = OPLCreate (OPL_TYPE_YM3812, 3579545, rate);
 
   currType = TYPE_DUAL_OPL2;
 
-  init();
+  init ();
 }
 
-CEmuopl::~CEmuopl()
+CEmuopl::~CEmuopl ()
 {
-  OPLDestroy(opl[0]); OPLDestroy(opl[1]);
+  OPLDestroy (opl[0]);
+  OPLDestroy (opl[1]);
 
-  if(mixbufSamples) {
-    delete [] mixbuf0;
-    delete [] mixbuf1;
+  if (mixbufSamples)
+  {
+    delete[]mixbuf0;
+    delete[]mixbuf1;
   }
 }
 
-void CEmuopl::update(short *buf, int samples)
+void
+CEmuopl::update (short *buf, int samples)
 {
   int i;
 
   //ensure that our mix buffers are adequately sized
-  if(mixbufSamples < samples) {
-    if(mixbufSamples) { delete[] mixbuf0; delete[] mixbuf1; }
+  if (mixbufSamples < samples)
+  {
+    if (mixbufSamples)
+    {
+      delete[]mixbuf0;
+      delete[]mixbuf1;
+    }
     mixbufSamples = samples;
 
     //*2 = make room for stereo, if we need it
-    mixbuf0 = new short[samples*2]; 
-    mixbuf1 = new short[samples*2];
+    mixbuf0 = new short[samples * 2];
+    mixbuf1 = new short[samples * 2];
   }
 
   //data should be rendered to outbuf
@@ -65,83 +73,94 @@
   //and so it must point to a mixbuf instead--
   //it will be reduced to 8bit and put in "buf" later
   short *outbuf;
-  short *tempbuf=mixbuf0;
-  short *tempbuf2=mixbuf1;
-  if(use16bit) outbuf = buf;
-  else outbuf = mixbuf1;
+  short *tempbuf = mixbuf0;
+  short *tempbuf2 = mixbuf1;
+  if (use16bit)
+    outbuf = buf;
+  else
+    outbuf = mixbuf1;
   //...there is a potentially confusing situation where mixbuf1 can be aliased.
   //beware. it is a little loony.
 
   //all of the following rendering code produces 16bit output
 
-  switch(currType) {
+  switch (currType)
+  {
   case TYPE_OPL2:
     //for opl2 mode:
     //render chip0 to the output buffer
-    YM3812UpdateOne(opl[0],outbuf,samples);
+    YM3812UpdateOne (opl[0], outbuf, samples);
 
     //if we are supposed to output stereo,
     //then we need to dup the mono channel
-    if(stereo)
-      for(i=samples-1;i>=0;i--) {
-	outbuf[i*2] = outbuf[i];
-	outbuf[i*2+1] = outbuf[i];
+    if (stereo)
+      for (i = samples - 1; i >= 0; i--)
+      {
+        outbuf[i * 2] = outbuf[i];
+        outbuf[i * 2 + 1] = outbuf[i];
       }
     break;
 
-  case TYPE_OPL3:	// unsupported
+  case TYPE_OPL3:              // unsupported
     break;
 
   case TYPE_DUAL_OPL2:
     //for dual opl2 mode:
     //render each chip to a different tempbuffer
-    YM3812UpdateOne(opl[0],tempbuf2,samples);
-    YM3812UpdateOne(opl[1],tempbuf,samples);
+    YM3812UpdateOne (opl[0], tempbuf2, samples);
+    YM3812UpdateOne (opl[1], tempbuf, samples);
 
     //output stereo:
     //then we need to interleave the two buffers
-    if(stereo){
+    if (stereo)
+    {
       //first, spread tempbuf's samples across left channel
       //left channel
-      for(i=0;i<samples;i++)
-	outbuf[i*2] = tempbuf2[i];
+      for (i = 0; i < samples; i++)
+        outbuf[i * 2] = tempbuf2[i];
       //next, insert the samples from tempbuf2 into right channel
-      for(i=0;i<samples;i++)
-	outbuf[i*2+1] = tempbuf[i];
-    } else
+      for (i = 0; i < samples; i++)
+        outbuf[i * 2 + 1] = tempbuf[i];
+    }
+    else
       //output mono:
       //then we need to mix the two buffers into buf
-      for(i=0;i<samples;i++)
-	outbuf[i] = (tempbuf[i]>>1) + (tempbuf2[i]>>1);
+      for (i = 0; i < samples; i++)
+        outbuf[i] = (tempbuf[i] >> 1) + (tempbuf2[i] >> 1);
     break;
   }
 
   //now reduce to 8bit if we need to
-  if(!use16bit)
-    for(i=0;i<(stereo ? samples*2 : samples);i++)
-      ((char *)buf)[i] = (outbuf[i] >> 8) ^ 0x80;
+  if (!use16bit)
+    for (i = 0; i < (stereo ? samples * 2 : samples); i++)
+      ((char *) buf)[i] = (outbuf[i] >> 8) ^ 0x80;
 }
 
-void CEmuopl::write(int reg, int val)
+void
+CEmuopl::write (int reg, int val)
 {
-  switch(currType){
+  switch (currType)
+  {
   case TYPE_OPL2:
   case TYPE_DUAL_OPL2:
-    OPLWrite(opl[currChip], 0, reg);
-    OPLWrite(opl[currChip], 1, val);
+    OPLWrite (opl[currChip], 0, reg);
+    OPLWrite (opl[currChip], 1, val);
     break;
-  case TYPE_OPL3:	// unsupported
+  case TYPE_OPL3:              // unsupported
     break;
   }
 }
 
-void CEmuopl::init()
+void
+CEmuopl::init ()
 {
-  OPLResetChip(opl[0]); OPLResetChip(opl[1]);
+  OPLResetChip (opl[0]);
+  OPLResetChip (opl[1]);
   currChip = 0;
 }
 
-void CEmuopl::settype(ChipType type)
+void
+CEmuopl::settype (ChipType type)
 {
   currType = type;
 }