On Monday 29 June 2009 7:37:54 am you wrote:
> Ok, so it's a little big, but you can see the error (on the audio output),
> then again, this maybe the normal behaviour when you put together 3 or more
> wave sines to play at the same time.
Hmm, it seems to work for me. I start getting a buzz after starting 2 or 3
sources, but it doesn't seem to turn into white noise. Tried with both 44.1khz
and 48khz output. Do you have an OpenAL Soft config set somewhere?
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <errno.h>
> #include <AL/al.h>
> #include <AL/alc.h>
> #include <AL/alut.h>
>
> #define KMAX_BUFFERS 16
> #define KMAX_SOURCES 255
> #define KFREQ 440
> #define KPHASE 90
> #define KDURATION 10
>
>
> ALuint m_buffers[KMAX_BUFFERS];
> ALuint m_sources[KMAX_SOURCES];
>
> void printALError(ALenum error)
> {
> switch(error)
> {
> /* ALut errors */
> case ALUT_ERROR_INVALID_VALUE: fprintf(stderr,"[ERROR] (ALUT)
> Invalid error");break;
> case ALUT_ERROR_INVALID_OPERATION: fprintf(stderr,"[ERROR] (ALUT)
> Invalid operation");break;
> case ALUT_ERROR_OPEN_DEVICE: fprintf(stderr,"[ERROR] (ALUT)
> Open device");break;
> case ALUT_ERROR_CREATE_CONTEXT: fprintf(stderr,"[ERROR] (ALUT)
> Create context");break;
> case ALUT_ERROR_MAKE_CONTEXT_CURRENT: fprintf(stderr,"[ERROR] (ALUT)
> Couldn't create context");break;
> case ALUT_ERROR_NO_CURRENT_CONTEXT: fprintf(stderr,"[ERROR] (ALUT) No
> current context");break;
> case ALUT_ERROR_AL_ERROR_ON_ENTRY: fprintf(stderr,"[ERROR] (ALUT) AL
> error on entry");break;
> case ALUT_ERROR_ALC_ERROR_ON_ENTRY: fprintf(stderr,"[ERROR] (ALUT)
> ALC error on entry");break;
> case ALUT_ERROR_CLOSE_DEVICE: fprintf(stderr,"[ERROR] (ALUT)
> Close device");break;
> case ALUT_ERROR_DESTROY_CONTEXT: fprintf(stderr,"[ERROR] (ALUT)
> Destroy context");break;
> case ALUT_ERROR_OUT_OF_MEMORY: fprintf(stderr,"[ERROR] (ALUT)
> Out of memory");break;
> case ALUT_ERROR_INVALID_ENUM: fprintf(stderr,"[ERROR] (ALUT)
> Invalid enumaration");break;
> case ALUT_ERROR_GEN_BUFFERS: fprintf(stderr,"[ERROR] (ALUT)
> Generating buffers");break;
> case ALUT_ERROR_BUFFER_DATA: fprintf(stderr,"[ERROR] (ALUT)
> Error passing buffer data");break;
> /* OpenAL Errors */
> case AL_INVALID_VALUE: fprintf(stderr,"[ERROR] (OpenAL) Invalid
> value");break;
> case AL_INVALID_ENUM: fprintf(stderr,"[ERROR] (OpenAL) Invalid
> enumeration");break;
> case AL_INVALID_OPERATION: fprintf(stderr,"[ERROR] (OpenAL) Invalid
> operation");break;
>
> default: fprintf(stderr,"[ERROR] Unknown error");break;
> }
> fprintf(stderr,"\n");
> }
>
> ALboolean loadALData(void)
> {
> ALenum error;
> ALfloat freq = 0.0;
> unsigned int i,j;
> i=j=0;
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Creating buffers\n");
> #endif
>
> for(i = 0; i < KMAX_BUFFERS; i++)
> {
> freq = KFREQ*(i+1);
> freq /= 2;
> m_buffers[i] =
> alutCreateBufferWaveform(ALUT_WAVEFORM_SINE,freq,KPHASE, KDURATION);
> if(m_buffers[i] == AL_NONE)
> {
> printALError(alGetError());
> return AL_FALSE;
> }
> }
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Creating sources\n");
> #endif
> //Creating sources
> alGenSources((ALsizei)KMAX_SOURCES,m_sources);
> if((error = alGetError()) != AL_NO_ERROR)
> {
> printALError(error);
> return AL_FALSE;
> }
> for(i = 0; i < KMAX_SOURCES; i++)
> {
> alSourcei (m_sources[i], AL_BUFFER, m_buffers[j++]);
> alSourcef (m_sources[i], AL_PITCH, 1.0);
> alSourcef (m_sources[i], AL_GAIN, 1.0);
> alSourcei (m_sources[i], AL_LOOPING, AL_TRUE);
> alSource3f(m_sources[i], AL_POSITION, 0, 0, 0);
> alSource3f(m_sources[i], AL_VELOCITY, 0, 0, 0);
> alSource3f(m_sources[i], AL_DIRECTION, 0, 0, 0);
> if(j >= KMAX_BUFFERS) j = 0;
> }
> return AL_TRUE;
> }
>
> ALboolean setListener(void)
> {
> ALenum error;
> ALfloat m_fListenerPos[] = {0.0, 0.0, 0.0}; //Position of the listener
> ALfloat m_fListenerVel[] = {0.0, 0.0, 0.0}; //Velocity of the listener
> ALfloat m_fListenerOri[] = {0.0, 0.0, -1.0, 0.0, 1.0, 0.0}; //Orientation
> of the listener, first 3 elements are "at", second 3 are "up"
> alListenerfv(AL_POSITION, m_fListenerPos);
> alListenerfv(AL_VELOCITY, m_fListenerVel);
> alListenerfv(AL_ORIENTATION, m_fListenerOri);
> if((error = alGetError()) != AL_NO_ERROR)
> {
> printALError(error);
> return AL_FALSE;
> }
> return AL_TRUE;
> }
>
> void killAllData(void)
> {
> alDeleteBuffers(KMAX_BUFFERS,m_buffers);
> alDeleteSources(KMAX_SOURCES,m_sources);
> alutExit();
> }
>
> int main()
> {
> ALenum error;
> char ch = '\0';
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Starting OpenAL via ALUT\n");
> #endif
> if(alutInit(NULL,0)!=AL_TRUE)
> {
> printALError(alGetError());
> return 1;
> }
> alGetError(); /* Clearing error bit */
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Setting listener values\n");
> #endif
>
> if(setListener() == AL_FALSE)
> {
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Killing all data\n");
> #endif
> killAllData();
> return 1;
> }
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Setting buffers and sources\n");
> #endif
> if(loadALData()==AL_FALSE)
> {
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Killing all data\n");
> #endif
> killAllData();
> return 1;
> }
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Playing sounds\n");
> #endif
>
> while(ch!='q')
> {
> fprintf(stdout,"Command> ");
> fscanf(stdin,"%c",&ch);
> switch(ch)
> {
> case '1':
> {
> alSourcePlay(m_sources[1]);
> if((error = alGetError()) != AL_NO_ERROR)
> printALError(error);
> break;
> }
> case '2':
> {
> alSourcePlay(m_sources[2]);
> if((error = alGetError()) != AL_NO_ERROR)
> printALError(error);
> break;
> }
> case '3':
> {
> alSourcePlay(m_sources[3]);
> if((error = alGetError()) != AL_NO_ERROR)
> printALError(error);
> break;
> }
> case '4':
> {
> alSourcePlay(m_sources[4]);
> if((error = alGetError()) != AL_NO_ERROR)
> printALError(error);
> break;
> }
> case 's':
> {
> alSourceStopv(KMAX_SOURCES,m_sources);
> if((error = alGetError()) != AL_NO_ERROR)
> printALError(error);
> break;
> }
> case 'q':
> {
> fprintf(stdout,"Shutting down\n");break;
> }
> default: fprintf(stdout,"Unknown command\n");break;
> }
> }
>
> #ifdef DEBUG
> fprintf(stderr,"[DEBUG] Killing all data\n");
> #endif
> killAllData();
>
> return 0;
> }
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal