[Openal-devel] Waveform and queued buffers
-Tobias-
superplus at gmx.net
Mon Oct 27 00:11:42 PDT 2008
Hi,
I have to implement a waveform synthesizer. Finally, it should mix sine
waves with different frequencies, and during runtime, these frequencies
change. So I have to use queing, I think. The code below produces a nice,
clear sound (sine wave) using a single buffer (see commented part). Using
multiple buffers and the Queue/Unqueue mechanism as shown, the same simple
sine wave sounds rippled/scratchy.
What is the reason for that?
Thanks a lot for your appreciated help,
Tobias
ALuint uiBuffer;
ALuint uiBuffers[2];
ALuint uiSource;
ALint iState;
char data[BUFFERSIZE];
char data2[BUFFERSIZE];
// Initialize Framework
ALFWInit();
mexPrintf("PlayStatic Test Application\n");
if (!ALFWInitOpenAL())
{
mexPrintf("Failed to initialize OpenAL\n");
ALFWShutdown();
return;
}
// Generate an AL Buffer
//alGenBuffers( 1, &uiBuffer );
alGenBuffers( 2, uiBuffers );
alSourcei(uiSource, AL_LOOPING, AL_TRUE);
double pi=3.141592654;
//for (int z = 0; z< BUFFERSIZE; z++) data[z] =
100*sin((double)z*(2*pi)/1000.0);//+128;//+100*sin(z*(2*pi)/400.0);
double freq = 80;
for (int z = 0; z< BUFFERSIZE; z++) data[z] =
100*sin(z*2*pi*freq/SAMPLEFREQ)+128;
for (int z = 0; z< BUFFERSIZE; z++) data2[z] =
100*sin((BUFFERSIZE+z)*2*pi*freq/SAMPLEFREQ)+128;
int i=1;
//alBufferData(uiBuffer, AL_FORMAT_MONO8, data, sizeof(data), SAMPLEFREQ);
alBufferData(uiBuffers[0], AL_FORMAT_MONO8, data, sizeof(data), 11024);
alBufferData(uiBuffers[1], AL_FORMAT_MONO8, data2, sizeof(data2),
11024);
// Generate a Source to playback the Buffer
alGenSources( 1, &uiSource );
// Attach Source to Buffer
//alSourcei( uiSource, AL_BUFFER, uiBuffer );
alSourceQueueBuffers(uiSource,2,uiBuffers);
// Play Source
//playIt(uiSource);
mexPrintf("Playing Source ");
alSourcePlay( uiSource );
alGetSourcei( uiSource, AL_SOURCE_STATE, &iState);
if (iState == AL_PLAYING)
mexPrintf("confirmed!");
if ((alGetError()) == AL_NO_ERROR)
mexPrintf("No Errors!");
--
View this message in context: http://www.nabble.com/Waveform-and-queued-buffers-tp20127480p20127480.html
Sent from the OpenAL - Dev mailing list archive at Nabble.com.
More information about the Openal-devel
mailing list