]> git.mxchange.org Git - simgear.git/blob - simgear/sound/sample_queue.hxx
Remove ALUT usage from SimGear .
[simgear.git] / simgear / sound / sample_queue.hxx
1 // queue.hxx -- Sample Queue encapsulation class
2 // 
3 // based on sample.hxx
4 // 
5 // Copyright (C) 2010 Erik Hofman <erik@ehofman.com>
6 //
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.
11 //
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.
16 //
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.
20 //
21 // $Id$
22
23 /**
24  * \file audio sample.hxx
25  * Provides a sample queue encapsulation
26  */
27
28 #ifndef _SG_QUEUE_HXX
29 #define _SG_QUEUE_HXX 1
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35 #include <string>
36 #include <vector>
37
38 #include <simgear/compiler.h>
39 #include <simgear/debug/logstream.hxx>
40 #include <simgear/structure/SGReferenced.hxx>
41 #include <simgear/structure/SGSharedPtr.hxx>
42
43 #include "sample_openal.hxx"
44
45 /**
46  * manages everything we need to know for an individual audio sample
47  */
48
49 class SGSampleQueue : public SGSoundSample {
50 public:
51
52
53      /**
54       * Empty constructor, can be used to read data to the systems
55       * memory and not to the driver.
56       * @param freq sample frequentie of the samples
57       * @param format OpenAL format id of the data
58       */
59     SGSampleQueue(int freq, int format = AL_FORMAT_MONO8);
60
61     /**
62      * Destructor
63      */
64     ~SGSampleQueue ();
65
66     /**
67      * Schedule this audio sample to stop playing.
68      */
69     virtual void stop();
70
71     /**
72      * Queue new data for this audio sample
73      * @param data Pointer to a memory block containg this audio sample data.
74      * @param len length of the sample buffer in bytes
75      */
76     void add( const void* smp_data, size_t len );
77
78     /**
79      * Set the source id of this source
80      * @param sid OpenAL source-id
81      */
82     virtual void set_source(unsigned int sid);
83
84     /**
85      * Get the OpenAL source id of this source
86      * @return OpenAL source-id
87      */
88     virtual inline unsigned int get_source() { return _source; }
89
90     /**
91      * Test if the source-id of this audio sample may be passed to OpenAL.
92      * @return true if the source-id is valid
93      */
94     virtual inline bool is_valid_source() const { return _valid_source; }
95
96     /**
97      * Set the source-id of this audio sample to invalid.
98      */
99     virtual inline void no_valid_source() { _valid_source = false; }
100
101     /**
102      * Test if the buffer-id of this audio sample may be passed to OpenAL.
103      * @return false for sample queue
104      */
105     inline bool is_valid_buffer() const { return false; }
106
107     inline virtual bool is_queue() const { return true; }
108
109 private:
110
111     // Position of the source sound.
112     SGVec3d _absolute_pos;      // absolute position
113     SGVec3d _relative_pos;      // position relative to the base position
114     SGVec3d _direction;         // orientation offset
115     SGVec3f _velocity;          // Velocity of the source sound.
116
117     // The position and orientation of this sound
118     SGQuatd _orientation;       // base orientation
119     SGVec3f _orivec;            // orientation vector for OpenAL
120     SGVec3d _base_pos;          // base position
121
122     SGQuatd _rotation;
123
124     std::string _refname;       // sample name
125     std::vector<unsigned int> _buffers;
126     unsigned int _buffer;
127
128     // configuration values
129     int _format;
130     int _freq;
131
132     // Sources are points emitting sound.
133     bool _valid_source;
134     unsigned int _source;
135
136     // The orientation of this sound (direction and cut-off angles)
137     float _inner_angle;
138     float _outer_angle;
139     float _outer_gain;
140
141     float _pitch;
142     float _volume;
143     float _master_volume;
144     float _reference_dist;
145     float _max_dist;
146     bool _loop;
147
148     bool _playing;
149     bool _changed;
150
151     std::string random_string();
152 };
153
154
155 #endif // _SG_QUEUE_HXX
156
157