SFML community forums

Help => Audio => Topic started by: gsaurus on November 27, 2009, 12:33:49 am

Title: Spatialization and sound channels
Post by: gsaurus on November 27, 2009, 12:33:49 am
Hi all,

I tried the tutorial spatialization example, and got no spatialization effect.
After a while, I decided to convert my sound.wav from stereo to mono, and it finally worked.

So, spatialization only works with mono sounds?

Thanks,
G

Edit: btw, windows xp, code::blocks (MinGW)
Title: Spatialization and sound channels
Post by: Laurent on November 27, 2009, 08:47:00 am
Quote
So, spatialization only works with mono sounds?

Absolutely. Spacialization uses all the channels available to reproduce a 3D effect; if the sound already uses more than one channel there's an obvious conflict.

I just realized that this information is completely missing from the tutorials. I suck.
Title: Spatialization and sound channels
Post by: gsaurus on November 27, 2009, 11:31:58 am
Thank you :)
I though it was possible to compute somehow the amount of sound to send for each channel, based on the original sound channels "distribution"
Title: Spatialization and sound channels
Post by: drmoth on November 28, 2009, 03:19:56 pm
You can technically spatialize a stereo sound in 3D, but you have to split it into 2 mono channels, and then decide what distance to apart to space them.

I recently created a "stereo sound" class which just holds the left and right channel data as mono sounds. I used it to be able to pan stereo sounds, but you could also use it I guess to move stereo sounds around in 3d space. If you're interested I could post the code.
Title: Spatialization and sound channels
Post by: gsaurus on November 28, 2009, 06:50:34 pm
That sounds good.
I though about that, but I'm not familiar with audio data manipulation. Your code could be useful.
Title: Spatialization and sound channels
Post by: drmoth on November 28, 2009, 07:05:07 pm
Hi,

my class is here:
http://www.digitalstar.net/openframeworks/SoundStereo.zip

I use it in a different framework than SFML but the only thing that's different is the namespace I think.

In order to get stereo panning I have to set up the audio device like this in AudioDevice.cpp:
Code: [Select]

////////////////////////////////////////////////////////////
/// Default constructor
////////////////////////////////////////////////////////////
AudioDevice::AudioDevice() :
myRefCount(0)
{
    float listenerDepth = 0.1;

    // Create the device
    myDevice = alcOpenDevice(NULL);

    if (myDevice)
    {
        // Create the context
        myContext = alcCreateContext(myDevice, NULL);

        if (myContext)
        {
            // Set the context as the current one (we'll only need one)
            alcMakeContextCurrent(myContext);

            // Initialize the listener
            Listener::SetPosition(0,0,listenerDepth);
            Listener::SetTarget(0,0,-listenerDepth);
        }
        else
        {
            std::cerr << "Failed to create the audio context" << std::endl;
        }
    }
    else
    {
        std::cerr << "Failed to open the audio device" << std::endl;
    }

}


The most important part of the above is this:
Code: [Select]
Listener::SetPosition(0,0,listenerDepth);
Listener::SetTarget(0,0,-listenerDepth);