Trouble with more than 2 buffers at the same time

View: New views
8 Messages — Rating Filter:   Alert me  

Trouble with more than 2 buffers at the same time

by Zarnick Maelstorm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all, I'm trying to create a program that builds a 16x16 grid, each
one with one buffer created with alutCreateBufferWaveform(), and it goes
OK, but if I then play more than 2 buffers at the same time (ie: 3 or
more) all I get is a white noise, here's the two functions (one to fill
the grid, and the other to add a sound source, each cell is one), please
help me out on this.

Thanks.

bool SoundManager::createSineMatrix(int step, ALfloat freq, ALfloat
duration)
{
  ALenum error;

  m_siBuffers = (ALsizei)step;
  if((m_vBuffers = (ALuint*)malloc(sizeof(ALuint)*m_siBuffers))==NULL)
  {
    perror("malloc");
    return false;
  }
  memset(m_vBuffers,'\0',sizeof(ALuint)*m_siBuffers);
  alGenBuffers(m_siBuffers, m_vBuffers);
  if((error = alGetError()) != AL_NO_ERROR)
  {
    logALError(error);
    return false;
  }
  for(int i = 0; i < step; i++)
  {
    ALfloat f = freq*(i+1);
    f/=2;
    m_vBuffers[i] = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE,f, 0,
duration);
    if(m_vBuffers[i] == AL_NONE)
    {
      logALError(alGetError());
      return false;
    }
  }
  return true;
}

bool SoundManager::addSource(unsigned int id, int step, float *pos, bool
loop)
{
  ALenum error;
  if(step < 0 || step > m_siBuffers) throw "<SoundManager::addSource()>
step invalid";
  if(id < 0 || (ALsizei)id > m_siSources) throw
"<SoundManager::addSource()> id invalid";
  if(m_vSources == NULL)
  {
    if((m_vSources = (ALuint*)malloc(sizeof(ALuint)*m_siSources))==NULL)
    {
      perror("malloc");
      return false;
    }
    memset(m_vSources,'\0',sizeof(ALuint)*m_siSources);
    alGenSources(m_siSources, m_vSources);
  }
  if((error = alGetError()) != AL_NO_ERROR)
  {
    logALError(error);
    return false;
  }
  alSourcei (m_vSources[id], AL_BUFFER,   m_vBuffers[step]);
  alSourcef (m_vSources[id], AL_PITCH,    1.0);
  alSourcef (m_vSources[id], AL_GAIN,     1.0);
  alSource3f(m_vSources[id], AL_VELOCITY, 0, 0, 0);
  if(pos != NULL) alSourcefv(m_vSources[id], AL_POSITION, pos);
  else alSource3f(m_vSources[id], AL_POSITION, 0, 0, 0);
  if(loop == true) alSourcei(m_vSources[id], AL_LOOPING, AL_TRUE);
  else alSourcei(m_vSources[id], AL_LOOPING, AL_FALSE);
  if((error = alGetError()) != AL_NO_ERROR)
  {
    logALError(error);
    return false;
  }
 
  return true;
}

PS: All the sources and buffers are created OK.
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Trouble with more than 2 buffers at the same time

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sunday 28 June 2009 6:48:18 am Mateus Interciso wrote:
> Hi all, I'm trying to create a program that builds a 16x16 grid, each
> one with one buffer created with alutCreateBufferWaveform(), and it goes
> OK, but if I then play more than 2 buffers at the same time (ie: 3 or
> more) all I get is a white noise, here's the two functions (one to fill
> the grid, and the other to add a sound source, each cell is one), please
> help me out on this.

My only real comment here is that you seem to be leaking buffers. You create
an array of them here:

>   memset(m_vBuffers,'\0',sizeof(ALuint)*m_siBuffers);
>   alGenBuffers(m_siBuffers, m_vBuffers);

Then overwrite/leak the handles in the following loop:

>   for(int i = 0; i < step; i++)
>   {
>     ALfloat f = freq*(i+1);
>     f/=2;
>     m_vBuffers[i] = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE,f, 0,
> duration);
>     if(m_vBuffers[i] == AL_NONE)
>     {
>       logALError(alGetError());
>       return false;
>     }
>   }

As for the static.. what OS and lib version are you using? What's your sound
card?
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Trouble with more than 2 buffers at the same time

by Zarnick Maelstorm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, I am overwriting the buffers, that's the ideia right, allocating an array of buffers and creating the wave sine and holding them in this array? This buffer is never written over latter in the program (ie: This function is called only once) Is there any other way for making this?

Also, I'm using Linux, and I've tested this on both M-Audio Audiophile USB interface and a common nForce audio board (the one on board on some mother boards), the results are the same. 
Zarnick
http://www.geekvault.org


