[Openal] Queuing/Unqueuing waveforms

Bruckmann, Tobias bruckmann at mechatronik.uni-duisburg.de
Thu Oct 23 23:22:46 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. 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 ()));




More information about the Openal mailing list