Skip to content
Snippets Groups Projects
Commit 99231e55 authored by jpbl's avatar jpbl
Browse files

added example03.cpp

parent 8176fc49
No related branches found
No related tags found
No related merge requests found
if MAINTENER_CODE
noinst_PROGRAMS = example01 example02
noinst_PROGRAMS = example01 example02 example03
noinst_LTLIBRARIES = libsflaudio.la
libsflaudio_la_SOURCES = \
......@@ -29,5 +29,6 @@ LDADD = libsflaudio.la $(PORTAUDIO_LIBS) -lopenal -lportaudio
example01_SOURCES = example01.cpp
example02_SOURCES = example02.cpp
example03_SOURCES = example03.cpp
endif
......@@ -33,6 +33,7 @@ namespace SFLAudio
virtual bool isNull() {return true;};
virtual bool isPlaying();
virtual void play(void *data, int size);
virtual void stop();
};
}
......
......@@ -170,6 +170,8 @@ SFLAudio::OpenALSource::play(void *data, int size)
{
ALboolean loop;
alGetError();
// Copy test.wav data into AL Buffer 0
alBufferData(mBuffer, getFormat(), data, size, getFrequency());
ALenum error = alGetError();
......@@ -179,3 +181,9 @@ SFLAudio::OpenALSource::play(void *data, int size)
alSourcePlay(mSource);
}
void
SFLAudio::OpenALSource::stop()
{
alSourceStop(mSource);
}
......@@ -42,6 +42,7 @@ namespace SFLAudio
// Source functions
virtual bool isPlaying();
virtual void play(void *data, int size);
virtual void stop();
private:
static bool genBuffer(ALuint &buffer);
......
example01.cpp: This is an enumeration of device example.
\ No newline at end of file
example01.cpp: This is an enumeration of device example.
example02.cpp: A simple WAV player.
example03.cpp: A simple WAV player, with 2 files playing at the same time.
\ No newline at end of file
......@@ -34,6 +34,7 @@ namespace SFLAudio
virtual bool isNull() {return false;}
virtual bool isPlaying() = 0;
virtual void play(void *data, int size) = 0;
virtual void stop() = 0;
int getFrequency() {return mFreq;}
int getFormat() {return mFormat;}
......
......@@ -39,12 +39,8 @@ int main(int, char* [])
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);
......@@ -55,17 +51,16 @@ int main(int, char* [])
}
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);
std::cin.get();
error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: unloadWAV : " << alGetString(error);
}
std::cin.get();
}
/*
* 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 <AL/al.h>
#include <AL/alc.h>
#include <AL/alut.h>
#include "SFLAudio.hpp"
using namespace SFLAudio;
int main(int, char* [])
{
ALenum format1;
ALvoid *data1;
ALsizei size1;
ALsizei freq1;
ALboolean loop1;
ALenum format2;
ALvoid *data2;
ALsizei size2;
ALsizei freq2;
ALboolean loop2;
AudioLayer *layer = SFLAudio::AudioManager::instance().currentLayer();
Device *device = layer->openDevice();
Context *context = device->createContext();
// Load test.wav
alutLoadWAVFile("test.wav",&format1,&data1,&size1,&freq1,&loop1);
ALenum error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error);
return 1;
}
// Load test2.wav
alutLoadWAVFile("test2.wav",&format2,&data2,&size2,&freq2,&loop2);
error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: loadWAVFile : " << alGetString(error);
return 1;
}
Source *source1 = context->createSource(format1, freq1);
source1->play(data1, size1);
Source *source2 = context->createSource(format2, freq2);
source2->play(data2, size2);
// Unload test.wav and test2.wav
alutUnloadWAV(format1, data1, size1, freq1);
alutUnloadWAV(format2, data2, size2, freq2);
std::cin.get();
error = alGetError();
if (error != AL_NO_ERROR) {
std::cerr << "OpenAL: unloadWAV : " << alGetString(error);
}
}
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