HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AU_SoundManager.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: AU_SoundManager.h ( AU Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __AU_SoundManager__
12 #define __AU_SoundManager__
13 
14 #include "AU_API.h"
15 #include "AU_Defines.h"
16 #include <UT/UT_SharedPtr.h>
17 #include <UT/UT_UniquePtr.h>
18 #include <SYS/SYS_AtomicInt.h>
19 
20 class CL_Clip;
21 class UT_Thread;
22 
23 enum au_SoundCommand : int;
24 class AU_SoundUtil; // internal class
25 
26 class AU_SoundManager;
28 
30 {
31 public:
32  ~AU_SoundManager();
33 
34  AU_SoundManager(const AU_SoundManager &) = delete;
35  AU_SoundManager &operator=(const AU_SoundManager &) = delete;
36 
37  //
38  // General access methods
39  //
40 
41  void setMute(int onoff);
42  int getMute() const;
43  void setMono(int onoff);
44  int getMono() const;
45  void setLeftVolume(float volume);
46  float getLeftVolume() const;
47  void setRightVolume(float volume);
48  float getRightVolume() const;
49 
50 
51  //
52  // Test clip methods
53  //
54  // The test buffer allows you to load a test sound clip and
55  // play portions of it with resumable interruptions.
56  // Very similiar to a tape deck operation.
57  //
58 
59  int loadTest(const CL_Clip *clip, int rewind);
60  int unloadTest();
61 
62  int isTestActive() const;
63  int rewindTest();
64  int forwardTest();
65  void waitTestEnd();
66 
67  int setTestDirection(int dir); // -1=rev,0=stop,1=for
68  int setTestLoop(int yesno);
69 
70  int setTestFull(int yesno); // if no use range
71  void setTestRange(float min, float max);
72 
73  //
74  // Play methods
75  //
76  // The play buffer loads and plays a single uninterruptable sound clip
77  // It is mainly intended to play single sound effect files
78  //
79 
80  int playFile(const char *filename, float l, float r);
81  int isPlaying() const;
82 
83  //
84  // Scrub methods
85  //
86  // The scrub buffer loads a sound clip which can be sampled and
87  // scrubbed.
88  //
89 
90 
91  int loadScrub(const CL_Clip *clip);
92  int unloadScrub();
93  int isScrubbing() const;
94 
95  void scrubReset();
96  void setScrubRealTime(int level);
97  int getScrubRealTime() const;
98  void setScrubRepeat(int onoff);
99  int getScrubRepeat() const;
100  void setScrubSustain(float sustain);
101  float getScrubSustain() const;
102  void setScrubOffset(float offset);
103  float getScrubOffset() const;
104  void setScrubLength(float length);
105  float getScrubLength() const;
106  void setScrubDeltas(float fore, float back);
107  void getScrubDeltas(float &fore, float &back) const;
108  void setScrubIndex(float index);
109  float getScrubIndex() const;
110  void setScrubSmooth(int smooth);
111  int getScrubSmooth() const;
112  void setScrubReverse(bool is_reverse);
113  bool getScrubReverse() const;
114  void setScrubOneFrame(bool is_oneframe);
115  bool getScrubOneFrame() const;
116 
117  //
118  // Realtime methods
119  //
120 
121  int loadRealtime(const CL_Clip *clip, int start,int end,
122  float queue);
123  void startRealtime(int rate, int channels,float queue);
124  void stopRealtime();
125  int isRealtime() const;
126 
127  //
128  // Misc methods
129  //
130 
131  void getMaxLevel(float *l, float *r) const; // meter
132  void shutDown(); // unload test/scrub buffers
133  int isAUDeviceOpen() const;// query
134  void loseAUInterest() const;// reset
135  int obtainAUDevice() ; // get
136  int releaseAUDevice(); // release audio device
137 
138 
139 private:
140  struct PassKey {};
141 public:
142  AU_SoundManager(const PassKey &);
143 
144 private:
145  void resetDataBuffers();
146 
147  static void *audioProcess(void *);
148  void initializeAudioProcess();
149 
150  int sendAudioCommand(au_SoundCommand command);
151  int loadFromClip(const CL_Clip *clip);
152  void loadSegmentFromClip(const CL_Clip *clip,
153  float *data[AU_MAX_CHANNELS],
154  int start, int end,
155  int &length);
156 
157 private:
158 
159  UT_UniquePtr<AU_SoundUtil> mySoundUtil;
160  UT_UniquePtr<float[]> myDataBuffers[AU_MAX_CHANNELS];
161  SYS_AtomicInt32 myLock;
162  UT_UniquePtr<UT_Thread> myServerPID;
163 
165 };
166 
167 AU_API extern AU_SoundManagerPtr AUgetSoundManager(); // Get sound interrupt ptr
168 
169 #endif
typedef int(APIENTRYP RE_PFNGLXSWAPINTERVALSGIPROC)(int)
GT_API const UT_StringHolder filename
GLuint start
Definition: glcorearb.h:475
UT_SharedPtr< AU_SoundManager > AU_SoundManagerPtr
GLint level
Definition: glcorearb.h:108
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLintptr offset
Definition: glcorearb.h:665
std::shared_ptr< T > UT_SharedPtr
Wrapper around std::shared_ptr.
Definition: UT_SharedPtr.h:36
#define AU_API
Definition: AU_API.h:10
GLuint GLuint end
Definition: glcorearb.h:475
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the queue
Definition: thread.h:632
AU_API AU_SoundManagerPtr AUgetSoundManager()
virtual bool smooth(GA_AttributeOperand &d, GA_AttributeOperand &min, GA_AttributeOperand &max, GA_AttributeOperand &t) const
d = SYSsmooth(min, max, t);
LeafData & operator=(const LeafData &)=delete
GLuint index
Definition: glcorearb.h:786
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
GLboolean r
Definition: glcorearb.h:1222
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER IMATH_HOSTDEVICE IMATH_CONSTEXPR14 T clip(const T &p, const Box< T > &box) IMATH_NOEXCEPT
Definition: ImathBoxAlgo.h:29
Definition: format.h:1821
#define AU_MAX_CHANNELS
Definition: AU_Defines.h:17
ImageBuf OIIO_API channels(const ImageBuf &src, int nchannels, cspan< int > channelorder, cspan< float > channelvalues={}, cspan< std::string > newchannelnames={}, bool shuffle_channel_names=false, int nthreads=0)