ntnll
ntnll

Reputation: 11

Openal buffer play only if filled with for cycle

I'm getting crazy trying to solve this strange behavior. I successful created a OpenAL buffer to queue waves and so play it:

static ALuint           snd_buffer  =0;

#define NUM_BUFFERS 10
static ALuint source, buffers[NUM_BUFFERS];

static float            pitch       = 1.0f;
static ALCdevice *      my_dev      = NULL;
static ALCcontext *     my_ctx      = NULL;

...

alGenBuffers(NUM_BUFFERS,buffers);
for (i = 0; i < NUM_BUFFERS; i++) {//EXPERIMENTAL (chaned i=0 to i=1)
    buffers[i]=load_wave(wavFile);
}

Once filled the buffer, I can successful play, all is ok and I can hear the queue that loop the wave 10 times:

alSourcePlay(source);

So far all is working fine, this obviously is only a test function, so I tried to replace for cycle and fill buffer "manually":

buffers[0]=load_wave(wavFile);

or

buffers[1]=load_wave(wavFile);
buffers[2]=load_wave(wavFile);
buffers[3]=load_wave(wavFile);
buffers[4]=load_wave(wavFile);

...

If I fill the buffer with for cycle all is working well, but if I try to feel buffer with buffers[whatever]=load_wave(wavFile) symply doesn't work, I can't hear nothing.

Upvotes: 0

Views: 158

Answers (1)

ntnll
ntnll

Reputation: 11

Solved myself, I'm posting solution for other people. The problem was in

alSourceQueueBuffers(source, NUM_BUFFERS, buffers);

the correcty way is pass the real user buffer usage instead all NUM_BUFFERS to alSourceQueueBuffers function

Upvotes: 1

Related Questions