Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Generating soun...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 4223 of 4370
Post > Topic >>

Generating sound in C

by "Marc Kroeks" <info@[EMAIL PROTECTED] > Jul 29, 2008 at 06:40 PM

Hello,

I would like to ask some advice on optimizing this function, that I want
to 
use to generate sound with waveOutOpen. I will just bluntly post it and
hope 
that some bright expert ****nes her/his light on it:

VOID FillBuffer (PBYTE pBuffer)
{
     static double fAngle[MAX_CH] ;   // Phasenwinkel
     static LONG          i, j ;
  static double dTmpL, dTmpR ;
     short iValueL, iValueR ;

  // Generate the sound data
  for (i = 0 ; i < OUT_BUFFER_SIZE / 4 ; i++)
     {
        dTmp=0 ;

        for (j = 0 ; j < siNChannels ; j++)
        {
            dTmp += dblVol[j] * sin (fAngle[j] + dblPhase[j]) ;
            fAngle[j] +=  dblFreq[j] ;
            if (fAngle[j] > PIx2) fAngle[j] -= PIx2 ;
        }

     // Average the siNChannels sines, apply master volume and panning
     dTmp = dblVolume * dTmp / siNChannels ;


     if (dblPan[j]<0) // -1 is left channel, 1 right channel
        {
            dTmpL= dTmp ;
         dTmpR = dTmp * (1.0 + dblPan[j]) ;
        } else {
            dTmpL= dTmp * (1.0 - dblPan[j]) ;
         dTmpR = dTmp ;
        }

        iValueL = (short) (32767 * dTmpL) ;
        iValueR = (short) (32767 * dTmpR) ;

        pBuffer [i * 4] = (BYTE) (iValueL & 0x00ff) ;
        pBuffer [i * 4 + 1] = (BYTE) ((iValueL& 0xff00) / 0x100);
        pBuffer [i * 4 + 2] = (BYTE) (iValueR & 0x00ff) ;
        pBuffer [i * 4 + 3] = (BYTE) ((iValueR & 0xff00) / 0x100);
     }
}

Thank you very much!

Marc.
 




 3 Posts in Topic:
Generating sound in C
"Marc Kroeks" &  2008-07-29 18:40:18 
Re: Generating sound in C
Barry Schwarz <schwarz  2008-07-29 17:05:08 
Re: Generating sound in C
"Marc Kroeks" &  2008-08-01 09:25:45 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Nov 21 9:15:29 CST 2008.