« Return to Thread: Trouble with more than 2 buffers at the same time

Trouble with more than 2 buffers at the same time

by Zarnick Maelstorm :: Rate this Message:

Reply to Author | View in Thread

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

 « Return to Thread: Trouble with more than 2 buffers at the same time