1 // queue.hxx -- Sample Queue encapsulation class
5 // Copyright (C) 2010 Erik Hofman <erik@ehofman.com>
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software Foundation,
19 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 * \file audio sample.hxx
25 * Provides a sample queue encapsulation
29 #define _SG_QUEUE_HXX 1
32 # error This library requires C++
38 #include <simgear/compiler.h>
39 #include <simgear/debug/logstream.hxx>
40 #include <simgear/structure/SGReferenced.hxx>
41 #include <simgear/structure/SGSharedPtr.hxx>
42 #include <simgear/math/SGMath.hxx>
44 #include "sample_openal.hxx"
47 * manages everything we need to know for an individual audio sample
50 class SGSampleQueue : public SGSoundSample {
55 * Empty constructor, can be used to read data to the systems
56 * memory and not to the driver.
57 * @param freq sample frequentie of the samples
58 * @param format OpenAL format id of the data
60 SGSampleQueue(int freq, int format = AL_FORMAT_MONO8);
68 * Schedule this audio sample to stop playing.
73 * Queue new data for this audio sample
74 * @param data Pointer to a memory block containg this audio sample data.
75 * @param len length of the sample buffer in bytes
77 void add( const void* smp_data, size_t len );
80 * Set the source id of this source
81 * @param sid OpenAL source-id
83 virtual void set_source(unsigned int sid);
86 * Get the OpenAL source id of this source
87 * @return OpenAL source-id
89 virtual inline unsigned int get_source() { return _source; }
92 * Test if the source-id of this audio sample may be passed to OpenAL.
93 * @return true if the source-id is valid
95 virtual inline bool is_valid_source() const { return _valid_source; }
98 * Set the source-id of this audio sample to invalid.
100 virtual inline void no_valid_source() { _valid_source = false; }
103 * Test if the buffer-id of this audio sample may be passed to OpenAL.
104 * @return false for sample queue
106 inline bool is_valid_buffer() const { return false; }
108 inline virtual bool is_queue() const { return true; }
112 // Position of the source sound.
113 SGVec3d _absolute_pos; // absolute position
114 SGVec3d _relative_pos; // position relative to the base position
115 SGVec3d _direction; // orientation offset
116 SGVec3f _velocity; // Velocity of the source sound.
118 // The position and orientation of this sound
119 SGQuatd _orientation; // base orientation
120 SGVec3f _orivec; // orientation vector for OpenAL
121 SGVec3d _base_pos; // base position
125 std::string _refname; // sample name
126 std::vector<unsigned int> _buffers;
127 unsigned int _buffer;
129 // configuration values
133 // Sources are points emitting sound.
135 unsigned int _source;
137 // The orientation of this sound (direction and cut-off angles)
144 float _master_volume;
145 float _reference_dist;
152 string random_string();
156 #endif // _SG_QUEUE_HXX