set(HEADERS
sample_group.hxx
sample_openal.hxx
- sample_queue.hxx
soundmgr_openal.hxx
xmlsound.hxx
readwav.hxx
set(SOURCES
sample_group.cxx
sample_openal.cxx
- sample_queue.cxx
soundmgr_openal.cxx
xmlsound.cxx
readwav.cxx
create_test(openal_test1)
create_test(openal_test2)
create_test(openal_test3)
-create_test(openal_test4)
endif()
+++ /dev/null
-#include <stdio.h>
-#ifdef _WIN32
-#include <windows.h>
-#define sleep(x) Sleep(x*1000)
-#else
-#include <unistd.h>
-#endif
-
-#include <simgear/debug/logstream.hxx>
-#include <simgear/misc/sg_path.hxx>
-
-#include "soundmgr_openal.hxx"
-#include "sample_group.hxx"
-#include "sample_openal.hxx"
-
-int main( int argc, char *argv[] ) {
- SGSampleQueue *squeue;
- SGSampleGroup *sgr;
- SGSoundMgr *smgr;
- SGGeod pos;
-
- smgr = new SGSoundMgr;
-
- smgr->bind();
- smgr->select_device("OSS Default");
- smgr->init();
- sgr = smgr->find("default", true);
- smgr->set_volume(0.9);
- smgr->activate();
- smgr->set_position( SGVec3d::fromGeod(SGGeod()), SGGeod() );
-
- void *data;
- size_t len;
- int freq, fmt;
- std::string file = SRC_DIR"/jet.wav";
- smgr->load(file, &data, &fmt, &len, &freq);
-
- squeue = new SGSampleQueue( freq, fmt );
- squeue->set_volume(1.0);
-
- sgr->add(squeue, "queue");
-
- squeue->add( data, len );
- squeue->add( data, len );
- squeue->play();
- printf("playing queue\n");
-
- smgr->update(1.0);
- sleep(10);
- smgr->update(10.0);
-
- printf("source at lat,lon = (10,-10), listener at (9.99,-9.99)\n");
- pos = SGGeod::fromDeg(9.99,-9.99);
- sgr->set_position_geod( SGGeod::fromDeg(10,-10) );
- smgr->set_position( SGVec3d::fromGeod(pos), pos );
-
- squeue->add( data, len );
- squeue->add( data, len );
- squeue->play( true ); // play looped
- printf("playing queue\n");
-
- smgr->update(1.0);
- sleep(10);
- smgr->update(10.0);
-
- squeue->stop();
- smgr->update(1.0);
- sleep(1);
-
- sgr->remove("queue");
- smgr->unbind();
- sleep(2);
-
- delete smgr;
-}
#include <simgear/structure/exception.hxx>
#include "sample_openal.hxx"
-#include "sample_queue.hxx"
typedef std::map < std::string, SGSharedPtr<SGSoundSample> > sample_map;
#ifndef _SG_SAMPLE_HXX
#define _SG_SAMPLE_HXX 1
+#include <simgear/math/SGMath.hxx>
#include <simgear/props/props.hxx>
enum {
+++ /dev/null
-
-// queue.cxx -- Audio sample encapsulation class
-//
-// Written by Curtis Olson, started April 2004.
-// Modified to match the new SoundSystem by Erik Hofman, October 2009
-//
-// Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
-// Copyright (C) 2009 Erik Hofman <erik@ehofman.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-//
-// $Id$
-
-#ifdef HAVE_CONFIG_H
-# include <simgear_config.h>
-#endif
-
-#include <cstdlib> // rand()
-#include <cstring>
-
-#include <simgear/debug/logstream.hxx>
-#include <simgear/structure/exception.hxx>
-#include <simgear/misc/sg_path.hxx>
-
-#include "soundmgr_openal.hxx"
-#include "sample_queue.hxx"
-#include "soundmgr_openal_private.hxx"
-
-using std::string;
-
-//
-// SGSampleQueue
-//
-
-// empty constructor
-SGSampleQueue::SGSampleQueue( int freq, int format ) :
- _refname(random_string()),
- _playing(false)
-{
- set_frequency( freq );
- set_format_AL( format );
- _buffers.clear();
-}
-
-SGSampleQueue::~SGSampleQueue() {
- stop();
-}
-
-void SGSampleQueue::stop()
-{
-#ifdef ENABLE_SOUND
- ALint num;
- alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num);
- for (int i=0; i<num; i++) {
- ALuint buffer;
- alSourceUnqueueBuffers(_source, 1, &buffer);
- alDeleteBuffers(1, &buffer);
- }
- _buffers.clear();
-#endif
- _playing = false;
- _changed = true;
-}
-
-void SGSampleQueue::add( const void* smp_data, size_t len )
-{
-#ifdef ENABLE_SOUND
- const ALvoid *data = (const ALvoid *)smp_data;
- ALuint buffer;
- ALint num;
-
- if ( _valid_source )
- {
- alGetSourcei(_source, AL_BUFFERS_PROCESSED, &num);
- if (num > 1) {
- alSourceUnqueueBuffers(_source, 1, &buffer);
- } else {
- alGenBuffers(1, &buffer);
- }
- alBufferData(buffer, get_format_AL(), data, len, get_frequency());
- }
- else
- {
- alGenBuffers(1, &buffer);
- alBufferData(buffer, get_format_AL(), data, len, get_frequency());
- _buffers.push_back(buffer);
- }
-#endif
-}
-
-void SGSampleQueue::set_source( unsigned int sid )
-{
- SGSoundSample::set_source(sid);
-#ifdef ENABLE_SOUND
- ALuint num = _buffers.size();
- for (unsigned int i=0; i < num; i++)
- {
- ALuint buffer = _buffers[i];
- alSourceQueueBuffers(_source, 1, &buffer);
- }
- _buffers.clear();
-#endif
-}
-
-string SGSampleQueue::random_string() {
- static const char *r = "0123456789abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
- string rstr = "Queued sample: ";
- for (int i=0; i<10; i++) {
- rstr.push_back( r[rand() % strlen(r)] );
- }
-
- return rstr;
-}
+++ /dev/null
-///@file
-/// Provides a sample queue encapsulation
-//
-// based on sample.hxx
-//
-// Copyright (C) 2010 Erik Hofman <erik@ehofman.com>
-//
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Library General Public
-// License as published by the Free Software Foundation; either
-// version 2 of the License, or (at your option) any later version.
-//
-// This library 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
-// Library General Public License for more details.
-//
-// You should have received a copy of the GNU Library General Public
-// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
-
-#ifndef _SG_QUEUE_HXX
-#define _SG_QUEUE_HXX 1
-
-#include <string>
-#include <vector>
-
-#include <simgear/compiler.h>
-#include <simgear/structure/SGReferenced.hxx>
-#include <simgear/structure/SGSharedPtr.hxx>
-
-#include "sample_openal.hxx"
-
-/**
- * manages everything we need to know for an individual audio sample
- */
-
-class SGSampleQueue : public SGSoundSample {
-public:
-
-
- /**
- * Empty constructor, can be used to read data to the systems
- * memory and not to the driver.
- * @param freq sample frequentie of the samples
- * @param format OpenAL format id of the data
- */
- SGSampleQueue(int freq, int format = SG_SAMPLE_MONO8);
-
- /**
- * Destructor
- */
- ~SGSampleQueue ();
-
- /**
- * Schedule this audio sample to stop playing.
- */
- virtual void stop();
-
- /**
- * Queue new data for this audio sample.
- *
- * @param data Pointer to a memory block containg this audio sample data.
- * @param len Length of the sample buffer in bytes.
- */
- void add( const void* data, size_t len );
-
- /**
- * Set the source id of this source.
- *
- * @param sid OpenAL source-id
- */
- virtual void set_source(unsigned int sid);
-
- /**
- * Test if the buffer-id of this audio sample may be passed to OpenAL.
- *
- * @return false for sample queue
- */
- inline bool is_valid_buffer() const { return false; }
-
- inline virtual bool is_queue() const { return true; }
-
-private:
- std::string _refname; // sample name
- std::vector<unsigned int> _buffers;
-
- bool _playing;
-
- std::string random_string();
-};
-
-
-#endif // _SG_QUEUE_HXX
-
-