Sign in to follow this  

OpenAL Buffer queuing

Recommended Posts

-Tobias-    122
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. I'm using ALUT routines to generate sound which works fine - I have a clear sound. Now I have the problem to change the queue content - I hear the sound (2 different buffers), but when I try to remove the last played one, I always get the information that there are no processed buffers. So I can't remove one of my buffers from the queue to remove it. What is the reason for that? Additionally, one question: How can I mix different frequencies at the same time? Do I have to define a source for every frequency and play them simultaneously, or how does it work? The code below plays two buffers in a loop as it should. After 5 seconds I expect it to replace the buffers by one with a different frequency which doesn't work. Output of the code below (sound is playing): Initializing OpenAL...done! Number of loaded buffers: 2 Number of processed buffers: 0 //<- That makes me crazy No errors detected! ALUT error state: No ALUT error found What's the problem here? Thanks a lot and best regards, Tobias mexPrintf("Initializing OpenAL..."); if (!alutInit (NULL, NULL)) { mexPrintf("Failed to initialize OpenAL\n"); return; }else mexPrintf("done!\n"); uiBuffers[0] = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE, 60.0, 0.0, 0.1); uiBuffers[1] = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE, 100.0, 0.0, 0.1); alGenSources( 1, &uiSource ); alSourceQueueBuffers(uiSource,2,uiBuffers); alSourcei(uiSource, AL_LOOPING, AL_TRUE); alSourcePlay( uiSource ); Sleep(1000); alGetSourcei(uiSource, AL_BUFFERS_QUEUED, &processed); mexPrintf("Number of loaded buffers: %i\n",processed); alGetSourcei(uiSource, AL_BUFFERS_PROCESSED, &processed); mexPrintf("Number of processed buffers: %i\n",processed); while(processed--) { ALuint buffer; mexPrintf("Unqueuing buffers..."); alSourceUnqueueBuffers(uiSource, 1, &buffer); mexPrintf("done!\n"); mexPrintf("Generate waveform..."); uiBuffer = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE, 1000.0, 0.0, 0.1); mexPrintf("done!\n"); mexPrintf("Queuing buffers..."); alSourceQueueBuffers(uiSource, 1, &buffer); mexPrintf("done!\n"); } if(alGetError() == AL_NO_ERROR) mexPrintf("No errors detected!\n"); else mexPrintf("Errors detected!\n"); mexPrintf ("ALUT error state: %s\n",alutGetErrorString (alutGetError ()));

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this