[Openal] Buffer size problem

Chris Robinson chris.kcat at gmail.com
Sat Jul 4 00:03:16 PDT 2009


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).


More information about the Openal mailing list