Raw audio data problems

Hi everyone :slight_smile:

Well, I tried to post this message on saturday to the newsgroup but it
seems the moderator’s answer was caught by my spamfilter so I try it
again as a registered user :slight_smile:

I am a member of a team writing a new game with SDL.
My current task is to write the sound routines and it works pretty good
with
normal WAV files.

But I have problems with RAW audio files which are created on an Amiga
(so
they are big-endian files).
Those files are not playable with SDL but I have read SDL can handle raw
audio files.

I explored google but unfortunately I could not find any example code
snippet how to deal with raw audio files.

On Linux “file mouseclick.raw” prints “data” :frowning:

I hope someone can help me here :slight_smile:

Thanks and regards,
Hauke–
Aus Ben Hur (1959): Wer nicht fuer Rom ist, ist gegen Rom
George W. Bush (2002): Wer nicht fuer uns ist, ist gegen uns

[…big endian raw audio files…]

I explored google but unfortunately I could not find any example
code snippet how to deal with raw audio files.
[…]

Well, that’s probably because a “raw audio file” could be pretty much
anything. There’s no way to tell what a raw file is, or what endian
it is, or anything else by that name, or by looking at the file; it’s
just plain raw data.

Anyway, assuming they’re 16 bit big endian files (mono or stereo
doesn’t matter) and you want 16 bit little endian, just load the file
and then go through the buffer swapping bytes. Something like this
should do:

void flip_endian(Uint8 *data, int length)
{
int i;
for(i = 0; i < length; i += 2)
{
int x = data[i];
data[i] = data[i + 1];
data[i + 1] = x;
}
}

(From “simplemixer” at http://olofson.net/examples.html)

BTW, how are you doing the mixing; custom code, SDL_mixer, or
something else? Keep in mind that if you want your code to be
portable, you most probably want to leave the data as is if you
compile for a big endian system.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Wednesday 12 November 2003 08.15, Hauke J. Zuehl wrote:

Hi David :slight_smile:

Well, that’s probably because a “raw audio file” could be pretty much
anything. There’s no way to tell what a raw file is, or what endian
it is, or anything else by that name, or by looking at the file; it’s
just plain raw data.

Hmmm…

Anyway, assuming they’re 16 bit big endian files (mono or stereo
doesn’t matter) and you want 16 bit little endian, just load the file
and then go through the buffer swapping bytes. Something like this
should do:

void flip_endian(Uint8 *data, int length)

Okay…we have such a function in our project :slight_smile:

(From “simplemixer” at http://olofson.net/examples.html)

Good to know :slight_smile:

BTW, how are you doing the mixing; custom code, SDL_mixer, or
something else? Keep in mind that if you want your code to be
portable, you most probably want to leave the data as is if you
compile for a big endian system.

Well, I use SDL_MixAudio to mix the sounds.

The code I use can be found on
http://athene.dnsalias.org/~hauke/SfxSound.txt
(Comments are written in German)

A short description:
We have arrays to store the name of the soundfile (just to know what
sound we want to play).
Then I prepare the spec structure with needed data, load the WAV, store
the callback function and opens audio.

That’s all but no sound :frowning:

Regards,
HaukeAm Mit, 2003-11-12 um 08.42 schrieb David Olofson:

Aus Ben Hur (1959): Wer nicht fuer Rom ist, ist gegen Rom
George W. Bush (2002): Wer nicht fuer uns ist, ist gegen uns