View Full Version : [OpenAL] Signed Audio Samples

09-12-2007, 10:12 PM
Is it possible to send signed audio samples to an OpenAL buffer to process?

The XM module format has 8/16-bit signed audio samples so this is what I'm stuck working with for playback, but the OpenAL wrapper I'm using doesn't seem to have a buffer format that includes signed data.

Suggestions, insight?

Also does DirectSound[3D] have the same restriction for audio data?

15-12-2007, 04:12 AM
Ok.... assuming that I have to convert my audio, lets draw out the problem into a simple example...

Lets say the audio data is 8-bit signed samples. Instead what I need to play it back in OpenAL is 8-bit unsigned samples.

Would I not be able to do this to convert?

original_data: ShortInt; // 8-bit signed value
final_data: Byte;

final_data := original_data + 128;

Considering this would equally transfer the place within the range of -128 to 127 over to 0 to 255?

Same, same with 16-bit values only that it's double the range...?

15-12-2007, 05:43 AM
Yes, that would work. The other solution is to just treat the values as unsigned data. This leaves positive numbers as they are and converts negatives: [-1..-128] will be [255..128] if I'm not mistaken. This example illustrates the both cases:var
i: shortint;
b: byte;
i := 50;
b := byte(i);
writeln(b); //50

i := 50;
b := i + 128;
writeln(b); //178

i := -50;
b := byte(i);
writeln(b); //206

i := -50;
b := i + 128;
writeln(b); //78

You just need to try out which one will work for OpenAL correctly.