On Sun, Jun 28, 2009 at 9:47 PM, Chris Robinson <chris.kcat@...> wrote:
On Sunday 28 June 2009 6:48:18 am Mateus Interciso wrote:
> Hi all, I'm trying to create a program that builds a 16x16 grid, each
> one with one buffer created with alutCreateBufferWaveform(), and it goes
> OK, but if I then play more than 2 buffers at the same time (ie: 3 or
> more) all I get is a white noise, here's the two functions (one to fill
> the grid, and the other to add a sound source, each cell is one), please
> help me out on this.

My only real comment here is that you seem to be leaking buffers. You create
an array of them here:

>   memset(m_vBuffers,'\0',sizeof(ALuint)*m_siBuffers);
>   alGenBuffers(m_siBuffers, m_vBuffers);

Then overwrite/leak the handles in the following loop:

>   for(int i = 0; i < step; i++)
>   {
>     ALfloat f = freq*(i+1);
>     f/=2;
>     m_vBuffers[i] = alutCreateBufferWaveform(ALUT_WAVEFORM_SINE,f, 0,
> duration);
>     if(m_vBuffers[i] == AL_NONE)
>     {
>       logALError(alGetError());
>       return false;
>     }
>   }

As for the static.. what OS and lib version are you using? What's your sound
card?
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Trouble with more than 2 buffers at the same time

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sunday 28 June 2009 6:03:21 pm Zarnick Maelstorm wrote:
> Well, I am overwriting the buffers, that's the ideia right, allocating an
> array of buffers and creating the wave sine and holding them in this array?
> This buffer is never written over latter in the program (ie: This function
> is called only once) Is there any other way for making this?

The problem is basically this.. when you call alGenBuffers, it will fill the
given array with bufferIDs. eg:

m_vBuffers = { 1, 2, 3, ... };

Then the loop will overwrite those values with the bufferIDs created from
alutCreateBufferWaveform, giving you:

m_vBuffers = { 7, 8, 9, ... };

In this case, buffers 1, 2, 3, ... are lost. They were replaced with new
buffers, and there's no handles to the old ones to delete them.

> Also, I'm using Linux, and I've tested this on both M-Audio Audiophile USB
> interface and a common nForce audio board (the one on board on some mother
> boards), the results are the same.

What lib version are you using? 0.0.8, or one of the 1.x releases?
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Trouble with more than 2 buffers at the same time

by Zarnick Maelstorm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

One of the 1.x releases, so I shouldn't call alGenBuffers, and call only alutCreateBufferWaveform?

Thanks.
 
Zarnick
http://www.geekvault.org


On Sun, Jun 28, 2009 at 10:27 PM, Chris Robinson <chris.kcat@...> wrote:
On Sunday 28 June 2009 6:03:21 pm Zarnick Maelstorm wrote:
> Well, I am overwriting the buffers, that's the ideia right, allocating an
> array of buffers and creating the wave sine and holding them in this array?
> This buffer is never written over latter in the program (ie: This function
> is called only once) Is there any other way for making this?

The problem is basically this.. when you call alGenBuffers, it will fill the
given array with bufferIDs. eg:

m_vBuffers = { 1, 2, 3, ... };

Then the loop will overwrite those values with the bufferIDs created from
alutCreateBufferWaveform, giving you:

m_vBuffers = { 7, 8, 9, ... };

In this case, buffers 1, 2, 3, ... are lost. They were replaced with new
buffers, and there's no handles to the old ones to delete them.

> Also, I'm using Linux, and I've tested this on both M-Audio Audiophile USB
> interface and a common nForce audio board (the one on board on some mother
> boards), the results are the same.

What lib version are you using? 0.0.8, or one of the 1.x releases?
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Trouble with more than 2 buffers at the same time

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sunday 28 June 2009 7:53:52 pm Zarnick Maelstorm wrote:
> One of the 1.x releases, so I shouldn't call alGenBuffers, and call
> only alutCreateBufferWaveform?

Right.

Would it be possible to create a small app (with source) that shows the issue?
Nothing from the code you pasted stands out as a problem to me.
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Parent Message unknown Re: Trouble with more than 2 buffers at the same time

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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

Re: Trouble with more than 2 buffers at the same time

by Zarnick Maelstorm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Well, I do have, and they work fine, the buzz you are hearing could be me the White noise I'm hearing, since I'm repeating the same sources over and over (like a loop), this can be "masked" as some sort of smaller white noise. What I'm trying to achieve is something like this http://lab.andre-michelle.com/tonematrix , it's a polyphone matrix, much like the tenory from Yamaha, now, if I'm not mistaken, this is MIDI right? But I should be able to mimic something like this using Wave Sines right?

Any help on this (books or whatever) would be really apreciated.

Thanks
 
Mateus
http://www.geekvault.org


On Mon, Jun 29, 2009 at 10:24 PM, Chris Robinson <chris.kcat@...> wrote:
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


_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal