From 7bdf5e36245dd7897caa2cd3cdb00c68f0961f82 Mon Sep 17 00:00:00 2001 From: jpbl <jpbl> Date: Tue, 17 Jan 2006 19:04:14 +0000 Subject: [PATCH] *** empty log message *** --- src/audio/OpenAL/AudioLayer.hpp | 1 + src/audio/OpenAL/AudioManagerImpl.cpp | 6 +- src/audio/OpenAL/Makefile.am | 18 +- src/audio/OpenAL/Null/NullContext.cpp | 28 ++ src/audio/OpenAL/Null/NullContext.hpp | 36 ++ src/audio/OpenAL/Null/NullDevice.cpp | 53 +++ src/audio/OpenAL/Null/NullDevice.hpp | 40 +++ src/audio/OpenAL/Null/NullEmitter.hpp | 41 +++ src/audio/OpenAL/Null/NullLayer.cpp | 54 +++ src/audio/OpenAL/Null/NullLayer.hpp | 41 +++ src/audio/OpenAL/Null/NullSource.cpp | 41 +++ src/audio/OpenAL/Null/NullSource.hpp | 41 +++ src/audio/OpenAL/OpenAL/MicEmitter.cpp | 121 +++++++ src/audio/OpenAL/OpenAL/MicEmitter.hpp | 78 +++++ src/audio/OpenAL/OpenAL/OpenALContext.cpp | 43 +++ src/audio/OpenAL/OpenAL/OpenALContext.hpp | 43 +++ src/audio/OpenAL/OpenAL/OpenALDevice.cpp | 90 +++++ src/audio/OpenAL/OpenAL/OpenALDevice.hpp | 43 +++ src/audio/OpenAL/OpenAL/OpenALLayer.cpp | 143 ++++++++ src/audio/OpenAL/OpenAL/OpenALLayer.hpp | 53 +++ src/audio/OpenAL/OpenAL/OpenALSource.cpp | 320 ++++++++++++++++++ src/audio/OpenAL/OpenAL/OpenALSource.hpp | 83 +++++ src/audio/OpenAL/OpenAL/WavEmitter.cpp | 62 ++++ src/audio/OpenAL/OpenAL/WavEmitter.hpp | 46 +++ src/audio/OpenAL/PortAudio/PortAudioLayer.cpp | 102 ++++++ src/audio/OpenAL/PortAudio/PortAudioLayer.hpp | 53 +++ src/audio/OpenAL/Source.cpp | 4 +- src/audio/OpenAL/example02.cpp | 4 +- src/audio/OpenAL/example03.cpp | 4 +- 29 files changed, 1675 insertions(+), 17 deletions(-) create mode 100644 src/audio/OpenAL/Null/NullContext.cpp create mode 100644 src/audio/OpenAL/Null/NullContext.hpp create mode 100644 src/audio/OpenAL/Null/NullDevice.cpp create mode 100644 src/audio/OpenAL/Null/NullDevice.hpp create mode 100644 src/audio/OpenAL/Null/NullEmitter.hpp create mode 100644 src/audio/OpenAL/Null/NullLayer.cpp create mode 100644 src/audio/OpenAL/Null/NullLayer.hpp create mode 100644 src/audio/OpenAL/Null/NullSource.cpp create mode 100644 src/audio/OpenAL/Null/NullSource.hpp create mode 100644 src/audio/OpenAL/OpenAL/MicEmitter.cpp create mode 100644 src/audio/OpenAL/OpenAL/MicEmitter.hpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALContext.cpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALContext.hpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALDevice.cpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALDevice.hpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALLayer.cpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALLayer.hpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALSource.cpp create mode 100644 src/audio/OpenAL/OpenAL/OpenALSource.hpp create mode 100644 src/audio/OpenAL/OpenAL/WavEmitter.cpp create mode 100644 src/audio/OpenAL/OpenAL/WavEmitter.hpp create mode 100644 src/audio/OpenAL/PortAudio/PortAudioLayer.cpp create mode 100644 src/audio/OpenAL/PortAudio/PortAudioLayer.hpp diff --git a/src/audio/OpenAL/AudioLayer.hpp b/src/audio/OpenAL/AudioLayer.hpp index a9c121f4c5..0c5fe9cf5d 100644 --- a/src/audio/OpenAL/AudioLayer.hpp +++ b/src/audio/OpenAL/AudioLayer.hpp @@ -44,6 +44,7 @@ namespace SFLAudio * on the system. */ virtual std::list< std::string > getDevicesNames() = 0; + virtual std::list< std::string > getCaptureDevicesNames() = 0; /** * Will return the name of the audio system. OpenAL or diff --git a/src/audio/OpenAL/AudioManagerImpl.cpp b/src/audio/OpenAL/AudioManagerImpl.cpp index 15397ea4d2..514dea39df 100644 --- a/src/audio/OpenAL/AudioManagerImpl.cpp +++ b/src/audio/OpenAL/AudioManagerImpl.cpp @@ -19,9 +19,9 @@ */ #include "AudioManagerImpl.hpp" -#include "NullLayer.hpp" -#include "OpenALLayer.hpp" -#include "PortAudioLayer.hpp" +#include "Null/NullLayer.hpp" +#include "OpenAL/OpenALLayer.hpp" +#include "PortAudio/PortAudioLayer.hpp" SFLAudio::AudioManagerImpl::AudioManagerImpl() { diff --git a/src/audio/OpenAL/Makefile.am b/src/audio/OpenAL/Makefile.am index b1e55aec8d..08da8be03a 100644 --- a/src/audio/OpenAL/Makefile.am +++ b/src/audio/OpenAL/Makefile.am @@ -1,5 +1,6 @@ if MAINTENER_CODE -noinst_PROGRAMS = example01 example02 example03 example04 example05 + +noinst_PROGRAMS = example01 example02 example03 example04 example05 example06 noinst_LTLIBRARIES = libsflaudio.la libsflaudio_la_SOURCES = \ @@ -8,12 +9,12 @@ libsflaudio_la_SOURCES = \ Context.cpp Context.hpp \ Device.cpp Device.hpp \ Emitter.cpp Emitter.hpp \ - MicEmitter.cpp MicEmitter.hpp \ - NullLayer.cpp NullLayer.hpp \ - NullContext.cpp NullContext.hpp \ - NullDevice.cpp NullDevice.hpp \ - NullEmitter.hpp \ - NullSource.cpp NullSource.hpp \ + ./Null/NullLayer.cpp ./Null/NullLayer.hpp \ + Null/NullContext.cpp Null/NullContext.hpp \ + Null/NullDevice.cpp Null/NullDevice.hpp \ + Null/NullEmitter.hpp \ + Null/NullSource.cpp Null/NullSource.hpp \ + OpenAL/MicEmitter.cpp OpenAL/MicEmitter.hpp \ OpenALLayer.cpp OpenALLayer.hpp \ OpenALDevice.cpp OpenALDevice.hpp \ OpenALContext.cpp OpenALContext.hpp \ @@ -30,11 +31,12 @@ AM_LDFLAGS = -L$(top_srcdir)/libs/portaudio/ LIBADD = $(PORTAUDIO_LIBS) -lportaudio -lopenal -lalut LDADD = libsflaudio.la $(PORTAUDIO_LIBS) -lopenal -lportaudio -lalut $(libccgnu2_LIBS) - example01_SOURCES = example01.cpp example02_SOURCES = example02.cpp example03_SOURCES = example03.cpp example04_SOURCES = example04.cpp example05_SOURCES = example05.cpp +example06_SOURCES = example06.cpp + endif diff --git a/src/audio/OpenAL/Null/NullContext.cpp b/src/audio/OpenAL/Null/NullContext.cpp new file mode 100644 index 0000000000..07000897d4 --- /dev/null +++ b/src/audio/OpenAL/Null/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 "Null/NullContext.hpp" +#include "Null/NullSource.hpp" + +SFLAudio::Source * +SFLAudio::NullContext::createSource(int, int) +{ + return new NullSource(); +} diff --git a/src/audio/OpenAL/Null/NullContext.hpp b/src/audio/OpenAL/Null/NullContext.hpp new file mode 100644 index 0000000000..a839310579 --- /dev/null +++ b/src/audio/OpenAL/Null/NullContext.hpp @@ -0,0 +1,36 @@ +/* + * 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: + virtual bool isNull() {return true;} + Source *createSource(int format, int freq); + }; +} + +#endif diff --git a/src/audio/OpenAL/Null/NullDevice.cpp b/src/audio/OpenAL/Null/NullDevice.cpp new file mode 100644 index 0000000000..2eccfb4044 --- /dev/null +++ b/src/audio/OpenAL/Null/NullDevice.cpp @@ -0,0 +1,53 @@ +/* + * 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 "Null/NullDevice.hpp" +#include "Null/NullContext.hpp" + +SFLAudio::NullDevice::NullDevice() + : Device("Null/NullDevice") +{ + currentContext(createContext()); +} + +SFLAudio::Context * +SFLAudio::NullDevice::createContext() +{ + return new NullContext(); +} + + +bool +SFLAudio::NullDevice::load() +{ + return true; +} + +void +SFLAudio::NullDevice::unload() +{} + +bool +SFLAudio::NullDevice::isNull() +{ + return true; +} diff --git a/src/audio/OpenAL/Null/NullDevice.hpp b/src/audio/OpenAL/Null/NullDevice.hpp new file mode 100644 index 0000000000..43387038ed --- /dev/null +++ b/src/audio/OpenAL/Null/NullDevice.hpp @@ -0,0 +1,40 @@ +/* + * 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(); + virtual void unload(); + bool isNull(); + }; +} + +#endif diff --git a/src/audio/OpenAL/Null/NullEmitter.hpp b/src/audio/OpenAL/Null/NullEmitter.hpp new file mode 100644 index 0000000000..bd685121ab --- /dev/null +++ b/src/audio/OpenAL/Null/NullEmitter.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_NULL_EMITTER_HPP__ +#define __SFLAUDIO_NULL_EMITTER_HPP__ + +#include "Emitter.hpp" + +namespace SFLAudio +{ + class Context; + class Source; + + class NullEmitter : public Emitter + { + public: + virtual bool isNull() {return true;} + virtual void play() {} + }; + +} + +#endif + diff --git a/src/audio/OpenAL/Null/NullLayer.cpp b/src/audio/OpenAL/Null/NullLayer.cpp new file mode 100644 index 0000000000..5e3e4c07f6 --- /dev/null +++ b/src/audio/OpenAL/Null/NullLayer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "Null/NullLayer.hpp" +#include "Null/NullDevice.hpp" +#include "Null/NullEmitter.hpp" + +SFLAudio::NullLayer::NullLayer() + : AudioLayer("Null/NullLayer") +{} + +std::list< std::string > +SFLAudio::NullLayer::getDevicesNames() +{return std::list< std::string >();} + +std::list< std::string > +SFLAudio::NullLayer::getCaptureDevicesNames() +{return std::list< std::string >();} + +SFLAudio::Device * +SFLAudio::NullLayer::openDevice() +{ + return new NullDevice(); +} + +SFLAudio::Emitter * +SFLAudio::NullLayer::openCaptureDevice() +{ + return new NullEmitter(); +} + +SFLAudio::Device * +SFLAudio::NullLayer::openDevice(const std::string &) +{ + return new NullDevice(); +} + diff --git a/src/audio/OpenAL/Null/NullLayer.hpp b/src/audio/OpenAL/Null/NullLayer.hpp new file mode 100644 index 0000000000..4d02b8f5ad --- /dev/null +++ b/src/audio/OpenAL/Null/NullLayer.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_NULL_LAYER_HPP__ +#define __SFLAUDIO_NULL_LAYER_HPP__ + +#include "AudioLayer.hpp" + +namespace SFLAudio +{ + class NullLayer : public AudioLayer + { + public: + NullLayer(); + std::list< std::string > getDevicesNames(); + std::list< std::string > getCaptureDevicesNames(); + virtual Device *openDevice(); + virtual Emitter *openCaptureDevice(); + virtual Device *openDevice(const std::string &name); + }; +} + +#endif + diff --git a/src/audio/OpenAL/Null/NullSource.cpp b/src/audio/OpenAL/Null/NullSource.cpp new file mode 100644 index 0000000000..a4aa3d6c95 --- /dev/null +++ b/src/audio/OpenAL/Null/NullSource.cpp @@ -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. + */ + +#include "Null/NullSource.hpp" + +SFLAudio::NullSource::NullSource() + : Source(0, 0) +{} + +bool +SFLAudio::NullSource::isPlaying() +{return true;} + +void +SFLAudio::NullSource::play(void *, int) +{} + +void +SFLAudio::NullSource::stream(void *, int) +{} + +void +SFLAudio::NullSource::stop() +{} diff --git a/src/audio/OpenAL/Null/NullSource.hpp b/src/audio/OpenAL/Null/NullSource.hpp new file mode 100644 index 0000000000..5d6c2ecfcd --- /dev/null +++ b/src/audio/OpenAL/Null/NullSource.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_NULL_SOURCE_HPP__ +#define __SFLAUDIO_NULL_SOURCE_HPP__ + +#include "Source.hpp" + +namespace SFLAudio +{ + class NullSource : public Source + { + public: + NullSource(); + + virtual bool isNull() {return true;}; + virtual bool isPlaying(); + virtual void stream(void *data, int size); + virtual void play(void *data, int size); + virtual void stop(); + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenAL/MicEmitter.cpp b/src/audio/OpenAL/OpenAL/MicEmitter.cpp new file mode 100644 index 0000000000..f09848f484 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/MicEmitter.cpp @@ -0,0 +1,121 @@ +/* + * 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/alut.h> +#include <AL/alut.h> +#include <iostream> + +#include "OpenAL/OpenALLayer.hpp" +#include "MicEmitter.hpp" +#include "Source.hpp" + +SFLAudio::MicEmitter::MicEmitter(int format, int freq, int size, + PFNALCAPTURESTARTPROC palCaptureStart, + PFNALCAPTURESTOPPROC palCaptureStop, + PFNALCAPTUREGETDATAPROC palCaptureGetData) + : Emitter(format, freq) + , mSize(size) + , mAlCaptureStart(palCaptureStart) + , mAlCaptureStop(palCaptureStop) + , mAlCaptureGetData(palCaptureGetData) + , mThread(0) +{} + +void +SFLAudio::MicEmitter::play() +{ + if(mThread == 0) { + mAlCaptureStart(); + + mThread = new MicEmitterThread(getFormat(), getFrequency(), mSize, mAlCaptureGetData); + mThread->setSource(getSource()); + mThread->start(); + } +} + +void +SFLAudio::MicEmitter::stop() +{ + if(mThread != 0) { + delete mThread; + mThread = 0; + } +} + + +SFLAudio::MicEmitterThread::MicEmitterThread(int format, + int freq, + int size, + PFNALCAPTUREGETDATAPROC palCaptureGetData) + : mSource(0) + , mFormat(format) + , mFreq(freq) + , mSize(size) + , mAlCaptureGetData(palCaptureGetData) +{ + setCancel(cancelDeferred); + mData = (ALchar *)malloc(mSize); +} + +SFLAudio::MicEmitterThread::~MicEmitterThread() +{ + terminate(); + free(mData); +} + +void +SFLAudio::MicEmitterThread::setSource(SFLAudio::Source *source) { + mSource = source; +} + +void +SFLAudio::MicEmitterThread::fill() { + ALsizei retval = 0; + std::cout << "filling capture buffer...\n"; + while(retval < mSize) { + int size = mAlCaptureGetData(&mData[retval], + mSize - retval, + mFormat, + mFreq); + retval += size; + if(size != 0) + std::cout << "read " << size << + " bytes from capture, for a total of " << retval << std::endl; + } + std::cout << "capture buffer filled!\n"; +} + +void +SFLAudio::MicEmitterThread::run() +{ + while (!testCancel()) { + if(mData) { + fill(); + } + + if(mSource && mData) { + mSource->stream(mData, mSize); + } + else { + std::cerr << "source or buffer invalid.\n"; + } + std::cout << "done." << std::endl; + } +} diff --git a/src/audio/OpenAL/OpenAL/MicEmitter.hpp b/src/audio/OpenAL/OpenAL/MicEmitter.hpp new file mode 100644 index 0000000000..719686fe84 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/MicEmitter.hpp @@ -0,0 +1,78 @@ +/* + * 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_MIC_EMITTER_HPP__ +#define __SFLAUDIO_MIC_EMITTER_HPP__ + +#include <AL/al.h> +#include <cc++/thread.h> +#include "Emitter.hpp" + + +namespace SFLAudio +{ + class Source; + + class MicEmitterThread : public ost::Thread + { + public: + MicEmitterThread(int format, int freq, int size, PFNALCAPTUREGETDATAPROC palCaptureGetData); + ~MicEmitterThread(); + + void setSource(SFLAudio::Source *source); + virtual void run(); + void fill(); + + private: + SFLAudio::Source *mSource; + ALchar *mData; + ALsizei mFormat; + ALsizei mFreq; + ALsizei mSize; + + PFNALCAPTUREGETDATAPROC mAlCaptureGetData; + }; + + class MicEmitter : public Emitter + { + private: + MicEmitter(); + + public: + MicEmitter(int format, int freq, int size, + PFNALCAPTURESTARTPROC palCaptureStart, + PFNALCAPTURESTOPPROC palCaptureStop, + PFNALCAPTUREGETDATAPROC palCaptureGetData); + virtual void play(); + virtual void stop(); + + + private: + ALsizei mSize; + PFNALCAPTURESTARTPROC mAlCaptureStart; + PFNALCAPTURESTOPPROC mAlCaptureStop; + PFNALCAPTUREGETDATAPROC mAlCaptureGetData; + + MicEmitterThread* mThread; + }; + +} + +#endif diff --git a/src/audio/OpenAL/OpenAL/OpenALContext.cpp b/src/audio/OpenAL/OpenAL/OpenALContext.cpp new file mode 100644 index 0000000000..13795f1860 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALContext.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 <iostream> + +#include "OpenAL/OpenALContext.hpp" +#include "OpenAL/OpenALSource.hpp" +#include "Null/NullSource.hpp" + +SFLAudio::OpenALContext::OpenALContext(ALCcontext *context) + : mContext(context) +{} + +SFLAudio::Source * +SFLAudio::OpenALContext::createSource(int format, int freq) +{ + Source *source = 0; + if(mContext == 0) { + source = new NullSource(); + } + else { + source = OpenALSource::create(this, format, freq); + } + + return source; +} diff --git a/src/audio/OpenAL/OpenAL/OpenALContext.hpp b/src/audio/OpenAL/OpenAL/OpenALContext.hpp new file mode 100644 index 0000000000..d287bccaf8 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALContext.hpp @@ -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. + */ + +#ifndef __SFLAUDIO_OPENAL_CONTEXT_HPP__ +#define __SFLAUDIO_OPENAL_CONTEXT_HPP__ + +#include "Context.hpp" +#include "AL/alc.h" + +namespace SFLAudio +{ + class OpenALContext : public Context + { + private: + OpenALContext(); + + public: + OpenALContext(ALCcontext *context); + Source *createSource(int format, int freq); + + private: + ALCcontext *mContext; + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenAL/OpenALDevice.cpp b/src/audio/OpenAL/OpenAL/OpenALDevice.cpp new file mode 100644 index 0000000000..a0437bf170 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALDevice.cpp @@ -0,0 +1,90 @@ +/* + * 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 <AL/al.h> +#include <AL/alc.h> + + +#include "OpenAL/OpenALDevice.hpp" +#include "OpenAL/OpenALContext.hpp" +#include "OpenAL/OpenALLayer.hpp" +#include "Null/NullContext.hpp" +#include "Null/NullDevice.hpp" + +SFLAudio::OpenALDevice::OpenALDevice() + : mDevice(0) +{} + +SFLAudio::OpenALDevice::~OpenALDevice() +{ + unload(); +} + +void +SFLAudio::OpenALDevice::unload() { + if(mDevice) { + if(alcCloseDevice(mDevice) == ALC_FALSE) { + ALenum error = alcGetError(mDevice); + std::cerr << "OpenAL/OpenAL::alcCloseDevice: " << alGetString(error) << std::endl; + } + mDevice = 0; + } +} + + +bool +SFLAudio::OpenALDevice::load() { + ALCcontext *context = alcGetCurrentContext(); + mDevice = alcGetContextsDevice(context); + if(mDevice != 0) { + const ALCchar *device = alcGetString(mDevice, ALC_DEVICE_SPECIFIER); + setName(device); + } + + return mDevice; +} + + +SFLAudio::Context * +SFLAudio::OpenALDevice::createContext() +{ + SFLAudio::Context *context = NULL; + if (mDevice) { + ALCcontext *c = alcCreateContext(mDevice, NULL); + alcMakeContextCurrent(c); + if(c == NULL) { + ALenum error = alcGetError(mDevice); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL::alcCreateContext: " << alGetString(error) << std::endl; + } + context = new NullContext(); + } + else { + alcMakeContextCurrent(c); + context = new OpenALContext(c); + } + } + else { + context = new NullContext(); + } + + return context; +} diff --git a/src/audio/OpenAL/OpenAL/OpenALDevice.hpp b/src/audio/OpenAL/OpenAL/OpenALDevice.hpp new file mode 100644 index 0000000000..1e9d1321ba --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALDevice.hpp @@ -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. + */ + +#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(); + ~OpenALDevice(); + virtual bool load(); + virtual void unload(); + virtual Context *createContext(); + + private: + ALCdevice *mDevice; + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenAL/OpenALLayer.cpp b/src/audio/OpenAL/OpenAL/OpenALLayer.cpp new file mode 100644 index 0000000000..ecd07628fc --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALLayer.cpp @@ -0,0 +1,143 @@ +/* + * 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 "OpenAL/OpenALLayer.hpp" +#include "OpenAL/OpenALDevice.hpp" +#include "MicEmitter.hpp" +#include "Null/NullDevice.hpp" +#include "Null/NullEmitter.hpp" + +#include <iostream> +#include <AL/al.h> +#include <AL/alc.h> +#include <AL/alext.h> +#include <AL/alut.h> + +#define DEFAULT_DEVICE_NAME "default" +#define DEFAULT_CAPTURE_DEVICE_NAME "default" + +#define MIC_FORMAT AL_FORMAT_MONO16 +#define FREQ 8192 +#define SAMPLES (1 * FREQ) +#define SIZE (SAMPLES * 2) + +#define GP(type,var,name) \ + var = (type)alGetProcAddress((const ALchar*) name); \ + if( var == NULL ) { \ + fprintf( stderr, "Could not get %s extension entry\n", name ); \ + } + + + +SFLAudio::OpenALLayer::OpenALLayer() + : AudioLayer("openal") +{ + alutInit(0, 0); + GP( PFNALCAPTUREINITPROC, palCaptureInit, "alCaptureInit_EXT" ); + GP( PFNALCAPTUREDESTROYPROC, palCaptureDestroy, + "alCaptureDestroy_EXT" ); + GP( PFNALCAPTURESTARTPROC, palCaptureStart, "alCaptureStart_EXT" ); + GP( PFNALCAPTURESTOPPROC, palCaptureStop, "alCaptureStop_EXT" ); + GP( PFNALCAPTUREGETDATAPROC, palCaptureGetData, + "alCaptureGetData_EXT" ); +} + + +SFLAudio::Emitter * +SFLAudio::OpenALLayer::openCaptureDevice() +{ + if(palCaptureInit == 0 || + !palCaptureInit( MIC_FORMAT, FREQ, 1024 ) ) { + printf( "Unable to initialize capture\n" ); + return new NullEmitter(); + } + + return new MicEmitter(MIC_FORMAT, FREQ, SIZE, + palCaptureStart, + palCaptureStop, + palCaptureGetData); +} + + +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); + } + } + else { + devices.push_back(alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER)); + } + + + return devices; + +} + +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(alcGetString(NULL, ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER)); + } + + + return devices; + +} + + +SFLAudio::Device * +SFLAudio::OpenALLayer::openDevice() +{ + Device *dev = new OpenALDevice(); + if(dev->load()) { + dev->setName(DEFAULT_DEVICE_NAME); + } + else { + delete dev; + dev = new NullDevice(); + } + + return dev; +} + +SFLAudio::Device * +SFLAudio::OpenALLayer::openDevice(const std::string &) +{ + return openDevice(); +} + + diff --git a/src/audio/OpenAL/OpenAL/OpenALLayer.hpp b/src/audio/OpenAL/OpenAL/OpenALLayer.hpp new file mode 100644 index 0000000000..0e2888c893 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALLayer.hpp @@ -0,0 +1,53 @@ +/* + * 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 <AL/alext.h> +#include "AudioLayer.hpp" + +namespace SFLAudio +{ + + class OpenALLayer : public AudioLayer + { + public: + OpenALLayer(); + + virtual std::list< std::string > getDevicesNames(); + virtual std::list< std::string > getCaptureDevicesNames(); + virtual Emitter *openCaptureDevice(); + virtual Device *openDevice(); + virtual Device *openDevice(const std::string &name); + + private: + PFNALCAPTUREINITPROC palCaptureInit; + PFNALCAPTUREDESTROYPROC palCaptureDestroy; + PFNALCAPTURESTARTPROC palCaptureStart; + PFNALCAPTURESTOPPROC palCaptureStop; + PFNALCAPTUREGETDATAPROC palCaptureGetData; + + }; +} + +#endif + + diff --git a/src/audio/OpenAL/OpenAL/OpenALSource.cpp b/src/audio/OpenAL/OpenAL/OpenALSource.cpp new file mode 100644 index 0000000000..b551cc747b --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALSource.cpp @@ -0,0 +1,320 @@ +/* + * 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 <AL/alut.h> +#include <iostream> +#include <unistd.h> + +#include "Context.hpp" +#include "Null/NullSource.hpp" +#include "OpenAL/OpenALSource.hpp" + +SFLAudio::OpenALSource::OpenALSource(int format, int freq, ALuint buffer, ALuint source) + : Source(format, freq) + , mBuffer(buffer) + , mSource(source) + , mIsAttached(false) + , mIsStatic(true) +{ + mBuffers.push_back(buffer); +} + +SFLAudio::OpenALSource::~OpenALSource() +{ + alGetError(); + + alDeleteSources(1, &mSource); + ALenum error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alDeleteSources : " << alGetString(error) << std::endl; + } + + for(std::list< ALuint >::iterator pos = mBuffers.begin(); + pos != mBuffers.end(); + pos++) { + alDeleteBuffers(1, &(*pos)); + error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alDeleteBuffers : " << alGetString(error) << std::endl; + } + } +} + + +bool +SFLAudio::OpenALSource::genBuffer(ALuint &buffer) { + // Generate buffer + alGetError(); // clear error code + alGenBuffers(1, &buffer); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alGenBuffers : " << alGetString(error) << std::endl;; + return false; + } + + return true; +} + +bool +SFLAudio::OpenALSource::genSource(ALuint &source) { + // Generate buffer + alGetError(); // clear error code + alGenSources(1, &source); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alGenSources : " << alGetString(error) << std::endl;; + return false; + } + + alSource3f(source, AL_POSITION, 0.0, 0.0, 0.0); + alSource3f(source, AL_VELOCITY, 0.0, 0.0, 0.0); + alSource3f(source, AL_DIRECTION, 0.0, 0.0, 0.0); + alSourcef (source, AL_ROLLOFF_FACTOR, 0.0); + alSourcei (source, AL_SOURCE_RELATIVE, AL_TRUE); + + return true; +} + +bool +SFLAudio::OpenALSource::deleteSource(ALuint &source) { + // Generate buffer + alGetError(); // clear error code + alDeleteSources(1, &source); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alDeleteSources : " << alGetString(error) << std::endl;; + return false; + } + + return true; +} + +bool +SFLAudio::OpenALSource::deleteBuffer(ALuint &buffer) { + // Generate buffer + alGetError(); // clear error code + alDeleteBuffers(1, &buffer); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alDeleteBuffers : " << alGetString(error) << std::endl;; + return false; + } + + return true; +} + +bool +SFLAudio::OpenALSource::detach() +{ + alSourcei(mSource, AL_BUFFER, 0); + ALenum error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alSourcei : " << alGetString(error); + return false; + } + + mIsAttached = false; + + return true; +} + +ALuint +SFLAudio::OpenALSource::getSourceState() +{ +// ALint answer; +// alGetError(); + +// alGetSourcei(mSource, AL_SOURCE_TYPE, &answer); +// ALenum error = alGetError(); +// if(error != AL_NO_ERROR) { +// std::cerr << "OpenAL/OpenAL: alGetSourcei(state) : " << alGetString(error); +// return AL_UNDETERMINED; +// } + +// return answer; + + if(!mIsAttached) { + return AL_UNDETERMINED; + } + + if(mIsStatic) { + return AL_STATIC; + } + + return AL_STREAMING; +} + +bool +SFLAudio::OpenALSource::isStatic() +{ + return (getSourceState() == AL_STATIC); +} + +bool +SFLAudio::OpenALSource::isUndetermined() +{ + return (getSourceState() == AL_UNDETERMINED); +} + +bool +SFLAudio::OpenALSource::isStreaming() +{ + return (getSourceState() == AL_STREAMING); +} + +bool +SFLAudio::OpenALSource::isAttached() +{ + return (getSourceState() != AL_UNDETERMINED); +} + +bool check(const char *message) { + ALenum error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << message << alGetString(error); + return false; + } + + return true; +} + +bool +SFLAudio::OpenALSource::attach() +{ + if(isAttached()) { + if(isStatic() == true) { + // it's already attached as static + return true; + } + + detach(); + } + + // Attach buffer to source + alSourcei(mSource, AL_BUFFER, mBuffer); + ALenum error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alSourcei : " << alGetString(error); + return false; + } + + mIsAttached = true; + mIsStatic = true; + + return true; +} + +SFLAudio::Source * +SFLAudio::OpenALSource::create(OpenALContext *, int format, int freq) { + ALuint buffer; + ALuint source; + + // Generate buffer + if(!genBuffer(buffer)){ + deleteBuffer(buffer); + return new NullSource(); + } + + // Generate source + if(!genSource(source)){ + deleteBuffer(buffer); + deleteSource(source); + return new NullSource(); + } + + return new OpenALSource(format, freq, buffer, source); +} + + +bool +SFLAudio::OpenALSource::isPlaying() +{ + ALint state; + if(alIsSource(mSource) == AL_FALSE) { + return false; + } + + alGetSourcei(mSource, AL_SOURCE_STATE, &state); + + return (state == AL_PLAYING); +} + +void +SFLAudio::OpenALSource::stream(void *data, int size) +{ + int processed; + ALuint buffer; + + alGetSourcei(mSource, AL_BUFFERS_PROCESSED, &processed); + + if(processed == 0) { + if(genBuffer(buffer) == false) { + return; + } + + // Attach streaming buffer to source + alSourceQueueBuffers(mSource, 1, &buffer); + ALenum error = alGetError(); + if(error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alSourceQueueBuffers : " << alGetString(error); + return; + } + mBuffers.push_back(buffer); + + mIsAttached = true; + mIsStatic = false; + + } + else { + alSourceUnqueueBuffers(mSource, 1, &buffer); + } + + alBufferData(buffer, getFormat(), data, size, getFrequency()); + alSourceQueueBuffers(mSource, 1, &buffer); + + if(!isPlaying()) { + alSourcePlay(mSource); + } +} + +void +SFLAudio::OpenALSource::play(void *data, int size) +{ + attach(); + + alGetError(); + + // Copy data into AL Buffer + alBufferData(mBuffer, getFormat(), data, size, getFrequency()); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: alBufferData : " << alGetString(error); + } + + alSourcePlay(mSource); +} + +void +SFLAudio::OpenALSource::stop() +{ + alSourceStop(mSource); +} diff --git a/src/audio/OpenAL/OpenAL/OpenALSource.hpp b/src/audio/OpenAL/OpenAL/OpenALSource.hpp new file mode 100644 index 0000000000..42b92b05cb --- /dev/null +++ b/src/audio/OpenAL/OpenAL/OpenALSource.hpp @@ -0,0 +1,83 @@ +/* + * 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_SOURCE_HPP__ +#define __SFLAUDIO_OPENAL_SOURCE_HPP__ + +#include <list> + +#include <AL/al.h> +#include <AL/alc.h> +#include "Source.hpp" + +namespace SFLAudio +{ + class OpenALContext; + + class OpenALSource : public Source + { + private: + OpenALSource(); + + public: + OpenALSource(int format, int freq, ALuint buffer, ALuint source); + ~OpenALSource(); + + static Source *create(OpenALContext *context, int format, int freq); + + // Source functions + virtual bool isPlaying(); + virtual void play(void *data, int size); + virtual void stream(void *data, int size); + virtual void stop(); + + private: + ALuint getSourceState(); + bool isStatic(); + bool isAttached(); + bool isStreaming(); + bool isUndetermined(); + bool attach(); + bool detach(); + + bool check(const char *message); + + static bool genBuffer(ALuint &buffer); + static bool genSource(ALuint &source); + static bool deleteBuffer(ALuint &buffer); + static bool deleteSource(ALuint &source); + + + private: + // Buffers that we'll eventually need to delete + std::list< ALuint > mBuffers; + + // Buffers to hold sound data. + ALuint mBuffer; + + // Sources are points of emitting sound. + ALuint mSource; + + bool mIsAttached; + bool mIsStatic; + }; +} + +#endif diff --git a/src/audio/OpenAL/OpenAL/WavEmitter.cpp b/src/audio/OpenAL/OpenAL/WavEmitter.cpp new file mode 100644 index 0000000000..eb7a98f986 --- /dev/null +++ b/src/audio/OpenAL/OpenAL/WavEmitter.cpp @@ -0,0 +1,62 @@ +/* + * 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/alut.h> +#include <iostream> + +#include "WavEmitter.hpp" +#include "Source.hpp" + +SFLAudio::WavEmitter::WavEmitter(char *filename) + : mData(0) + , mSize(0) +{ + ALenum format; + ALsizei freq; + ALboolean loop; + + // Load test.wav + alutLoadWAVFile(filename, &format,&mData,&mSize,&freq,&loop); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: loadWAVFile : " << alGetString(error); + mData = 0; + } + else { + setFrequency(freq); + setFormat(format); + } +} + +void +SFLAudio::WavEmitter::play() +{ + Source *source = getSource(); + if(source && mData) { + source->play(mData, mSize); + + // Unload test.wav + alutUnloadWAV(getFormat(), mData, mSize, getFrequency()); + ALenum error = alGetError(); + if (error != AL_NO_ERROR) { + std::cerr << "OpenAL/OpenAL: unloadWAV : " << alGetString(error); + } + } +} diff --git a/src/audio/OpenAL/OpenAL/WavEmitter.hpp b/src/audio/OpenAL/OpenAL/WavEmitter.hpp new file mode 100644 index 0000000000..34af517b0e --- /dev/null +++ b/src/audio/OpenAL/OpenAL/WavEmitter.hpp @@ -0,0 +1,46 @@ +/* + * 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_WAV_EMITTER_HPP__ +#define __SFLAUDIO_WAV_EMITTER_HPP__ + +#include <AL/al.h> +#include "Emitter.hpp" + +namespace SFLAudio +{ + class Source; + + class WavEmitter : public Emitter + { + private: + WavEmitter(); + + public: + WavEmitter(char *filename); + void play(); + + private: + ALvoid *mData; + ALsizei mSize; + }; +} + +#endif diff --git a/src/audio/OpenAL/PortAudio/PortAudioLayer.cpp b/src/audio/OpenAL/PortAudio/PortAudioLayer.cpp new file mode 100644 index 0000000000..3a9c7315b6 --- /dev/null +++ b/src/audio/OpenAL/PortAudio/PortAudioLayer.cpp @@ -0,0 +1,102 @@ +/* + * 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 "PortAudio/PortAudioLayer.hpp" +#include "portaudio.h" + +#include "Null/NullDevice.hpp" +#include "Null/NullEmitter.hpp" + + +SFLAudio::PortAudioLayer::PortAudioLayer() + : AudioLayer("portaudio") +{ + Pa_Initialize(); +} + +SFLAudio::PortAudioLayer::~PortAudioLayer() +{ + Pa_Terminate(); +} + + + +std::list< std::string > +SFLAudio::PortAudioLayer::getDevicesNames() +{ + refreshDevices(); + + std::list< std::string > devices; + for(DevicesType::iterator pos = mDevices.begin(); + pos != mDevices.end(); + pos++) { + devices.push_back(pos->first); + } + + return devices; +} + + +std::list< std::string > +SFLAudio::PortAudioLayer::getCaptureDevicesNames() +{ + return std::list< std::string >(); +} + + +void +SFLAudio::PortAudioLayer::refreshDevices() +{ + mDevices.clear(); + for(int index = 0; index < Pa_GetDeviceCount(); index++ ) { + const PaDeviceInfo *device = NULL; + const PaHostApiInfo *host = NULL; + + device = Pa_GetDeviceInfo(index); + if(device != NULL) { + host = Pa_GetHostApiInfo(device->hostApi); + } + + if(device != NULL && host != NULL) { + std::string name(host->name); + name += ": "; + name += device->name; + mDevices.insert(std::make_pair(name, index)); + } + } +} + +SFLAudio::Device * +SFLAudio::PortAudioLayer::openDevice() +{ + return new NullDevice(); +} + +SFLAudio::Emitter * +SFLAudio::PortAudioLayer::openCaptureDevice() +{ + return new NullEmitter(); +} + +SFLAudio::Device * +SFLAudio::PortAudioLayer::openDevice(const std::string &) +{ + return new NullDevice(); +} diff --git a/src/audio/OpenAL/PortAudio/PortAudioLayer.hpp b/src/audio/OpenAL/PortAudio/PortAudioLayer.hpp new file mode 100644 index 0000000000..9db73d523e --- /dev/null +++ b/src/audio/OpenAL/PortAudio/PortAudioLayer.hpp @@ -0,0 +1,53 @@ +/* + * 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 std::list< std::string > getCaptureDevicesNames(); + virtual Device *openDevice(); + virtual Emitter *openCaptureDevice(); + virtual Device *openDevice(const std::string &name); + + private: + virtual void refreshDevices(); + + private: + typedef std::map< std::string, int > DevicesType; + DevicesType mDevices; + }; +} + +#endif + + diff --git a/src/audio/OpenAL/Source.cpp b/src/audio/OpenAL/Source.cpp index dd2e40003d..ff35229517 100644 --- a/src/audio/OpenAL/Source.cpp +++ b/src/audio/OpenAL/Source.cpp @@ -25,8 +25,8 @@ #include <unistd.h> #include "Context.hpp" -#include "NullSource.hpp" -#include "OpenALSource.hpp" +#include "Null/NullSource.hpp" +#include "OpenAL/OpenALSource.hpp" SFLAudio::Source::Source(int format, int freq) : mFormat(format) diff --git a/src/audio/OpenAL/example02.cpp b/src/audio/OpenAL/example02.cpp index 785eda71cc..f0370cef62 100644 --- a/src/audio/OpenAL/example02.cpp +++ b/src/audio/OpenAL/example02.cpp @@ -46,7 +46,7 @@ int main(int, char* []) alutLoadWAVFile("test.wav",&format,&data,&size,&freq,&loop); ALenum error = alGetError(); if (error != AL_NO_ERROR) { - std::cerr << "OpenAL: loadWAVFile : " << alGetString(error); + std::cerr << "OpenAL/OpenAL: loadWAVFile : " << alGetString(error); return 1; } @@ -59,7 +59,7 @@ int main(int, char* []) error = alGetError(); if (error != AL_NO_ERROR) { - std::cerr << "OpenAL: unloadWAV : " << alGetString(error); + std::cerr << "OpenAL/OpenAL: unloadWAV : " << alGetString(error); } diff --git a/src/audio/OpenAL/example03.cpp b/src/audio/OpenAL/example03.cpp index edfd40298d..c0c60cf2bf 100644 --- a/src/audio/OpenAL/example03.cpp +++ b/src/audio/OpenAL/example03.cpp @@ -61,7 +61,7 @@ int main(int argc, char* argv[]) &infos[i].loop); error = alGetError(); if (error != AL_NO_ERROR) { - std::cerr << "OpenAL: loadWAVFile : " << alGetString(error); + std::cerr << "OpenAL/OpenAL: loadWAVFile : " << alGetString(error); return 1; } } @@ -80,7 +80,7 @@ int main(int argc, char* argv[]) infos[i].freq); error = alGetError(); if (error != AL_NO_ERROR) { - std::cerr << "OpenAL: unloadWAV : " << alGetString(error); + std::cerr << "OpenAL/OpenAL: unloadWAV : " << alGetString(error); } } -- GitLab