Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: C  |  size: 3.02 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. {
  2.         int i, j;
  3.         for (i = 0; i < s3m_numChans; i++)
  4.         {
  5.                 if (ch[i].data != NULL)
  6.                 {
  7.                         for (j = 0; j < numSamples; j++)
  8.                         {
  9.                                 if (ch[i].stereo)
  10.                                 {
  11.                                         float smpL, smpR;
  12.  
  13.                                         if (interpolation)
  14.                                         {
  15.                                                 float smp1_L = (float)ch[i].data[ch[i].index];
  16.                                                 float smp1_R = (float)ch[i].data[ch[i].len + ch[i].index];
  17.                                                 float smp2_L, smp2_R;
  18.  
  19.                                                 if (ch[i].loopLen >= 2)
  20.                                                 {
  21.                                                         if (ch[i].index >= (ch[i].loopEnd - 1))
  22.                                                         {
  23.                                                                 smp2_L = (float)ch[i].data[ch[i].loopEnd - ch[i].loopLen];
  24.                                                                 smp2_R = (float)ch[i].data[ch[i].len + ch[i].loopEnd - ch[i].loopLen];
  25.                                                         }
  26.                                                         else
  27.                                                         {
  28.                                                                 smp2_L = (float)ch[i].data[ch[i].index + 1];
  29.                                                                 smp2_R = (float)ch[i].data[ch[i].len + ch[i].index + 1];
  30.                                                         }
  31.                                                 }
  32.                                                 else
  33.                                                 {
  34.                                                         if (ch[i].index >= (ch[i].len - 1))
  35.                                                         {
  36.                                                                 smp2_L = 0.0f;
  37.                                                                 smp2_R = 0.0f;
  38.                                                         }
  39.                                                         else
  40.                                                         {
  41.                                                                 smp2_L = (float)ch[i].data[ch[i].index + 1];
  42.                                                                 smp2_R = (float)ch[i].data[ch[i].len + ch[i].index + 1];
  43.                                                         }
  44.                                                 }
  45.  
  46.                                                 smpL = (smp1_L + (smp1_L - smp2_L) * ch[i].frac) * ch[i].vol;
  47.                                                 smpR = (smp1_R + (smp1_R - smp2_R) * ch[i].frac) * ch[i].vol;
  48.                                         }
  49.                                         else
  50.                                         {
  51.                                                 smpL = (float)ch[i].data[ch[i].index] * ch[i].vol;
  52.                                                 smpR = (float)ch[i].data[ch[i].len + ch[i].index] * ch[i].vol;
  53.                                         }
  54.  
  55.                                         masterBufferL[j] += (smpL * ch[i].panL);
  56.                                         masterBufferR[j] += (smpR * ch[i].panR);
  57.  
  58.                                         ch[i].frac += ch[i].incRate;
  59.                                         if (ch[i].frac >= 1.0f)
  60.                                         {
  61.                                                 ch[i].index += (int)ch[i].frac;
  62.                                                 ch[i].frac  -= (int)ch[i].frac;
  63.  
  64.                                                 if (ch[i].loopLen >= 2)
  65.                                                 {
  66.                                                         if (ch[i].index >= ch[i].loopEnd)
  67.                                                                 ch[i].index -= ch[i].loopLen;
  68.                                                 }
  69.                                                 else if (ch[i].index >= ch[i].len)
  70.                                                 {
  71.                                                         ch[i].data = NULL;
  72.  
  73.                                                         break;
  74.                                                 }
  75.                                         }
  76.                                 }
  77.                                 else
  78.                                 {
  79.                                         float smp;
  80.  
  81.                                         if (interpolation)
  82.                                         {
  83.                                                 float smp1 = (float)ch[i].data[ch[i].index];
  84.                                                 float smp2;
  85.  
  86.                                                 if (ch[i].loopLen >= 2)
  87.                                                 {
  88.                                                         if (ch[i].index >= (ch[i].loopEnd - 1))
  89.                                                                 smp2 = (float)ch[i].data[ch[i].loopEnd - ch[i].loopLen];
  90.                                                         else
  91.                                                                 smp2 = (float)ch[i].data[ch[i].index + 1];
  92.                                                 }
  93.                                                 else
  94.                                                 {
  95.                                                         if (ch[i].index >= (ch[i].len - 1))
  96.                                                                 smp2 = 0.0f;
  97.                                                         else
  98.                                                                 smp2 = (float)ch[i].data[ch[i].index + 1];
  99.                                                 }
  100.  
  101.                                                 smp = (smp1 + (smp2 - smp1) * ch[i].frac) * ch[i].vol;
  102.                                         }
  103.                                         else
  104.                                         {
  105.                                                 smp = (float)ch[i].data[ch[i].index] * ch[i].vol;
  106.                                         }
  107.  
  108.                                         masterBufferL[j] += (smp * ch[i].panL);
  109.                                         masterBufferR[j] += (smp * ch[i].panR);
  110.  
  111.                                         ch[i].frac += ch[i].incRate;
  112.                                         if (ch[i].frac >= 1.0f)
  113.                                         {
  114.                                                 ch[i].index += (int)ch[i].frac;
  115.                                                 ch[i].frac  -= (int)ch[i].frac;
  116.  
  117.                                                 if (ch[i].loopLen >= 2)
  118.                                                 {
  119.                                                         if (ch[i].index >= ch[i].loopEnd)
  120.                                                                 ch[i].index -= ch[i].loopLen;
  121.                                                 }
  122.                                                 else if (ch[i].index >= ch[i].len)
  123.                                                 {
  124.                                                         ch[i].data = NULL;
  125.  
  126.                                                         break;
  127.                                                 }
  128.                                         }
  129.                                 }
  130.                         }
  131.                 }
  132.         }
  133. }