Commit 0e576348 authored by jpbl's avatar jpbl

added the Emitter functionnality

parent 6c9863ab
......@@ -19,5 +19,11 @@
*/
#include "Context.hpp"
#include "NullSource.hpp"
#include "Emitter.hpp"
SFLAudio::Source *
SFLAudio::Context::createSource(SFLAudio::Emitter *emitter)
{
Source *source = createSource(emitter->getFormat(), emitter->getFrequency());
emitter->connect(source);
}
......@@ -23,6 +23,7 @@
namespace SFLAudio
{
class Emitter;
class Source;
class Context
......@@ -34,6 +35,7 @@ namespace SFLAudio
* Create a source for the context.
*/
virtual Source *createSource(int format, int freq) = 0;
Source *createSource(Emitter *emitter);
};
}
......
/*
* 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 "Emitter.hpp"
SFLAudio::Emitter::Emitter()
: mSource(0)
, mFormat(0)
, mFreq(0)
{}
SFLAudio::Emitter::Emitter(int format, int freq)
: mSource(0)
, mFormat(format)
, mFreq(freq)
{}
int
SFLAudio::Emitter::getFrequency()
{return mFreq;}
int
SFLAudio::Emitter::getFormat()
{return mFormat;}
void
SFLAudio::Emitter::setFrequency(int freq)
{mFreq = freq;}
void
SFLAudio::Emitter::setFormat(int format)
{mFormat = format;}
void
SFLAudio::Emitter::connect(Source *source)
{mSource = source;}
void
SFLAudio::Emitter::connect(Context *context)
{mSource = context->createSource(this);}
SFLAudio::Source *
SFLAudio::Emitter::getSource()
{return mSource;}
/*
* 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_EMITTER_HPP__
#define __SFLAUDIO_EMITTER_HPP__
namespace SFLAudio
{
class Context;
class Source;
class Emitter
{
public:
Emitter();
Emitter(int format, int freq);
int getFrequency();
int getFormat();
void setFrequency(int freq);
void setFormat(int format);
void connect(Source *source);
void connect(Context *context);
Source *getSource();
private:
Source *mSource;
int mFormat;
int mFreq;
};
}
#endif
if MAINTENER_CODE
noinst_PROGRAMS = example01 example02 example03
noinst_PROGRAMS = example01 example02 example03 example04
noinst_LTLIBRARIES = libsflaudio.la
libsflaudio_la_SOURCES = \
AudioLayer.cpp AudioLayer.hpp \
AudioManagerImpl.cpp AudioManagerImpl.hpp \
Context.hpp \
Context.cpp Context.hpp \
Device.cpp Device.hpp \
Emitter.cpp Emitter.hpp \
NullLayer.cpp NullLayer.hpp \
NullDevice.cpp NullDevice.hpp \
NullContext.cpp NullContext.hpp \
......@@ -17,7 +18,8 @@ libsflaudio_la_SOURCES = \
OpenALSource.cpp OpenALSource.hpp \
PortAudioLayer.cpp PortAudioLayer.hpp \
SFLAudio.hpp \
Source.cpp Source.hpp
Source.cpp Source.hpp \
WavEmitter.cpp WavEmitter.hpp
AM_CPPFLAGS = $(PORTAUDIO_CFLAGS) -I$(top_srcdir)/libs/portaudio/pa_common -I$(top_srcdir)/libs/
AM_CXXFLAGS = $(PORTAUDIO_CXXFLAGS) -I$(top_srcdir)/libs/
......@@ -30,5 +32,6 @@ LDADD = libsflaudio.la $(PORTAUDIO_LIBS) -lopenal -lportaudio
example01_SOURCES = example01.cpp
example02_SOURCES = example02.cpp
example03_SOURCES = example03.cpp
example04_SOURCES = example04.cpp
endif
......@@ -41,7 +41,10 @@ SFLAudio::OpenALDevice::~OpenALDevice()
void
SFLAudio::OpenALDevice::unload() {
if(mDevice) {
alcCloseDevice(mDevice);
if(alcCloseDevice(mDevice) == ALC_FALSE) {
ALenum error = alcGetError(mDevice);
std::cerr << "OpenAL::alcCloseDevice: " << alGetString(error) << std::endl;
}
mDevice = 0;
}
}
......
......@@ -27,6 +27,7 @@
#include <AL/alc.h>
#define DEFAULT_DEVICE_NAME "default"
#define DEFAULT_CAPTURE_DEVICE_NAME "default"
SFLAudio::OpenALLayer::OpenALLayer()
: AudioLayer("openal")
......@@ -53,6 +54,28 @@ SFLAudio::OpenALLayer::getDevicesNames()
}
std::list< std::string >
SFLAudio::OpenALLayer::getCaptureDevicesNames()
{
std::list< std::string > devices;
if (alcIsExtensionPresent(NULL, "ALC_ENUMERATION_EXT") == AL_TRUE) {
const ALCchar *devs = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER);
const ALCchar *devname = devs;
while(devname) {
devices.push_back(devname);
devname += sizeof(ALCchar) * (strlen(devname) + 1);
}
}
else {
devices.push_back(DEFAULT_CAPTURE_DEVICE_NAME);
}
return devices;
}
SFLAudio::Device *
SFLAudio::OpenALLayer::openDevice()
{
......
......@@ -31,6 +31,7 @@ namespace SFLAudio
OpenALLayer();
virtual std::list< std::string > getDevicesNames();
virtual std::list< std::string > getCaptureDevicesNames();
virtual Device *openDevice();
virtual Device *openDevice(const std::string &name);
};
......
/*
* 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: 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: unloadWAV : " << alGetString(error);
}
}
}
/*
* 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
/*
* 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"
#include "WavEmitter.hpp"
using namespace SFLAudio;
int main(int, char* [])
{
AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer();
Device *device = layer->openDevice();
Context *context = device->createContext();
// Load test.wav
SFLAudio::WavEmitter wav("test.wav");
wav.connect(context);
wav.play();
// Wait for user input.
std::cout << "Press any key to quit the program." << std::endl;
std::cin.get();
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment