LWJGL
May 19, 2013, 00:21:37 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: alBufferData() and the meanings of AL_FORMAT_STEREO16 AL_FORMAT_STEREO8 etc  (Read 1910 times)
ouattwtym
Newbie
*
Posts: 20


« on: July 07, 2011, 11:28:40 »

For the alBufferData function I've found through experimentation that you can generate "data" based on "format" if you stick to these rules:

  • 16 bit buffers are little-endian and signed and 0 is the silent position
  • 8 bit buffers are unsigned and 128 is the silent position
  • for stereo formats the left channel comes first

Q1: Is this documented anywhere?
( not in http://connect.creativelabs.com/openal/Documentation/oalspecs-annote.pdf or in http://lwjgl.org/javadoc/org/lwjgl/openal/AL10.html  )

Q2: Can I depend on these facts remaining true?
e.g. if the  little-endian-ness depended on my CPU the answer would be "no".

Logged
Matthias
Talks Too Much
***
Posts: 180


WWW
« Reply #1 on: July 07, 2011, 12:27:03 »

Byte order depends on the CPU - use ByteOrder.nativeOrder().
And yes - 8 bit data is unsigned with a 128 offset, and 16 bit data is signed.
Stereo is left followed by right - for multi channel audio (more then 2) you need to look it up Smiley
Logged

ouattwtym
Newbie
*
Posts: 20


« Reply #2 on: July 07, 2011, 13:44:24 »

Thanks! That's great.

In fact, looking at the source code for lwjgl-source-2.7.1/src/java/org/lwjgl/util/WaveData.java I can see that happening:

Code:
   private static ByteBuffer convertAudioBytes(byte[] audio_bytes, boolean two_bytes_data) {
        ByteBuffer dest = ByteBuffer.allocateDirect(audio_bytes.length);
        dest.order(ByteOrder.nativeOrder());
        ByteBuffer src = ByteBuffer.wrap(audio_bytes);
        src.order(ByteOrder.LITTLE_ENDIAN);
        if (two_bytes_data) {
            ShortBuffer dest_short = dest.asShortBuffer();
            ShortBuffer src_short = src.asShortBuffer();
            while (src_short.hasRemaining())
                dest_short.put(src_short.get());
        } else {
            while (src.hasRemaining())
                dest.put(src.get());
        }
        dest.rewind();
        return dest;
    }


Is this documented anywhere except by the source?
(and here now  Smiley )
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!