YSE sound engine  1.0
cross platform sound engine
 All Classes Namespaces Functions Pages
soundInterface.hpp
1 /*
2  ==============================================================================
3 
4  sound.h
5  Created: 28 Jan 2014 11:50:15am
6  Author: yvan
7 
8  ==============================================================================
9 */
10 
11 #ifndef SOUNDINTERFACE_H_INCLUDED
12 #define SOUNDINTERFACE_H_INCLUDED
13 
14 #include "../classes.hpp"
15 #include "../headers/defines.hpp"
16 
17 #if defined PUBLIC_JUCE
18 #include "JuceHeader.h"
19 #endif
20 
21 namespace YSE {
22  namespace SOUND {
23 
36  class API interfaceObject {
37  public:
39  ~interfaceObject();
40 
41  // Sound interfaces cannot be copied. The implementation needs access to the
42  // interface object. To do this, the address of the interface must not change.
43  interfaceObject(const interfaceObject&) = delete;
44 
63  interfaceObject& create(const char * fileName, channel * ch = nullptr, Bool loop = false, Flt volume = 1.0f, Bool streaming = false);
64 
74  interfaceObject& create(DSP::dspSourceObject & dsp, channel * ch = nullptr, Flt volume = 1.0f);
75 
84  interfaceObject& create(SYNTH::interfaceObject & synth, channel * ch = nullptr, Flt volume = 1.0f);
85 
86 
87 #if defined PUBLIC_JUCE
88 
94  interfaceObject& create(juce::InputStream * source, channel * ch = nullptr, Bool loop = false, Flt volume = 1.0f, Bool streaming = false);
95 #endif
96 
97  /*
98  Checks if there is an implementation linked to this interface. You can use this for debugging, but safely assume
99  this returns true for the lifetime of the interface. It's not needed to check against this function before
100  using the interface.
101  */
102  Bool isValid();
103 
107  interfaceObject& setPosition(const Vec &v);
108 
112  Vec getPosition();
113 
119  interfaceObject& setSpread(Flt value);
120 
124  Flt getSpread();
125 
138  interfaceObject& setSpeed(Flt value);
139 
142  Flt getSpeed();
143 
148  interfaceObject& setSize(Flt value);
149 
152  Flt getSize();
153 
156  interfaceObject& setLooping(Bool value);
157 
160  Bool isLooping();
161 
168  interfaceObject& setVolume(Flt value, UInt time = 0);
169 
174  Flt getVolume();
175 
179  interfaceObject& fadeAndStop(UInt time);
180 
184  interfaceObject& play();
185 
189  Bool isPlaying();
190 
194  interfaceObject& pause();
195 
199  Bool isPaused();
200 
205  interfaceObject& stop();
206 
210  Bool isStopped();
211 
215  interfaceObject& toggle();
216 
220  interfaceObject& restart();
221 
228  interfaceObject& setTime(Flt value);
229 
236  Flt getTime();
237 
243  UInt getLength(); // sound length in samples
244 
253  interfaceObject& setRelative(Bool value);
254 
258  Bool isRelative();
259 
264  interfaceObject& setDoppler(Bool value);
265 
269  Bool getDoppler();
270 
274  interfaceObject& set2D(Bool value);
275 
276 
277  Bool is2D();
278 
283  Bool isStreaming();
284 
293  Bool isReady();
294 
299  interfaceObject& setOcclusion(Bool value);
300 
304  Bool getOcclusion();
305 
311  interfaceObject& moveTo(channel & target);
312 
313  interfaceObject& setDSP(DSP::dspObject * value); DSP::dspObject * getDSP(); // attach a dsp object to this sound
314 
315 
316 
317  private:
318  implementationObject * pimpl;
319 
320  // These values keep the last set value and are used by getters
321  // so that we don't have to query the implementation
322  Vec pos;
323  Flt spread;
324  Flt volume;
325  Flt speed;
326  Flt size;
327  Bool loop;
328  Bool relative;
329  Bool doppler;
330  Bool pan2D;
331  Bool occlusion;
332 
333  UInt fadeAndStopTime;
334  DSP::dspObject * dsp;
335  channel * parent;
336 
337  // these are frequently updated by the implementation
338  aBool streaming;
339  aUInt length;
340  aFlt time;
341  std::atomic<SOUND_STATUS> status; // what it is currently doing
342 
343  friend class SOUND::implementationObject;
344  };
345  }
346 }
347 
348 
349 
350 
351 #endif // SOUND_H_INCLUDED
Channels are used to control groups of sounds simultaniously.
A sound object is needed for every kind of sound you want to use.