1 // sample.hxx -- Sound sample encapsulation class
3 // Written by Curtis Olson, started April 2004.
5 // Copyright (C) 2004 Curtis L. Olson - http://www.flightgear.org/~curt
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
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 * Provides a sound sample encapsulation
28 #ifndef _SG_SAMPLE_HXX
29 #define _SG_SAMPLE_HXX 1
32 # error This library requires C++
35 #include <simgear/compiler.h>
39 #include <simgear/debug/logstream.hxx>
43 #if defined(__APPLE__)
44 # define AL_ILLEGAL_ENUM AL_INVALID_ENUM
45 # define AL_ILLEGAL_COMMAND AL_INVALID_OPERATION
46 # include <OpenAL/al.h>
47 # include <OpenAL/alut.h>
56 * manages everything we need to know for an individual sound sample
65 // Buffers hold sound data.
68 // Sources are points emitting sound.
71 // Position of the source sound.
72 ALfloat source_pos[3];
74 // A constant offset to be applied to the final source_pos
75 ALfloat offset_pos[3];
77 // The orientation of the sound (direction and cut-off angles)
79 ALfloat inner, outer, outergain;
81 // Velocity of the source sound.
82 ALfloat source_vel[3];
84 // configuration values
92 double reference_dist;
103 * @param path Path name to sound
104 * @param file File name of sound
105 * @param cleanup Request clean up the intermediate data (this
106 should usually be true unless you want to manipulate the data
109 SGSoundSample( const char *path, const char *file, bool cleanup );
113 * @param _data Pointer to a memory buffer containing the sample data
114 * @param len Byte length of array
115 * @param _freq Frequency of the provided data (bytes per second)
116 * @param cleanup Request clean up the intermediate data (this
117 should usually be true unless you want to manipulate the data
120 SGSoundSample( unsigned char *_data, int len, int _freq, bool cleanup );
125 * Start playing this sample.
127 * @param _loop Define wether the sound should be played in a loop.
129 void play( bool _loop );
132 * Stop playing this sample.
134 * @param sched A pointer to the appropriate scheduler.
139 * Play this sample once.
142 inline void play_once() { play(false); }
145 * Play this sample looped.
148 inline void play_looped() { play(true); }
151 * Test if a sample is curretnly playing.
152 * @return true if is is playing, false otherwise.
157 * Get the current pitch setting of this sample.
159 inline double get_pitch() const { return pitch; }
162 * Set the pitch of this sample.
164 void set_pitch( double p );
167 * Get the current volume setting of this sample.
169 inline double get_volume() const { return volume; }
172 * Set the volume of this sample.
174 void set_volume( double v );
177 * Returns the size of the sounds sample
179 inline int get_size() {
184 * Return a pointer to the raw data
186 inline char *get_data() {
191 * Set position of sound source (uses same coordinate system as opengl)
193 void set_source_pos( ALfloat *pos );
196 * Set "constant" offset position of sound source (uses same
197 * coordinate system as opengl)
199 void set_offset_pos( ALfloat *pos );
202 * Set the orientation of the sound source, both for direction
203 * and audio cut-off angles.
205 void set_orientation( ALfloat *dir, ALfloat inner_angle=360.0,
206 ALfloat outer_angle=360.0,
207 ALfloat outer_gain=0.0);
210 * Set velocity of sound source (uses same coordinate system as opengl)
212 void set_source_vel( ALfloat *vel );
216 * Set reference distance of sound (the distance where the gain
219 void set_reference_dist( ALfloat dist );
223 * Set maximume distance of sound (the distance where the sound is
226 void set_max_dist( ALfloat dist );
230 #endif // _SG_SAMPLE_HXX