|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
Waveform and queued buffersHi,
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!"); |
|
|
Re: Waveform and queued buffersHi,
meanwhile, I switched to the ALUT routines to generate sound which works fine. No I still 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... 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"); } Output: Initializing OpenAL...done! Number of loaded buffers: 2 Number of processed buffers: 0 What's the problem here? Thanks a lot and best regards, Tobias |
|
|
Re: Waveform and queued buffersHi Tobias, The problem is that you have enabled Looping on the Source. A looped Source will never set queued buffers as processed because they are effectively always pending in this scenario. So, take this line ... alSourcei(uiSource, AL_LOOPING, AL_TRUE); out and the buffers will be marked as processed enabling you to unqueue them. Dan Creative Labs (UK) Ltd. Notice The information in this message is confidential and may be legally privileged. It is intended solely for the addressee. Access to this message by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying or distribution of the message, or any action taken by you in reliance on it, is prohibited and may be unlawful. If you have received this message in error, please delete it and contact the sender immediately. Thank you. -Tobias- <superplus@... t> To Sent by: openal-devel@... openal-devel-boun m ces@... cc eative.com Subject Re: [Openal-devel] Waveform and 10/24/2008 07:09 queued buffers AM Hi, meanwhile, I switched to the ALUT routines to generate sound which works fine. No I still 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... 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"); } Output: Initializing OpenAL...done! Number of loaded buffers: 2 Number of processed buffers: 0 What's the problem here? Thanks a lot and best regards, Tobias -- View this message in context: http://www.nabble.com/Waveform-and-queued-buffers-tp20127480p20133611.html Sent from the OpenAL - Dev mailing list archive at Nabble.com. _______________________________________________ Openal-devel mailing list Openal-devel@... http://opensource.creative.com/mailman/listinfo/openal-devel ForwardSourceID:NT000663CA _______________________________________________ Openal-devel mailing list Openal-devel@... http://opensource.creative.com/mailman/listinfo/openal-devel |
| Free embeddable forum powered by Nabble | Forum Help |