-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|555|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> File Access


 
Afr0
Created : 26 July 2009
Edited : 11 December 2009
System : Windows
Language : C/C++

*.XA loading + decompressing

Load sounds from Maxis games!



Credits: The decompression functions were ported to C# from this code.

 

Comments


Sunday, 26 July 2009, 12:52
Afr0
If you are going to port this, note that longs are 64 bits in C#, and have thusly been replaced with ints in this code.
In C++, you'd normally use long instead.

Also note that this class is designed to inflate the compressed data in memory. You could also write the inflated data directly to a file, though this is not recommended for realtime use!
Sunday, 26 July 2009, 13:07
Phoenix
In C++ you'd have to use some preprocessor macros to get exactly 64 bits (if possible), or long longs to get at least 64 bits in the integer.

I'm not sure how useful this is for the rest of us who aren't interested in remaking The Sims Online, but it looks like some decent working code.
Sunday, 26 July 2009, 13:19
JL235
It's MS only, but there is also __int64.
Sunday, 26 July 2009, 14:15
Afr0
No, no!
Longs are 32 bits in C++, and are stored as 32 bits in XA files and Wav files. So you should treat them as 32 bits.

Oh and XA files are used in all Maxis games from Sim City 3000 onwards. I believe there is even an early version of *.xa used in Sim City 2000, but I've never actually opened any of those data files.
Sunday, 26 July 2009, 14:31
Phoenix
*sigh*

We already had this discussion in the chat a while ago. In C++, things aren't that simple. There are no guarantees that an int is 32 bits, or even that a char is 8 bits.
Monday, 27 July 2009, 00:55
cthug
You could use SDL types (Uint32, Uint8 etc)
Friday, 31 July 2009, 17:20
Afr0
I'm not sure if the original code is designed to be compiled as C or C++, but it seems to be using the Microsoft specific types like LONG, BYTE and DWORD. These are, IIRC, defined in Windows.h, and should be confined to 'general' standards like LONG = 32 bits and BYTE is 8 bits.

See the link in the original post for reference.