Results 1 to 3 of 3

Thread: [OpenAL] Signed Audio Samples

  1. #1
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    [OpenAL] Signed Audio Samples

    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?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  2. #2
    Co-Founder / PGD Elder WILL's Avatar
    Join Date
    Apr 2003
    Location
    Canada
    Posts
    6,107
    Blog Entries
    25

    [OpenAL] Signed Audio Samples

    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?

    [pascal]var
    original_data: ShortInt; // 8-bit signed value
    final_data: Byte;

    final_data := original_data + 128;[/pascal]

    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...?
    Jason McMillen
    Pascal Game Development
    Co-Founder





  3. #3

    [OpenAL] Signed Audio Samples

    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:[pascal]var
    i: shortint;
    b: byte;
    begin
    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
    end.
    [/pascal]
    You just need to try out which one will work for OpenAL correctly.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •