OpenALLayer.cpp 2.61 KB
Newer Older
jpbl's avatar
jpbl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 *  Copyright (C) 2004-2005 Savoir-Faire Linux inc.
 *  Author: Jean-Philippe Barrette-LaPierre
 *             <jean-philippe.barrette-lapierre@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *                                                                              
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *                                                                              
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "OpenALLayer.hpp"
#include "OpenALDevice.hpp"
#include "NullDevice.hpp"

#include <iostream>
#include <AL/al.h>
#include <AL/alc.h>

29
#define DEFAULT_DEVICE_NAME "default"
jpbl's avatar
jpbl committed
30
#define DEFAULT_CAPTURE_DEVICE_NAME "default"
31

jpbl's avatar
jpbl committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
SFLAudio::OpenALLayer::OpenALLayer() 
  : AudioLayer("openal")
{}

std::list< std::string > 
SFLAudio::OpenALLayer::getDevicesNames() 
{
  std::list< std::string > devices;
  if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) {
    const ALCchar *devs = alcGetString(NULL, ALC_DEVICE_SPECIFIER);
    const ALCchar *devname = devs;
    while(devname) {
      devices.push_back(devname);
      devname += sizeof(ALCchar) * (strlen(devname) + 1);
    }
  }
48 49 50 51
  else {
    devices.push_back(DEFAULT_DEVICE_NAME);
  }
  
jpbl's avatar
jpbl committed
52 53 54 55 56

  return devices;

}

jpbl's avatar
jpbl committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
std::list< std::string > 
SFLAudio::OpenALLayer::getCaptureDevicesNames() 
{
  std::list< std::string > devices;
  if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) {
    const ALCchar *devs = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
    const ALCchar *devname = devs;
    while(devname) {
      devices.push_back(devname);
      devname += sizeof(ALCchar) * (strlen(devname) + 1);
    }
  }
  else {
    devices.push_back(DEFAULT_CAPTURE_DEVICE_NAME);
  }
  

  return devices;

}


jpbl's avatar
jpbl committed
79 80 81 82
SFLAudio::Device *
SFLAudio::OpenALLayer::openDevice()
{
  Device *dev = new OpenALDevice();
83 84 85 86
  if(dev->load()) {
    dev->setName(DEFAULT_DEVICE_NAME);
  }
  else {
jpbl's avatar
jpbl committed
87 88 89 90 91 92 93 94 95 96 97 98 99 100
    delete dev;
    dev = new NullDevice();
  }

  return dev;
}

SFLAudio::Device *
SFLAudio::OpenALLayer::openDevice(const std::string &)
{
  return new NullDevice();
}