Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Spatialization and sound channels  (Read 8830 times)

0 Members and 2 Guests are viewing this topic.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Spatialization and sound channels
« 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)
Pluma - Plug-in Management Framework

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Spatialization and sound channels
« Reply #1 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.
Laurent Gomila - SFML developer

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Spatialization and sound channels
« Reply #2 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"
Pluma - Plug-in Management Framework

drmoth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Spatialization and sound channels
« Reply #3 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.

gsaurus

  • Sr. Member
  • ****
  • Posts: 262
    • View Profile
    • Evolution Engine
Spatialization and sound channels
« Reply #4 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.
Pluma - Plug-in Management Framework

drmoth

  • Newbie
  • *
  • Posts: 9
    • View Profile
Spatialization and sound channels
« Reply #5 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);