Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: stereo to 2 mono channels, can it be done?

  1. #1

    stereo to 2 mono channels, can it be done?

    Is it possible to 'demix' a stereo sound buffer to 2 mono channels? That way i could play a streaming stereo .ogg file via 2 virtual speakers in a 3d world. Is there a math trick to get 2 mono channels from the mixed stereo signal? Or is it just impossible.
    http://3das.noeska.com - create adventure games without programming

  2. #2

    stereo to 2 mono channels, can it be done?

    That'd be awesome.

    I think it's possible. You have to convert your audio to PCM WAV, and then you have to split up the data. I'm not sure but i think you do it like this:
    When you have a 16 bit stereo WAV buffer, you read the first 16 bits and put those in a 16 bit mono buffer. the next 16 bits should be moved to the second mono buffer, the next 2bytes to the first buffer and so on... keep alternating between the two buffers.

    I think that'll do the trick. If it works I would love to have the code. :razz: Are you planning to put it on your site?

    I googled for it and i think this page confirms my assumption.

    Good luck!
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  3. #3

    stereo to 2 mono channels, can it be done?

    I found this page too.
    Jarrod Davis
    Technical Director @ Piradyne Games

  4. #4

    stereo to 2 mono channels, can it be done?

    Ok i have a first result:

    Code:
    for i:=0 to BufferSize div 2 do
      begin
        if ( l= true ) then
        begin
          PByteArray(dataR)^[iR]:=PByteArray(data)^[i*2];
          PByteArray(dataR)^[iR+1]:=PByteArray(data)^[i*2+1];
          ic:=ic+2;
          iR:=iR+2;
          l:=false;
        end
        else
        begin
          PByteArray(dataL)^[iL]:=PByteArray(data)^[i*2];
          PByteArray(dataL)^[iL+1]:=PByteArray(data)^[i*2+1];
          ic:=ic+2;
          iL:=iL+2;
          l:=true;
        end;
      end;
    
      alBufferData(Buffer, Format, dataR, BufferSize div 2, FRate);
    So to get this further to work i need to have 2 sources with double buffering. Also note the div 2 for the buffersize. And yes the code needs much cleaning up.

    I now need an .ogg or .mp3 file with heareable stereo effect to properly test it. My current test files are not suiteable. Does anyone here have such a thing lying around? I have not.
    http://3das.noeska.com - create adventure games without programming

  5. #5

    stereo to 2 mono channels, can it be done?

    Here is an finished example: http://www.noeska.net/downloads/oggstream.zip .

    Try experimenting with the L and R source positions. You need the ogg player example for ogg vorbis units and ogg vorbis dlls. I used .ogg as i found an .ogg file with heareable stereo effect.
    http://3das.noeska.com - create adventure games without programming

  6. #6

    stereo to 2 mono channels, can it be done?

    Thanks for the code. It seems to work.

    However i don't find the results satisfactory. I've tried some dance music and there is still a little delay between the two channels. What kind of music did you try? Did you notice any delays? The delay isn't very big (i guess 20ms or so) but it is still noticable. I tried fixing it but i do not have much experience with threading etc.. so i got stuck.

    maybe you can test some dance music? Do you think there is any way to solve this? Can we sync the buffers in some way?
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  7. #7

    stereo to 2 mono channels, can it be done?

    I haven been testing with some ryan addams music: http://www.archive.org/details/ra200...-22.flac16.sbd
    And a whoosh sound effect file.
    I also noticed a difference in sound but i did not relate i to a delay in sound. If you turn of either left or right source you will also hear a part of the other source somewhat softer on the other side. I blamed it on that but yours is also a reason.
    Unfortunately you can only fill the buffers of one source at one time.

    Possible fix: advance source one so it in sync with source 2.
    Possible fix2: alSourcePlayv(2,@Sources);
    http://3das.noeska.com - create adventure games without programming

  8. #8

    stereo to 2 mono channels, can it be done?

    I just tried possible fix 2 and i cannot directly tell whether it's an improvement or not. :? I'm not sure what the code for possible fix 1 should look like.

    You should try some dance music (if you have some). The bass-drum should be one clear kick, but it isn't. It's echooing and it all sounds a bit strange.

    If you like, i can mail you the ogg i use, so you can hear for yourself (plz PM me your mail-adres).
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

  9. #9

    stereo to 2 mono channels, can it be done?

    I think the echo you are refering to is in not even caused by not playing sources in sync or not feeding the buffers correctly, but by OpenAL spatializing the sound. E.g. you get feeback from the left channel on the right and the other way. I hear the effect also in the applause in the Ryan Addams ogg files.

    The theory with advancing one source is that if one source is 20ms ahead you should ffwd the other source by 20ms or slow down the other source. Also when feeding data to the buffer you could skip the first 20ms of data for the buffer that is behind. But i did not get good results with either method.

    For the spatializing, we can make that partially good be setting up the OpenAL environment.
    Code:
      alDistanceModel( AL_INVERSE_DISTANCE  );
    (Yes there is a nasty typo bug in the openal.pas again.)
    And set up sources like:

    Code:
      alSource3f(sourceL, AL_POSITION, -5.5, 0, 0.0);
      alSource3f(sourceL, AL_VELOCITY, 0, 0, 0);
      alSource3f(sourceL, AL_DIRECTION, 0, 0, 0);
      alSourcef(sourceL, AL_ROLLOFF_FACTOR, 1.5);
      alSourcei(sourceL, AL_SOURCE_RELATIVE, AL_FALSE);
    
      alSource3f(sourceR, AL_POSITION, 5.5, 0, 0.0);
      alSource3f(sourceR, AL_VELOCITY, 0, 0, 0);
      alSource3f(sourceR, AL_DIRECTION, 0, 0, 0);
      alSourcef(sourceR, AL_ROLLOFF_FACTOR, 1.5);
      alSourcei(sourceR, AL_SOURCE_RELATIVE, AL_FALSE);
    It is not correct with this, but you can use this to control it a bit.
    http://3das.noeska.com - create adventure games without programming

  10. #10

    stereo to 2 mono channels, can it be done?

    I think it's a little improvement but i still hear the bass-drum echooing.

    but by OpenAL spatializing the sound. E.g.
    Can you explain it a little more? Is it caused by the time taken by OpenAL to process the buffer for spatializing?
    Coders rule nr 1: Face ur bugz.. dont cage them with code, kill'em with ur cursor.

Page 1 of 2 12 LastLast

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
  •