diff --git a/src/audio/Makefile.am b/src/audio/Makefile.am index 2f1b897b57652988bb27fc5f49ec42f38c913920..d0fe8c8ee36d30c027cb4713b65f3bd3039faa86 100644 --- a/src/audio/Makefile.am +++ b/src/audio/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = gsm pacpp +SUBDIRS = gsm pacpp OpenAL noinst_LTLIBRARIES = libaudio.la diff --git a/src/audio/OpenAL/AudioLayer.cpp b/src/audio/OpenAL/AudioLayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..556f5927c6e447d25b98e109d53313503740c10e --- /dev/null +++ b/src/audio/OpenAL/AudioLayer.cpp @@ -0,0 +1,35 @@ +/* + * 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; +} + + + diff --git a/src/audio/OpenAL/AudioLayer.hpp b/src/audio/OpenAL/AudioLayer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4fe1c4a496f01a6162851466eda762c66eda6ddc --- /dev/null +++ b/src/audio/OpenAL/AudioLayer.hpp @@ -0,0 +1,71 @@ +/* + * 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 + + diff --git a/src/audio/OpenAL/AudioManager.hpp b/src/audio/OpenAL/AudioManager.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5c2ee4acde18f990646278bbbf5887000ea6148e --- /dev/null +++ b/src/audio/OpenAL/AudioManager.hpp @@ -0,0 +1,33 @@ +/** + * 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 + diff --git a/src/audio/OpenAL/AudioManagerImpl.cpp b/src/audio/OpenAL/AudioManagerImpl.cpp new file mode 100644 index 0000000000000000000000000000000000000000..15397ea4d280e9114ba97f0d14991f3e244673a8 --- /dev/null +++ b/src/audio/OpenAL/AudioManagerImpl.cpp @@ -0,0 +1,98 @@ +/* + * 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)); +} diff --git a/src/audio/OpenAL/AudioManagerImpl.hpp b/src/audio/OpenAL/AudioManagerImpl.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e3f68204a623ed7a4d8f6359809a04424c2f5fd5 --- /dev/null +++ b/src/audio/OpenAL/AudioManagerImpl.hpp @@ -0,0 +1,85 @@ +/* + * 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 + diff --git a/src/audio/OpenAL/Context.cpp b/src/audio/OpenAL/Context.cpp new file mode 100644 index 0000000000000000000000000000000000000000..47e03d498b493f50b5114080454482aba4c02c10 --- /dev/null +++ b/src/audio/OpenAL/Context.cpp @@ -0,0 +1,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 "Context.hpp" +#include "NullSource.hpp" + +SFLAudio::Source * +SFLAudio::Context::createSource() +{ + return new NullSource(); +} diff --git a/src/audio/OpenAL/Context.hpp b/src/audio/OpenAL/Context.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e22378e05a1911460e923e0e62df65d48598161e --- /dev/null +++ b/src/audio/OpenAL/Context.hpp @@ -0,0 +1,38 @@ +/* + * 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 diff --git a/src/audio/OpenAL/Device.cpp b/src/audio/OpenAL/Device.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b95720a3e6b08c04a4a7cfaef268a081080ffa26 --- /dev/null +++ b/src/audio/OpenAL/Device.cpp @@ -0,0 +1,58 @@ +/* + * 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; +} diff --git a/src/audio/OpenAL/Device.hpp b/src/audio/OpenAL/Device.hpp new file mode 100644 index 0000000000000000000000000000000000000000..751f380d58f20a380e27a8e804435f7b9000b13e --- /dev/null +++ b/src/audio/OpenAL/Device.hpp @@ -0,0 +1,72 @@ +/* + * 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 diff --git a/src/audio/OpenAL/Makefile.am b/src/audio/OpenAL/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..2da160d1efc83f780ed947f27f326df389f274ed --- /dev/null +++ b/src/audio/OpenAL/Makefile.am @@ -0,0 +1,30 @@ +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 + + diff --git a/src/audio/OpenAL/NullContext.cpp b/src/audio/OpenAL/NullContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d83499a3a335c8f7c356346da3de9700fc609561 --- /dev/null +++ b/src/audio/OpenAL/NullContext.cpp @@ -0,0 +1,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 "NullContext.hpp" +#include "NullSource.hpp" + +SFLAudio::Source * +SFLAudio::NullContext::createSource() +{ + return new NullSource(); +} diff --git a/src/audio/OpenAL/NullContext.hpp b/src/audio/OpenAL/NullContext.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4588ff5f17d323f80b06a49ab2677070d7e76adf --- /dev/null +++ b/src/audio/OpenAL/NullContext.hpp @@ -0,0 +1,35 @@ +/* + * 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 +{ + class NullContext : public Context + { + public: + Source *createSource(); + }; +} + +#endif diff --git a/src/audio/OpenAL/NullDevice.cpp b/src/audio/OpenAL/NullDevice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f48417fb10646ac714bc5916c799dafc5774f15d --- /dev/null +++ b/src/audio/OpenAL/NullDevice.cpp @@ -0,0 +1,49 @@ +/* + * 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 <iostream> + +#include "NullDevice.hpp" +#include "NullContext.hpp" + +SFLAudio::NullDevice::NullDevice() + : Device("NullDevice") +{ + currentContext(createContext()); +} + +SFLAudio::Context * +SFLAudio::NullDevice::createContext() +{ + return new NullContext(); +} + + +bool +SFLAudio::NullDevice::load() +{ + return true; +} + +bool +SFLAudio::NullDevice::isNull() +{ + return true; +} diff --git a/src/audio/OpenAL/NullDevice.hpp b/src/audio/OpenAL/NullDevice.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d783518adf2b4df58220413714fa81bb3762cd44 --- /dev/null +++ b/src/audio/OpenAL/NullDevice.hpp @@ -0,0 +1,39 @@ +/* + * 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_DEVICE_HPP__ +#define __SFLAUDIO_NULL_DEVICE_HPP__ + +#include "Device.hpp" + +namespace SFLAudio +{ + class NullDevice : public Device + { + public: + NullDevice(); + Context *createContext(); + + virtual bool load(); + bool isNull(); + }; +} + +#endif diff --git a/src/audio/OpenAL/NullLayer.cpp b/src/audio/OpenAL/NullLayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d9c94e2b8e86323f95ff5552cd19fefe86cc4db --- /dev/null +++ b/src/audio/OpenAL/NullLayer.cpp @@ -0,0 +1,43 @@ +/* + * 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 "NullLayer.hpp" +#include "NullDevice.hpp" + +SFLAudio::NullLayer::NullLayer() + : AudioLayer("NullLayer") +{} + +std::list< std::string > +SFLAudio::NullLayer::getDevicesNames() +{return std::list< std::string >();} + +SFLAudio::Device * +SFLAudio::NullLayer::openDevice() +{ + return new NullDevice(); +} + +SFLAudio::Device * +SFLAudio::NullLayer::openDevice(const std::string &) +{ + return new NullDevice(); +} + diff --git a/src/audio/OpenAL/NullLayer.hpp b/src/audio/OpenAL/NullLayer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dedd263ad86af84c0a5b8c1847807b1242a02d48 --- /dev/null +++ b/src/audio/OpenAL/NullLayer.hpp @@ -0,0 +1,39 @@ +/* + * 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_LAYER_HPP__ +#define __SFLAUDIO_NULL_LAYER_HPP__ + +#include "AudioLayer.hpp" + +namespace SFLAudio +{ + class NullLayer : public AudioLayer + { + public: + NullLayer(); + std::list< std::string > getDevicesNames(); + virtual Device *openDevice(); + virtual Device *openDevice(const std::string &name); + }; +} + +#endif + diff --git a/src/audio/OpenAL/NullSource.hpp b/src/audio/OpenAL/NullSource.hpp new file mode 100644 index 0000000000000000000000000000000000000000..85c07f380ce22a64b81742a58ebf1ab9e6c2ab7e --- /dev/null +++ b/src/audio/OpenAL/NullSource.hpp @@ -0,0 +1,33 @@ +/* + * 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_SOURCE_HPP__ +#define __SFLAUDIO_NULL_SOURCE_HPP__ + +#include "Source.hpp" + +namespace SFLAudio +{ + class NullSource : public Source + { + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenALDevice.cpp b/src/audio/OpenAL/OpenALDevice.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0389e9cc2f0e79c2d87ce1cbee64bf647b0aeb6a --- /dev/null +++ b/src/audio/OpenAL/OpenALDevice.cpp @@ -0,0 +1,51 @@ +/* + * 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 <AL/al.h> +#include <AL/alc.h> + +#include "OpenALDevice.hpp" +#include "OpenALLayer.hpp" +#include "NullContext.hpp" +#include "NullDevice.hpp" + +SFLAudio::OpenALDevice::OpenALDevice() + : mDevice(0) +{} + +bool +SFLAudio::OpenALDevice::load() { + OpenALLayer::clearError(); + mDevice = alcOpenDevice(0); + OpenALLayer::assertError(); + + if(mDevice != 0) { + const ALCchar *device = alcGetString(mDevice, ALC_DEVICE_SPECIFIER); + setName(device); + } + return mDevice; +} + + +SFLAudio::Context * +SFLAudio::OpenALDevice::createContext() +{ + return new NullContext(); +} diff --git a/src/audio/OpenAL/OpenALDevice.hpp b/src/audio/OpenAL/OpenALDevice.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4701d53df51f0329461caea31a246741d9f6dabb --- /dev/null +++ b/src/audio/OpenAL/OpenALDevice.hpp @@ -0,0 +1,41 @@ +/* + * 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_OPENAL_DEVICE_HPP__ +#define __SFLAUDIO_OPENAL_DEVICE_HPP__ + +#include <AL/alc.h> +#include "Device.hpp" + +namespace SFLAudio +{ + class OpenALDevice : public Device + { + public: + OpenALDevice(); + virtual bool load(); + virtual Context *createContext(); + + private: + ALCdevice *mDevice; + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenALLayer.cpp b/src/audio/OpenAL/OpenALLayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8d3130defdd744becb3bb324dcfa859bcfb6336f --- /dev/null +++ b/src/audio/OpenAL/OpenALLayer.cpp @@ -0,0 +1,81 @@ +/* + * 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> + +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); + } + } + + return devices; + +} + +SFLAudio::Device * +SFLAudio::OpenALLayer::openDevice() +{ + Device *dev = new OpenALDevice(); + if(dev->load() == false) { + delete dev; + dev = new NullDevice(); + } + + return dev; +} + +SFLAudio::Device * +SFLAudio::OpenALLayer::openDevice(const std::string &) +{ + return new NullDevice(); +} + +void +SFLAudio::OpenALLayer::assertError() +{ + ALenum error; + if ((error = alGetError()) != AL_NO_ERROR) { + std::cerr << "OpenAL::alcOpenDevice: " << alGetString(error) << std::endl; + } +} + +void +SFLAudio::OpenALLayer::clearError() +{ + alGetError(); +} diff --git a/src/audio/OpenAL/OpenALLayer.hpp b/src/audio/OpenAL/OpenALLayer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ecea6ab510e71d4f5bdeefb2e0a2dfe532199c34 --- /dev/null +++ b/src/audio/OpenAL/OpenALLayer.hpp @@ -0,0 +1,44 @@ +/* + * 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_OPENAL_LAYER_HPP__ +#define __SFLAUDIO_OPENAL_LAYER_HPP__ + +#include "AudioLayer.hpp" + +namespace SFLAudio +{ + class OpenALLayer : public AudioLayer + { + public: + OpenALLayer(); + + virtual std::list< std::string > getDevicesNames(); + virtual Device *openDevice(); + virtual Device *openDevice(const std::string &name); + + static void clearError(); + static void assertError(); + }; +} + +#endif + + diff --git a/src/audio/OpenAL/PortAudioLayer.cpp b/src/audio/OpenAL/PortAudioLayer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4fdf2d7db251fb4588211f1d76e0426b04303491 --- /dev/null +++ b/src/audio/OpenAL/PortAudioLayer.cpp @@ -0,0 +1,66 @@ +/* + * 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 "PortAudioLayer.hpp" +#include "portaudiocpp/Device.hxx" +#include "portaudiocpp/HostApi.hxx" +#include "portaudiocpp/System.hxx" + +#include "NullDevice.hpp" + + +SFLAudio::PortAudioLayer::PortAudioLayer() + : AudioLayer("portaudio") +{ + portaudio::System::initialize(); +} + +SFLAudio::PortAudioLayer::~PortAudioLayer() +{ + portaudio::System::terminate(); +} + +std::list< std::string > +SFLAudio::PortAudioLayer::getDevicesNames() +{ + std::list< std::string > devices; + for(int index = 0; index < portaudio::System::instance().deviceCount(); index++ ) { + portaudio::Device &device = portaudio::System::instance().deviceByIndex(index); + + std::string name(device.hostApi().name()); + name += ": "; + name += device.name(); + devices.push_back(name); + } + + return devices; +} + +SFLAudio::Device * +SFLAudio::PortAudioLayer::openDevice() +{ + return new NullDevice(); +} + +SFLAudio::Device * +SFLAudio::PortAudioLayer::openDevice(const std::string &) +{ + return new NullDevice(); +} diff --git a/src/audio/OpenAL/PortAudioLayer.hpp b/src/audio/OpenAL/PortAudioLayer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..31eac5a03771ba37707ef37875156fdcc6212707 --- /dev/null +++ b/src/audio/OpenAL/PortAudioLayer.hpp @@ -0,0 +1,47 @@ +/* + * 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_PORTAUDIO_LAYER_HPP__ +#define __SFLAUDIO_PORTAUDIO_LAYER_HPP__ + +#include <map> + +#include "AudioLayer.hpp" + +namespace SFLAudio +{ + class PortAudioLayer : public AudioLayer + { + public: + PortAudioLayer(); + ~PortAudioLayer(); + + virtual std::list< std::string > getDevicesNames(); + virtual Device *openDevice(); + virtual Device *openDevice(const std::string &name); + + private: + std::map< std::string, std::pair< int, int > > mDevices; + }; +} + +#endif + + diff --git a/src/audio/OpenAL/README.txt b/src/audio/OpenAL/README.txt new file mode 100644 index 0000000000000000000000000000000000000000..6ed8af5f60b0034b30cd2cef07bcb474c0c054d7 --- /dev/null +++ b/src/audio/OpenAL/README.txt @@ -0,0 +1 @@ +example01.cpp: This is an enumeration of device example. \ No newline at end of file diff --git a/src/audio/OpenAL/SFLAudio.hpp b/src/audio/OpenAL/SFLAudio.hpp new file mode 100644 index 0000000000000000000000000000000000000000..28c1202faf5f37fe0b5c60ca0dc8d608be56bb1b --- /dev/null +++ b/src/audio/OpenAL/SFLAudio.hpp @@ -0,0 +1,26 @@ +/* + * 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 "AudioManager.hpp" +#include "AudioLayer.hpp" +#include "Device.hpp" +#include "Context.hpp" +#include "Source.hpp" + diff --git a/src/audio/OpenAL/Source.hpp b/src/audio/OpenAL/Source.hpp new file mode 100644 index 0000000000000000000000000000000000000000..86ae4b5fd99e2e34c3c371292fca94dceef93b20 --- /dev/null +++ b/src/audio/OpenAL/Source.hpp @@ -0,0 +1,32 @@ +/* + * 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_SOURCE_HPP__ +#define __SFLAUDIO_SOURCE_HPP__ + +namespace SFLAudio +{ + class Source + { + }; +} + +#endif + diff --git a/src/audio/OpenAL/example01.cpp b/src/audio/OpenAL/example01.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db398d86e1952a248873e0f6f723cf834f6cdc4e --- /dev/null +++ b/src/audio/OpenAL/example01.cpp @@ -0,0 +1,44 @@ +/* + * 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 <iostream> +#include <list> +#include <string> + +#include "AudioManager.hpp" +#include "AudioLayer.hpp" + + +int main(int, char* []) +{ + std::list< SFLAudio::AudioLayer * > layers = + SFLAudio::AudioManager::instance().getLayers(); + for(std::list< SFLAudio::AudioLayer *>::iterator it = layers.begin(); + it != layers.end(); + it++) { + std::cout << "Layer: " << (*it)->getName() << std::endl; + std::list< std::string > devices = (*it)->getDevicesNames(); + for(std::list< std::string >::iterator device = devices.begin(); + device != devices.end(); + device++) { + std::cout << " Device: " << *device << std::endl; + } + } +} diff --git a/src/audio/OpenAL/example02.cpp b/src/audio/OpenAL/example02.cpp new file mode 100644 index 0000000000000000000000000000000000000000..49de87c6ae16c51c68294bf631d6805a3c684322 --- /dev/null +++ b/src/audio/OpenAL/example02.cpp @@ -0,0 +1,44 @@ +/* + * 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 <iostream> +#include <list> +#include <string> + +#include "SFLAudio.hpp" + +using namespace SFLAudio; + +int main(int, char* []) +{ + std::list< SFLAudio::AudioLayer * > layers = + SFLAudio::AudioManager::instance().getLayers(); + for(std::list< SFLAudio::AudioLayer *>::iterator it = layers.begin(); + it != layers.end(); + it++) { + std::cout << "Layer: " << (*it)->getName() << std::endl; + + AudioLayer *layer = *it; + Device *device = layer->openDevice(); + std::cout << " Device: " << device->getName() << std::endl; + Context *context = device->createContext(); + Source *source = context->createSource(); + } +}