Panda3D
audioSound.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file audioSound.h
10  * @author skyler
11  * @date 2001-06-06
12  * Prior system by: cary
13  */
14 
15 #ifndef __AUDIOSOUND_H__
16 #define __AUDIOSOUND_H__
17 
18 #include "config_audio.h"
19 #include "typedReferenceCount.h"
20 #include "pointerTo.h"
21 #include "filterProperties.h"
22 
23 class AudioManager;
24 
25 class EXPCL_PANDA_AUDIO AudioSound : public TypedReferenceCount {
26 PUBLISHED:
27  virtual ~AudioSound();
28 
29  // For best compatibility, set the loop_count, volume, and balance, prior to
30  // calling play(). You may set them while they're playing, but it's
31  // implementation specific whether you get the results. - Calling play() a
32  // second time on the same sound before it is finished will start the sound
33  // again (creating a skipping or stuttering effect).
34  virtual void play() = 0;
35  virtual void stop() = 0;
36 
37  // loop: false = play once; true = play forever. inits to false.
38  virtual void set_loop(bool loop=true) = 0;
39  virtual bool get_loop() const = 0;
40 
41  // loop_count: 0 = forever; 1 = play once; n = play n times. inits to 1.
42  virtual void set_loop_count(unsigned long loop_count=1) = 0;
43  virtual unsigned long get_loop_count() const = 0;
44 
45 /*
46  * Control time position within the sound. This is similar (in concept) to
47  * the seek position within a file. time in seconds: 0 = beginning; length()
48  * = end. inits to 0.0. - The current time position will not change while the
49  * sound is playing; you must call play() again to effect the change. To play
50  * the same sound from a time offset a second time, explicitly set the time
51  * position again. When looping, the second and later loops will start from
52  * the beginning of the sound. - If a sound is playing, calling get_time()
53  * repeatedly will return different results over time. e.g.: PN_stdfloat
54  * percent_complete = s.get_time() s.length();
55  */
56  virtual void set_time(PN_stdfloat start_time=0.0) = 0;
57  virtual PN_stdfloat get_time() const = 0;
58 
59  // 0 = minimum; 1.0 = maximum. inits to 1.0.
60  virtual void set_volume(PN_stdfloat volume=1.0) = 0;
61  virtual PN_stdfloat get_volume() const = 0;
62 
63  // -1.0 is hard left 0.0 is centered 1.0 is hard right inits to 0.0.
64  virtual void set_balance(PN_stdfloat balance_right=0.0) = 0;
65  virtual PN_stdfloat get_balance() const = 0;
66 
67  // play_rate is any positive PN_stdfloat value. inits to 1.0.
68  virtual void set_play_rate(PN_stdfloat play_rate=1.0f) = 0;
69  virtual PN_stdfloat get_play_rate() const = 0;
70 
71  // inits to manager's state.
72  virtual void set_active(bool flag=true) = 0;
73  virtual bool get_active() const = 0;
74 
75  // Set (or clear) the event that will be thrown when the sound finishes
76  // playing. To clear the event, pass an empty string.
77  virtual void set_finished_event(const std::string& event) = 0;
78  virtual const std::string& get_finished_event() const = 0;
79 
80  // There is no set_name(), this is intentional.
81  virtual const std::string& get_name() const = 0;
82 
83  // return: playing time in seconds.
84  virtual PN_stdfloat length() const = 0;
85 
86  // Controls the position of this sound's emitter. px, py and pz are the
87  // emitter's position. vx, vy and vz are the emitter's velocity in UNITS
88  // PER SECOND (default: meters).
89  virtual void set_3d_attributes(PN_stdfloat px, PN_stdfloat py, PN_stdfloat pz,
90  PN_stdfloat vx, PN_stdfloat vy, PN_stdfloat vz);
91  virtual void get_3d_attributes(PN_stdfloat *px, PN_stdfloat *py, PN_stdfloat *pz,
92  PN_stdfloat *vx, PN_stdfloat *vy, PN_stdfloat *vz);
93 
94 
95  // Controls the distance (in units) that this sound begins to fall off.
96  // Also affects the rate it falls off. Default is 1.0 CloserFaster, <1.0
97  // FartherSlower, >1.0
98  virtual void set_3d_min_distance(PN_stdfloat dist);
99  virtual PN_stdfloat get_3d_min_distance() const;
100 
101  // Controls the maximum distance (in units) that this sound stops falling
102  // off. The sound does not stop at that point, it just doesn't get any
103  // quieter. You should rarely need to adjust this. Default is 1000000000.0
104  virtual void set_3d_max_distance(PN_stdfloat dist);
105  virtual PN_stdfloat get_3d_max_distance() const;
106 
107  // *_speaker_mix and *_speaker_level(s) serve the same purpose.
108  // *_speaker_mix is for use with FMOD. *_speaker_level(s) is for use with
109  // Miles. Both interfaces exist because of a significant difference in the
110  // two APIs. Hopefully the difference can be reconciled into a single
111  // interface at some point.
112  virtual PN_stdfloat get_speaker_mix(int speaker);
113  virtual void set_speaker_mix(PN_stdfloat frontleft, PN_stdfloat frontright, PN_stdfloat center, PN_stdfloat sub, PN_stdfloat backleft, PN_stdfloat backright, PN_stdfloat sideleft, PN_stdfloat sideright);
114 
115  virtual PN_stdfloat get_speaker_level(int index);
116  virtual void set_speaker_levels(PN_stdfloat level1, PN_stdfloat level2=-1.0f, PN_stdfloat level3=-1.0f, PN_stdfloat level4=-1.0f, PN_stdfloat level5=-1.0f, PN_stdfloat level6=-1.0f, PN_stdfloat level7=-1.0f, PN_stdfloat level8=-1.0f, PN_stdfloat level9=-1.0f);
117 
118  virtual int get_priority();
119  virtual void set_priority(int priority);
120 
121  virtual bool configure_filters(FilterProperties *config);
122 
123  enum SoundStatus { BAD, READY, PLAYING };
124  virtual SoundStatus status() const = 0;
125 
126  virtual void output(std::ostream &out) const;
127  virtual void write(std::ostream &out) const;
128 
129 protected:
130  AudioSound();
131 
132  friend class AudioManager;
133 
134 public:
135  static TypeHandle get_class_type() {
136  return _type_handle;
137  }
138  static void init_type() {
139  TypedReferenceCount::init_type();
140  register_type(_type_handle, "AudioSound",
141  TypedReferenceCount::get_class_type());
142  }
143  virtual TypeHandle get_type() const {
144  return get_class_type();
145  }
146  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
147 
148 private:
149  static TypeHandle _type_handle;
150 };
151 
152 inline std::ostream &
153 operator << (std::ostream &out, const AudioSound &sound) {
154  sound.output(out);
155  return out;
156 }
157 
158 #include "audioSound.I"
159 
160 EXPCL_PANDA_AUDIO std::ostream &
161 operator << (std::ostream &out, AudioSound::SoundStatus status);
162 
163 #endif /* __AUDIOSOUND_H__ */
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...
Definition: register_type.I:22
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Stores a configuration for a set of audio DSP filters.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.