« Return to Thread: Buffer size problem

Re: Buffer size problem

by Jimmy Gervais :: Rate this Message:

Reply to Author | View in Thread

You pointed the right place, but the real problem was my understanding of the rand() function. In another langage it generates a floating point value between 0 and 1, which I can multiply by the max value I want. But in C++, in generates an integer between 0 and MAX_RAND, which already is 2^16. Also, my conversion was to ALuint, instead of short. The only thing left was to randomize the sign too, because 16bits audio is signed, which leads to:

 Tampon1[i] = rand() * (short)pow(-1,(rand() % 2) == 1);

Also, I noted that when the buffer is too small, that being under 8192, the Source State is AL_INITIATE, so looking for AL_STOPPED only is no good.

Now everything works fine, so thank you so much for your help!

Jimmy

2009/7/4 Chris Robinson <chris.kcat@...>
On Friday 03 July 2009 11:26:04 pm Jimmy Gervais wrote:
> The call *needs *a ALvoid pointer, it is specified and otherwise returns an
> error, hence to copy.

In C++, any pointer type can implicitly cast to a void*, as long as it doesn't
remove const-ness. Setting PTampon1 to Tampon1 like you do does the same work,
but is harder to follow.

Even if it needs the cast (by not recognizing ALvoid* as void*), then this
would work, too:
alBufferData(MesTampons[0], AL_FORMAT_STEREO16, (ALvoid*)Tampon1, taille,
            44100);

> Now it doesn't crash, not even with 500MB, but I got *no sound at all*!!

Probably the way you're generating the sound:

       AleatD = rand() * pow(2,16);
       Aleat = (ALuint)AleatD;
pow(2,16) = 1<<16 = 0x10000
0xABCD * 0x1000 = 0xABCD0000

       Tampon1[i] = Aleat;
(short)0xABCD0000 = 0x0000

The value given by rand() is effectively shifted up by 16 bits, which leaves
the bottom 16 bits as 0. When cast to a short, it takes the bottom 16 bits,
which will always be 0 (silence).
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal


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

 « Return to Thread: Buffer size problem