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.


|