Skip to content
Snippets Groups Projects
Commit 7bdf5e36 authored by jpbl's avatar jpbl
Browse files

*** empty log message ***

parent de904074
No related branches found
No related tags found
No related merge requests found
Showing
with 1003 additions and 11 deletions
......@@ -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
......
......@@ -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()
{
......
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
/*
* 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();
}
/*
* 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
/*
* 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;
}
/*
* 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
/*
* 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
/*
* 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();
}
/*
* 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
/*
* 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()
{}
/*
* 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
/*
* 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;
}
}
/*
* 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
/*
* 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;
}
/*
* 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
/*
* 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;
}
/*
* 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
/*
* 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();
}
/*
* 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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment