if((soundControl & 0x0200) && (soundEnableFlag & 0x100)) res = ((s8)soundBuffer[4][soundIndex]);
if((soundControl & 0x0200) && (soundEnableFlag & 0x100)){ if(!dsaRatio) res = ((s8)soundBuffer[4][soundIndex])>>1; else res = ((s8)soundBuffer[4][soundIndex]); }
void soundMix(){  int res = 0;  int cgbRes = 0;  int ratio = ioMem[0x82] & 3;  int dsaRatio = ioMem[0x82] & 4;  int dsbRatio = ioMem[0x82] & 8;    if(soundBalance & 16) {    cgbRes = ((s8)soundBuffer[0][soundIndex]);  }  if(soundBalance & 32) {    cgbRes += ((s8)soundBuffer[1][soundIndex]);  }  if(soundBalance & 64) {    cgbRes += ((s8)soundBuffer[2][soundIndex]);  }  if(soundBalance & 128) {    cgbRes += ((s8)soundBuffer[3][soundIndex]);  }  if((soundControl & 0x0200) && (soundEnableFlag & 0x100))    res = ((s8)soundBuffer[4][soundIndex]);    if((soundControl & 0x2000) && (soundEnableFlag & 0x200))    res += ((s8)soundBuffer[5][soundIndex]);    res = (res * 170);  cgbRes = (cgbRes * 52 * soundLevel1);  switch(ratio) {  case 0:  case 3: // prohibited, but 25%        cgbRes >>= 2;    break;  case 1:    cgbRes >>= 1;    break;  case 2:    break;  }  if(!dsaRatio)    res >>= 1;    res += cgbRes;  if(soundEcho) {    res *= 2;    res += soundFilter[soundEchoIndex];    res /= 2;    soundFilter[soundEchoIndex++] = res;  }  if(soundLowPass) {    soundLeft[4] = soundLeft[3];    soundLeft[3] = soundLeft[2];    soundLeft[2] = soundLeft[1];    soundLeft[1] = soundLeft[0];    soundLeft[0] = res;    res = (soundLeft[4] + 2*soundLeft[3] + 8*soundLeft[2] + 2*soundLeft[1] +           soundLeft[0])/14;  }  res *= (soundVolume+1);    if(res > 32767)    res = 32767;  if(res < -32768)    res = -32768;  if(soundReverse)    soundFinalWave[++soundBufferIndex] = res;  else    soundFinalWave[soundBufferIndex++] = res;    res = 0;  cgbRes = 0;    if(soundBalance & 1) {    cgbRes = ((s8)soundBuffer[0][soundIndex]);  }  if(soundBalance & 2) {    cgbRes += ((s8)soundBuffer[1][soundIndex]);  }  if(soundBalance & 4) {    cgbRes += ((s8)soundBuffer[2][soundIndex]);  }  if(soundBalance & 8) {    cgbRes += ((s8)soundBuffer[3][soundIndex]);  }  if((soundControl & 0x0100) && (soundEnableFlag & 0x100))    res = ((s8)soundBuffer[4][soundIndex]);    if((soundControl & 0x1000) && (soundEnableFlag & 0x200)) {    res += ((s8)soundBuffer[5][soundIndex]);        }  res = (res * 170);  cgbRes = (cgbRes * 52 * soundLevel1);    switch(ratio) {  case 0:  case 3: // prohibited, but 25%    cgbRes >>= 2;    break;  case 1:    cgbRes >>= 1;    break;  case 2:    break;  }  if(!dsbRatio)    res >>= 1;    res += cgbRes;    if(soundEcho) {    res *= 2;    res += soundFilter[soundEchoIndex];    res /= 2;    soundFilter[soundEchoIndex++] = res;    if(soundEchoIndex >= 4000)      soundEchoIndex = 0;  }  if(soundLowPass) {    soundRight[4] = soundRight[3];    soundRight[3] = soundRight[2];    soundRight[2] = soundRight[1];    soundRight[1] = soundRight[0];    soundRight[0] = res;    res = (soundRight[4] + 2*soundRight[3] + 8*soundRight[2] + 2*soundRight[1] +           soundRight[0])/14;  }  res *= (soundVolume+1);    if(res > 32767)    res = 32767;  if(res < -32768)    res = -32768;    if(soundReverse)    soundFinalWave[-1+soundBufferIndex++] = res;  else    soundFinalWave[soundBufferIndex++] = res;}