Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (532)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Bug in Mac OS X version: flipped bytes  (Read 2754 times)
0 Members and 1 Guest are viewing this topic.
Offline itistoday

Junior Member




There's too much blood in my caffeine system.


« Posted 2004-11-28 00:58:50 »

There's a bug in the OS X version of JOAL that several people have posted about here and other forums where projects (like Xith) use JOAL.  As I understand it, OS X uses big-endian words, and so in 16-bit wav files (ogg seems to be affected by this too) JOAL reads the bytes in reverse order, resulting in static sound (8-bit files, since there's nothing to flip, are read correctly).  This seems like it could be easily fixed if JOAL simply checks if the OS is OS X and reads the files in big-endian format.  I've checked out the CVS source and the bug is still in there.

Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #1 - Posted 2004-11-28 03:11:35 »

I patched WAVLoader.java with this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
        ByteBuffer buffer = ByteBuffer.allocateDirect(size);
        aChannel.read(buffer);
      
      // On Mac we need to convert this to big endian
     if (bits == 16 && ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
      {
            buffer.rewind();
            ShortBuffer tmp = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
            while(tmp.hasRemaining())
                  buffer.putShort(tmp.get());
      }

        result = new WAVData(buffer, format, size, freq, false);
        aIn.close();

Offline itistoday

Junior Member




There's too much blood in my caffeine system.


« Reply #2 - Posted 2004-11-28 03:32:48 »

Quote
I patched WAVLoader.java with this:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
        ByteBuffer buffer = ByteBuffer.allocateDirect(size);
        aChannel.read(buffer);
     
      // On Mac we need to convert this to big endian
     if (bits == 16 && ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN)
      {
            buffer.rewind();
            ShortBuffer tmp = buffer.duplicate().order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
            while(tmp.hasRemaining())
                  buffer.putShort(tmp.get());
      }

        result = new WAVData(buffer, format, size, freq, false);
        aIn.close();

Awesome! That works perfectly Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #3 - Posted 2004-11-28 03:35:17 »

Java programmers will need to be aware that JOAL on Mac expects 16-bit samples in the native (Big Endian) byte order.   Loaders for OGG will need similar tweaks.

If you are making samples algorithmically with 16-bit samples be sure to set the ByteBuffer to the native byte order before you stuff it with 'shorts'.

Offline xmariachi

Senior Newbie





« Reply #4 - Posted 2005-09-30 15:40:31 »

Yes, it's perfect! thanks swpalmer!!

But, why is this not actually in a new version??
I cannot understand why this issue still isn't fixed in the new versions, given that this post dates back to november 2004!! (almost a year ago).

Actually, I will put a new post regarding this... for anyone that has that problem.
Thanks again
Offline ajmas

Junior Member




Miles away from here!


« Reply #5 - Posted 2005-12-21 04:58:54 »

Just a heads up that if you do any byte flipping here, because if you tested for MacOS X, make sure you also check for the architecture. I say this since this will break otherwise on the new x86 machines due out in 2006. Truth is, this should be fixed in the native library.
Offline swpalmer

JGO Coder




Where's the Kaboom?


« Reply #6 - Posted 2005-12-21 05:13:21 »

If you take a closer look at my fix.. I used "ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN",  I chose that on-purpose in the hope that it would work for unforseen platforms (e.g. Linux PPC).  So hopefully OS X on Intel will "just work".

Offline Ken Russell

JGO Coder




Java games rock!


« Reply #7 - Posted 2005-12-21 09:44:31 »

swpalmer: thanks for the patch. I'll apply something similar to the source base soon.

Regarding the lack of updates on JOAL, the original maintainer left Sun a while back and the project has been somewhat orphaned since then. I'll post an update in another thread.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (14 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (15 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (39 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (36 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!