Skip to content
Snippets Groups Projects
Commit 8176fc49 authored by jpbl's avatar jpbl
Browse files

Launcher is back

parent f4562026
No related branches found
No related tags found
No related merge requests found
Showing with 462 additions and 27 deletions
......@@ -21,8 +21,3 @@
#include "Context.hpp"
#include "NullSource.hpp"
SFLAudio::Source *
SFLAudio::Context::createSource()
{
return new NullSource();
}
......@@ -28,10 +28,12 @@ namespace SFLAudio
class Context
{
public:
virtual bool isNull() {return false;}
/**
* Create a source for the context.
*/
Source *createSource();
virtual Source *createSource(int format, int freq) = 0;
};
}
......
......@@ -5,17 +5,19 @@ noinst_LTLIBRARIES = libsflaudio.la
libsflaudio_la_SOURCES = \
AudioLayer.cpp AudioLayer.hpp \
AudioManagerImpl.cpp AudioManagerImpl.hpp \
Context.cpp Context.hpp \
Context.hpp \
Device.cpp Device.hpp \
NullLayer.cpp NullLayer.hpp \
NullDevice.cpp NullDevice.hpp \
NullContext.cpp NullContext.hpp \
NullSource.hpp \
NullSource.cpp NullSource.hpp \
OpenALLayer.cpp OpenALLayer.hpp \
OpenALDevice.cpp OpenALDevice.hpp \
OpenALContext.cpp OpenALContext.hpp \
OpenALSource.cpp OpenALSource.hpp \
PortAudioLayer.cpp PortAudioLayer.hpp \
SFLAudio.hpp \
Source.hpp
Source.cpp Source.hpp
AM_CPPFLAGS = $(PORTAUDIO_CFLAGS) -I$(top_srcdir)/libs/portaudio/pa_common -I$(top_srcdir)/libs/
AM_CXXFLAGS = $(PORTAUDIO_CXXFLAGS) -I$(top_srcdir)/libs/
......
......@@ -22,7 +22,7 @@
#include "NullSource.hpp"
SFLAudio::Source *
SFLAudio::NullContext::createSource()
SFLAudio::NullContext::createSource(int, int)
{
return new NullSource();
}
......@@ -28,7 +28,8 @@ namespace SFLAudio
class NullContext : public Context
{
public:
Source *createSource();
virtual bool isNull() {return true;}
Source *createSource(int format, int freq);
};
}
......
......@@ -27,6 +27,12 @@ namespace SFLAudio
{
class NullSource : public Source
{
public:
NullSource();
virtual bool isNull() {return true;};
virtual bool isPlaying();
virtual void play(void *data, int size);
};
}
......
/*
* 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 "OpenALContext.hpp"
#include "OpenALSource.hpp"
#include "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
......@@ -22,7 +22,9 @@
#include <AL/al.h>
#include <AL/alc.h>
#include "OpenALDevice.hpp"
#include "OpenALContext.hpp"
#include "OpenALLayer.hpp"
#include "NullContext.hpp"
#include "NullDevice.hpp"
......@@ -66,5 +68,25 @@ SFLAudio::OpenALDevice::load() {
SFLAudio::Context *
SFLAudio::OpenALDevice::createContext()
{
return new NullContext();
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::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.
*/
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include <iostream>
#include <unistd.h>
#include "Context.hpp"
#include "NullSource.hpp"
#include "OpenALSource.hpp"
SFLAudio::OpenALSource::OpenALSource(int format, int freq, ALuint buffer, ALuint source)
: Source(format, freq)
, mBuffer(buffer)
, mSource(source)
{}
SFLAudio::OpenALSource::~OpenALSource()
{
alGetError();
alDeleteSources(1, &mSource);
ALenum error = alGetError();
if(error != AL_NO_ERROR) {
std::cerr << "OpenAL: alDeleteSources : " << alGetString(error) << std::endl;
}
alDeleteBuffers(1, &mBuffer);
error = alGetError();
if(error != AL_NO_ERROR) {
std::cerr << "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: 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: 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: 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: alDeleteBuffers : " << alGetString(error) << std::endl;;
return false;
}
return true;
}
bool
SFLAudio::OpenALSource::attach(ALuint source, ALuint buffer) {
// Attach buffer to source
alSourcei(source, AL_BUFFER, buffer);
ALenum error = alGetError();
if(error != AL_NO_ERROR) {
std::cerr << "OpenAL: alSourcei : " << alGetString(error);
return false;
}
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();
}
// Attach buffer to source
if(!attach(source, buffer)) {
deleteBuffer(buffer);
deleteSource(source);
return new NullSource();
}
return new OpenALSource(format, freq, buffer, source);
}
bool
SFLAudio::OpenALSource::isPlaying()
{
ALenum state;
alGetSourcei(mSource, AL_SOURCE_STATE, &state);
return (state == AL_PLAYING);
}
void
SFLAudio::OpenALSource::play(void *data, int size)
{
ALboolean loop;
// Copy test.wav data into AL Buffer 0
alBufferData(mBuffer, getFormat(), data, size, getFrequency());
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: alBufferData : " << alGetString(error);
}
alSourcePlay(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_OPENAL_SOURCE_HPP__
#define __SFLAUDIO_OPENAL_SOURCE_HPP__
#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);
private:
static bool genBuffer(ALuint &buffer);
static bool genSource(ALuint &source);
static bool deleteBuffer(ALuint &buffer);
static bool deleteSource(ALuint &source);
static bool attach(ALuint source, ALuint buffer);
private:
// Buffers to hold sound data.
ALuint mBuffer;
// Sources are points of emitting sound.
ALuint mSource;
};
}
#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/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include <iostream>
#include <unistd.h>
#include "Context.hpp"
#include "NullSource.hpp"
#include "OpenALSource.hpp"
SFLAudio::Source::Source(int format, int freq)
: mFormat(format)
, mFreq(freq)
{}
......@@ -25,6 +25,22 @@ namespace SFLAudio
{
class Source
{
private:
Source();
public:
Source(int format, int freq);
virtual bool isNull() {return false;}
virtual bool isPlaying() = 0;
virtual void play(void *data, int size) = 0;
int getFrequency() {return mFreq;}
int getFormat() {return mFormat;}
private:
int mFormat;
int mFreq;
};
}
......
......@@ -22,23 +22,50 @@
#include <list>
#include <string>
#include <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include "SFLAudio.hpp"
using namespace SFLAudio;
int main(int, char* [])
{
std::list< SFLAudio::AudioLayer * > layers =
SFLAudio::AudioManager::instance().getLayers();
for(std::list< SFLAudio::AudioLayer *>::iterator it = layers.begin();
it != layers.end();
it++) {
std::cout << "Layer: " << (*it)->getName() << std::endl;
AudioLayer *layer = *it;
Device *device = layer->openDevice();
std::cout << " Device: " << device->getName() << std::endl;
Context *context = device->createContext();
Source *source = context->createSource();
ALenum format;
ALvoid *data;
ALsizei size;
ALsizei freq;
ALboolean loop;
AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer();
std::cout << "Layer: " << layer->getName() << std::endl;
Device *device = layer->openDevice();
std::cout << " Device: " << device->getName() << std::endl;
Context *context = device->createContext();
std::cout << " Context is null: " << (context->isNull() ? "true" : "false") << std::endl;
// Load test.wav
alutLoadWAVFile("test.wav",&format,&data,&size,&freq,&loop);
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error);
return 1;
}
Source *source = context->createSource(format, freq);
std::cout << " Source is null: " << (source->isNull() ? "true" : "false") << std::endl;
source->play(data, size);
std::cout << "Unloading test.wav" << std::endl;
// Unload test.wav
alutUnloadWAV(format, data, size, freq);
error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: unloadWAV : " << alGetString(error);
}
std::cin.get();
}
......@@ -93,9 +93,9 @@ SFLPhoneApp::handleArg()
void
SFLPhoneApp::launch()
{
// if(mLauncher) {
// mLauncher->start();
// }
if(mLauncher) {
mLauncher->start();
}
}
void
......
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