Commit e5bd0270 authored by jpbl's avatar jpbl

started openal work

parent 8fb3fff5
SUBDIRS = gsm pacpp
SUBDIRS = gsm pacpp OpenAL
noinst_LTLIBRARIES = libaudio.la
......
/*
* 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 "AudioLayer.hpp"
#include "Device.hpp"
SFLAudio::AudioLayer::AudioLayer(const std::string &name)
: mName(name)
{}
std::string
SFLAudio::AudioLayer::getName()
{
return mName;
}
/*
* 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.
*/
#ifndef __SFLAUDIO_AUDIO_LAYER_HPP__
#define __SFLAUDIO_AUDIO_LAYER_HPP__
#include <list>
#include <string>
namespace SFLAudio
{
class Device;
class AudioLayer
{
public:
/**
* This will initialize this audio system. The name
* given in argument is the name of the system.
*
*/
AudioLayer(const std::string &name);
/**
* This function returns all the devices availables
* on the system.
*/
virtual std::list< std::string > getDevicesNames() = 0;
/**
* Will return the name of the audio system. OpenAL or
* PortAudio might be an answer.
*/
std::string getName();
/**
* Open the default device.
*/
virtual Device *openDevice() = 0;
/**
* Open the specified device. If the device don't
* exists, the default will be opened.
*/
virtual Device *openDevice(const std::string &name) = 0;
private:
std::string mName;
};
}
#endif
/**
* 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.
*/
#ifndef __SFLAUDIO_AUDIO_MANAGER_HPP__
#define __SFLAUDIO_AUDIO_MANAGER_HPP__
#include "utilspp/Singleton.hpp"
#include "AudioManagerImpl.hpp"
namespace SFLAudio
{
typedef utilspp::SingletonHolder< AudioManagerImpl > AudioManager;
}
#endif
/*
* 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 "AudioManagerImpl.hpp"
#include "NullLayer.hpp"
#include "OpenALLayer.hpp"
#include "PortAudioLayer.hpp"
SFLAudio::AudioManagerImpl::AudioManagerImpl()
{
mLayer = NULL;
registerLayer(new SFLAudio::PortAudioLayer());
registerLayer(new SFLAudio::OpenALLayer());
}
SFLAudio::AudioManagerImpl::~AudioManagerImpl()
{
for(LayersType::iterator layer = mLayers.begin();
layer != mLayers.end();
layer++) {
delete layer->second;
}
}
std::list< SFLAudio::AudioLayer * >
SFLAudio::AudioManagerImpl::getLayers()
{
std::list< AudioLayer * > layers;
for(LayersType::iterator layer = mLayers.begin();
layer != mLayers.end();
layer++) {
layers.push_back(layer->second);
}
return layers;
}
SFLAudio::AudioLayer *
SFLAudio::AudioManagerImpl::getLayer(const std::string &name)
{
AudioLayer *layer = NULL;
LayersType::iterator it = mLayers.find(name);
if(it != mLayers.end()) {
layer = it->second;
}
else {
layer = new NullLayer();
}
return layer;
}
SFLAudio::AudioLayer *
SFLAudio::AudioManagerImpl::defaultLayer()
{
return getLayer("openal");
}
SFLAudio::AudioLayer *
SFLAudio::AudioManagerImpl::currentLayer()
{
if(mLayer == NULL) {
mLayer = defaultLayer();
}
return mLayer;
}
void
SFLAudio::AudioManagerImpl::currentLayer(AudioLayer *layer)
{
if(layer != NULL) {
mLayer = layer;
}
}
void
SFLAudio::AudioManagerImpl::registerLayer(AudioLayer *layer)
{
mLayers.insert(std::make_pair(layer->getName(), layer));
}
/*
* 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.
*/
#ifndef __SFLAUDIO_AUDIO_MANAGER_IMPL_HPP__
#define __SFLAUDIO_AUDIO_MANAGER_IMPL_HPP__
#include <list>
#include <map>
#include <string>
namespace SFLAudio
{
class AudioLayer;
class AudioManagerImpl
{
public:
/**
* We load all available layers.
*/
AudioManagerImpl();
~AudioManagerImpl();
/**
* Return all loaded layers.
*/
std::list< AudioLayer * > getLayers();
/**
* Return the layer specified. It will return NULL if
* there's no corresponding layer.
*/
AudioLayer *getLayer(const std::string &name);
/**
* Return the default layer.
*/
AudioLayer *defaultLayer();
/**
* Return the current layer.
*/
AudioLayer *currentLayer();
/**
* Set the current layer. It will do nothing if the
* layer is NULL.
*/
void currentLayer(AudioLayer *layer);
/**
* Will register the layer. The manager will be
* the pointer's owner. You can use this if you
* have a layer that is isn't included in the main
* library.
*/
void registerLayer(AudioLayer *layer);
private:
typedef std::map< std::string, AudioLayer * > LayersType;
LayersType mLayers;
AudioLayer *mLayer;
};
}
#endif
/*
* 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 "Context.hpp"
#include "NullSource.hpp"
SFLAudio::Source *
SFLAudio::Context::createSource()
{
return new NullSource();
}
/*
* 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.
*/
#ifndef __SFLAUDIO_CONTEXT_HPP__
#define __SFLAUDIO_CONTEXT_HPP__
namespace SFLAudio
{
class Source;
class Context
{
public:
/**
* Create a source for the context.
*/
Source *createSource();
};
}
#endif
/*
* 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 "Device.hpp"
SFLAudio::Device::Device()
: mContext(0)
{}
SFLAudio::Device::Device(const std::string &name)
: mName(name)
, mContext(0)
{}
std::string
SFLAudio::Device::getName()
{
return mName;
}
bool
SFLAudio::Device::isNull()
{
return false;
}
void
SFLAudio::Device::setName(const std::string &name)
{
mName = name;
}
SFLAudio::Context *
SFLAudio::Device::currentContext(Context *context)
{
if(context != 0) {
mContext = context;
}
return mContext;
}
/*
* 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.
*/
#ifndef __SFLAUDIO_DEVICE_HPP__
#define __SFLAUDIO_DEVICE_HPP__
#include <string>
namespace SFLAudio
{
class Context;
class Device
{
public:
Device();
Device(const std::string &name);
/**
* This will load the device. You shouldn't use
* this function directly. It returns true if
* the load is successfull.
*/
virtual bool load() = 0;
/**
* This will create a context for the device.
* If there's no current context, it will be
* set as the current;
*/
virtual Context *createContext() = 0;
/**
* This will set the current context. If NULL is
* given, the context isn't changed. It returns the
* current context.
*/
Context *currentContext(Context *context = 0);
std::string getName();
void setName(const std::string &name);
/**
* Return true if the device is the NullDevice.
*/
bool isNull();
private:
std::string mName;
Context *mContext;
};
}
#endif
noinst_PROGRAMS = example01 example02
noinst_LTLIBRARIES = libsflaudio.la
libsflaudio_la_SOURCES = \
AudioLayer.cpp AudioLayer.hpp \
AudioManagerImpl.cpp AudioManagerImpl.hpp \
Context.cpp Context.hpp \
Device.cpp Device.hpp \
NullLayer.cpp NullLayer.hpp \
NullDevice.cpp NullDevice.hpp \
NullContext.cpp NullContext.hpp \
NullSource.hpp \
OpenALLayer.cpp OpenALLayer.hpp \
OpenALDevice.cpp OpenALDevice.hpp \
PortAudioLayer.cpp PortAudioLayer.hpp \
SFLAudio.hpp \
Source.hpp
AM_CPPFLAGS = $(PORTAUDIO_CFLAGS) -I../pacpp/include -I$(top_srcdir)/libs/portaudio/pa_common -I$(top_srcdir)/libs/
AM_CXXFLAGS = $(PORTAUDIO_CXXFLAGS) -I$(top_srcdir)/libs/
AM_LDFLAGS = -L$(top_srcdir)/libs/portaudio/
LIBADD = $(PORTAUDIO_LIBS) -lportaudio -lopenal
LDADD = libsflaudio.la $(PORTAUDIO_LIBS) -lopenal ../pacpp/source/portaudiocpp/libportaudiocpp.la -lportaudio
example01_SOURCES = example01.cpp
example02_SOURCES = example02.cpp
/*
* 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 "NullContext.hpp"
#include "NullSource.hpp"
SFLAudio::Source *
SFLAudio::NullContext::createSource()
{
return new NullSource();
}
/*
* 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.
*/
#ifndef __SFLAUDIO_NULL_CONTEXT_HPP__
#define __SFLAUDIO_NULL_CONTEXT_HPP__
#include "Context.hpp"
namespace SFLAudio