Jump to content


changing the output device with openAL


6 replies to this topic

#1 tarbeu

    New Member

  • Members
  • Pip
  • 2 posts

Posted 19 March 2004 - 06:54 AM

I don't know how I can choose an other output sound card than the primary sound device.
Is it possible to choose the secondary sound card with the function alcOpenDevice()
or is it an other function which could allow to play a sound on the sound card of my choice either the primary sound card either the secondary sound card.
Thank you for your help.

#2 SpreeTree

    Valued Member

  • Members
  • PipPipPip
  • 265 posts

Posted 20 March 2004 - 04:11 PM

To be honest, from my experience, I dont think you can. I had a good look at the OpenAL spec's, and as far as I can tell, using alcOpenDevice(...) selects the device that is most suited to the method you have choosen. It doesnt specifiy wether multiple calls to alcOpenDevice(...) selects another sound device, or just uses the same one.

It might be worth looking at OpenGL (this is a total shot in the dark, so I may be totally wrong here) and seeing if you can select different display devices. If you can, you might be able to use a similar method in AL. But as I said, thats a shot in the dark...

Sorry I couldnt be more help
Spree

#3 anubis

    Senior Member

  • Members
  • PipPipPipPip
  • 2225 posts

Posted 20 March 2004 - 07:00 PM

you can't do that with opengl
If Prolog is the answer, what is the question ?

#4 SpreeTree

    Valued Member

  • Members
  • PipPipPip
  • 265 posts

Posted 22 March 2004 - 11:16 AM

I did say it was a shot in the dark, oh well ;)

Just reading the OpenAL mailing lists, and the same question came up. So I guess it can be done! :)

Here is one of the responses

Quote

If you download the code from CVS (instructions at
http://www.openal.org/downloads.html), you'll find the source code for
"altest" in openal/demos/altest/common/altest.cpp.  During
initialization, you'll see a reference to enumeration -- that section
will show you how to use the context enumeration extension to enumerate
the various "devices" on your system.

These "devices" do not necessarily correspond with sound cards,
however.  For instance, I have a computer at work with an NVIDIA
nForce2 and a Creative Audigy 2 in it.  The devices enumerate and will
play back as follows:

Device Name / playback device
MMSYSTEM / whatever is the "preferred audio device" selected for Windows
DirectSound / "preferred audio device" as with MMSYSTEM
DirectSound3D / "preferred audio device" as with MMSYSTEM
NVIDIA nForce2 / always will play back on the nForce 2
Creative Audigy 2 / always will play back on the Audigy 2

On your system, if you have an nForce2 and a Creative card, then you'll
see explicit entries for those two cards on your device list.  Any card
that doesn't have its own accelerated OpenAL implementation will have
to be selected by using one of the generic devices, which will follow
the "preferred audio device" selection in Windows.

Bare in mind that the DirectSound3D enumeration has a few bugs associated with it, so at the moment, out of the 3 standard devices, DirectSound is probably the best bet

Hope that helps some
Spree

#5 tarbeu

    New Member

  • Members
  • Pip
  • 2 posts

Posted 23 March 2004 - 04:14 AM

that was me who ask that in the openAL forum :blink:
I have tried what the guy has tell but it seems only working
with nForce2 and Creative audigy sound card....
and I don't have any of these sound card....
If anyone has a solution with other type of soundcard
thank you for your help.

#6 SpreeTree

    Valued Member

  • Members
  • PipPipPip
  • 265 posts

Posted 23 March 2004 - 09:35 AM

Haha thought it might have been, but thought I'd post it anyway ;)

Spree

#7 kitt3n

    New Member

  • Members
  • PipPip
  • 15 posts

Posted 03 September 2004 - 02:32 PM

Sth like this to detect all devices

const alDeviceList* sound::getDeviceList (bool refresh)
{
  if (devList.numDevices==0 || refresh)
  {
    char deviceName[256] = {0};
  char *defaultDevice=NULL;
  char *deviceList=NULL;

  if (alcIsExtensionPresent(NULL, (ALubyte*)"ALC_ENUMERATION_EXT") == AL_TRUE) 
    { // try out enumeration extension
    deviceList = (char *)alcGetString(NULL, ALC_DEVICE_SPECIFIER);

      devList.numDevices = 0;
      if (strlen(deviceList))
      {
        devList.numDevices=1;
      defaultDevice = (char *)alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
        devList.numDefaultDevice = 0;

      for (U16 numDevices = 0; numDevices < 16; numDevices++) 
        {
      devList.devices[numDevices] = deviceList;
      if (defaultDevice && strcmp(devList.devices[numDevices], defaultDevice) == 0) 
          {
        devList.numDefaultDevice = numDevices;
      }

      deviceList += strlen(deviceList);


      if (deviceList[0] == 0)
          {
        if (deviceList[1] == 0) 
            {
        break;
        } 
            else 
            {
              devList.numDevices++;
        deviceList++; 
        }
      }
        }
    }
    }
  }
  return &devList;
}

and then sth like this - mind you, only tested on sb-audigy,
switching sound without exiting the game also works (although
old sound will be stopped so you will only hear new sounds):


bool sound::useDevice    (U16 id)
{
  bool result = false;
  const char* devname = getDeviceName (id);

  // terminate old device + context
  destroyBuffers();

  alcMakeContextCurrent(NULL);
  if (pDevice)
    alcCloseDevice(pDevice);
  if (pContext)
    alcDestroyContext(pContext);

  // open 
  if (id<SOUND_AL_MAXDEVICE)
  {
    // open specified device
    pDevice  = alcOpenDevice((unsigned char*)devList.devices[id]);
    devList.curDevice = id;
    pContext = alcCreateContext(pDevice, NULL);
    alcMakeContextCurrent(pContext);
    initBuffers();
    result=true;
  }
  else
  {
    // open default device
    pDevice  = alcOpenDevice(NULL);
    devList.curDevice = devList.numDefaultDevice;
    pContext = alcCreateContext(pDevice, NULL);
    alcMakeContextCurrent(pContext);
    initBuffers();
    result=true;
  }

  alDistanceModel (AL_NONE); // or whatever distanceModel you like

  return result;
}
Note that you'll probably need some locks to avoid threading problems





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users