Audio Scol plugin 1.0
Audio Scol plugin based on CAudio library
audio.h
1
2
3#ifndef SCOLAUDIO_H
4#define SCOLAUDIO_H
5
6#include <string>
7#include <set>
8
9//Data source
10#include "IDataSource.h"
11#include "cAudioDefines.h"
12#include "cMemoryOverride.h"
13#include "cMemorySource.h"
14#include "cMutex.h"
15
16#include "plugin.h"
17
18class cScolFileSource : public cAudio::IDataSource, public cAudio::cMemoryOverride
19{
20public:
21 cScolFileSource(const char* filename);
23
24 virtual bool isValid();
25 virtual int getCurrentPos();
26 virtual int getSize();
27 virtual int read(void* output, int size);
28 virtual bool seek(int amount, bool relative);
29
30protected:
32 bool Valid;
36 FILE* pFile;
37private:
38};
39
40class cScolFileSourceFactory : public cAudio::IDataSourceFactory
41{
42public:
44 virtual ~cScolFileSourceFactory() { }
45
46 virtual cAudio::IDataSource* CreateDataSource(const char* filename, bool streamingRequested)
47 {
48 cAudio::IDataSource* source = CAUDIO_NEW cScolFileSource(filename);
49
50 if (!streamingRequested && source && source->isValid())
51 {
52 //A bit hackish, but if the user doesn't want streaming, make this a memory source
53 int length = source->getSize();
54 char* tempbuf = (char*)CAUDIO_MALLOC(length);
55 if (tempbuf)
56 {
57 source->read(tempbuf, length);
58 cAudio::IDataSource* memSource = CAUDIO_NEW cAudio::cMemorySource(tempbuf, length, true);
59 CAUDIO_FREE(tempbuf);
60
61 if (memSource && memSource->isValid())
62 {
63 source->drop();
64 return memSource;
65 }
66
67 if (memSource)
68 memSource->drop();
69 }
70 }
71 return source;
72 }
73};
74
75class SAudioSound;
76class SAudioInput;
77class SAudioManager : public cAudio::IManagerEventHandler
78{
79private:
82protected:
83public:
84
85private:
86 cAudio::IAudioManager* manager;
87 cScolFileSourceFactory* scolDataFactory;
88 static SAudioManager* _singleton;
89 std::set<SAudioSound*> validSounds;
90 std::set<SAudioInput*> validInput;
91 bool mPaused;
92 bool muted;
93 float unmutedVolume;
94
95#if CAUDIO_EFX_ENABLED == 1
96 cAudio::IEffect* mEffect;
97 cAudio::IFilter* mFilter;
98
99 cAudio::FilterTypes mFilterType;
100 float mFilterLowFreqVolume;
101 float mFilterHighFreqVolume;
102 cAudio::EffectTypes mEffectType;
103 std::string mEffectPreset;
104#endif
105
106protected:
107
108public:
109 static SAudioManager* GetInstance();
110 static void Kill();
111
112 cAudio::IAudioManager* GetManager();
113 void SetListenerPosition(cAudio::cVector3 pos, cAudio::cVector3 dir);
114 bool GetValidSound(SAudioSound* sound);
115 void RemoveSound(SAudioSound* sound);
116 SAudioSound* AddSound(std::string name, std::string path, bool stream);
117 SAudioSound* AddSound(std::string name, unsigned int frequency, cAudio::AudioFormats format);
118 void Pause();
119 void Resume();
120 void StopAllSounds();
121 bool GetPaused();
122 void SetMuted(bool value);
123 void ToggleMute();
124 bool IsMuted();
125 void SetMasterVolume(float volume);
126 float GetMasterVolume();
127
128 SAudioInput* CreateAudioCapture(int device = -1, unsigned int frequency = 22050, cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO);
129 void RemoveAudioCapture(SAudioInput* capture);
130
131#if CAUDIO_EFX_ENABLED == 1
132 bool SetFilter(cAudio::FilterTypes type, float lowFreqVolume, float highFreqVolume);
133 bool SetEffect(cAudio::EffectTypes type, std::string preset);
134 bool SetReverbEffectParam(cAudio::sReverbParameters param);
135 bool SetAutowahEffectParam(cAudio::sAutowahParameters param);
136 bool SetChorusEffectParam(cAudio::sChorusParameters param);
137 bool SetCompressorEffectParam(cAudio::sCompressorParameters param);
138 bool SetDistortionEffectParam(cAudio::sDistortionParameters param);
139 bool SetEchoEffectParam(cAudio::sEchoParameters param);
140 bool SetEqualizerEffectParam(cAudio::sEqualizerParameters param);
141 bool SetFlangerEffectParam(cAudio::sFlangerParameters param);
142 bool SetFrequencyShiftEffectParam(cAudio::sFrequencyShiftParameters param);
143 bool SetPitchShifterEffectParam(cAudio::sPitchShifterParameters param);
144 bool SetRingModulatorEffectParam(cAudio::sRingModulatorParameters param);
145 bool SetVocalMorpherEffectParam(cAudio::sVocalMorpherParameters param);
146
147 void AttachSoundEffect(cAudio::IAudioSource* source);
148 void DettachSoundEffect(cAudio::IAudioSource* source);
149 void AttachSoundFilter(cAudio::IAudioSource* source);
150 void DettachSoundFilter(cAudio::IAudioSource* source);
151#endif
152
154 virtual void onInit();
155
157 virtual void onUpdate();
158
160 virtual void onRelease();
161
163 virtual void onSourceCreate();
164
166 virtual void onDecoderRegister();
167
169 virtual void onDataSourceRegister();
170
172 virtual void onDeviceChange();
173
174private:
175 void AddValidSound(SAudioSound* sound);
176 void RemoveValidSound(SAudioSound* sound);
177
178#if CAUDIO_EFX_ENABLED == 1
179 void InitEffects();
180#endif
181
182protected:
183};
184
186{
187public:
188 SAudioInput();
189 SAudioInput(int device = -1, unsigned int frequency = 22050, cAudio::AudioFormats format = cAudio::EAF_8BIT_MONO);
190 ~SAudioInput();
191
192#ifdef ANDROID
193 bool checkRecordAudioPermission();
194#endif
195
196 bool IsValid();
197 bool GetState();
198 void Start();
199 void Stop();
200 size_t GetBuffer(char* destBuffer, size_t length);
201
202 void SetResumeState(bool state);
203 bool GetResumeState();
204
205private:
206 cAudio::IAudioCapture* mAudioCapture;
207 bool mState;
208 bool mValid;
209 bool mResumeState;
210};
211
212class SAudioSound : public cAudio::ISourceEventHandler
213{
214 public:
215 SAudioSound(std::string name, std::string path, bool stream);
216 SAudioSound(std::string name, unsigned int frequency, cAudio::AudioFormats format);
217 ~SAudioSound();
218
219 bool mEffectState;
220 bool mFilterState;
221
222 private:
223 std::string mName;
224 cAudio::IAudioSource* mSound;
225 bool mPlayOnResume;
226 bool mLoopOnResume;
227 bool mLast3dState;
228 bool mIsStream;
229 float mLast3dAttenuation;
230
231 public:
232 bool IsValid();
233 std::string GetName();
234
235 bool Play(bool loop);
236 bool Play3d(float attenuation, bool loop);
237 void Stop();
238 void Pause();
239 void SetVolume(float volume);
240 float GetVolume();
241 bool IsPlaying();
242 bool Is3d();
243 bool IsLoop();
244 bool FillBuffer(const char* &data, const unsigned int &size);
245
246 bool GetLoopOnResume();
247 void SetLoopOnResume(bool state);
248 bool GetPlayOnResume();
249 void SetPlayOnResume(bool playOnResume);
250
251 float Get3DAttenuation();
252 float GetTime();
253 float GetTotalTime();
254 void SetPitch(float pitch);
255 float GetPitch();
256 void Seek(float pos, bool relative);
257
258 // 3D
259 void SetPositionAndDirection(cAudio::cVector3 pos, cAudio::cVector3 dir);
260 cAudio::cVector3 GetPosition();
261 cAudio::cVector3 GetDirection();
262
263 void SetCone(float inner, float outer, float outvol);
264 float GetInnerCone();
265 float GetOuterCone();
266 float GetOuterConeVolume();
267
268 void SetRolloffFactor(float rolloff);
269 float GetRolloffFactor();
270
271#if CAUDIO_EFX_ENABLED == 1
272 void SetEffectState(bool state);
273 void SetFilterState(bool state);
274#endif
275
276 virtual void onUpdate();
277
279 virtual void onRelease();
280
282 virtual void onPlay();
283
285 virtual void onStop();
286
288 virtual void onPause();
289
290 private:
291};
292
293#endif
virtual void onDeviceChange()
This function is called when the default device has change.
Definition audio.cpp:606
virtual void onRelease()
This function is called on manager shutdown.
Definition audio.cpp:586
virtual void onDecoderRegister()
This function is called when an audio decoder is registered.
Definition audio.cpp:596
virtual void onDataSourceRegister()
This function is called when a data source is registered.
Definition audio.cpp:601
virtual void onInit()
This function is called on manager initialization.
Definition audio.cpp:576
virtual void onUpdate()
This function is called on every manager update.
Definition audio.cpp:581
virtual void onSourceCreate()
This function is called on when an audio source is created.
Definition audio.cpp:591
virtual void onRelease()
This function is called when a source is released and soon to be deleted.
Definition audio.cpp:1407
virtual void onStop()
This function is called when a source stopped playback.
Definition audio.cpp:1415
virtual void onPause()
This function is called when a source is paused.
Definition audio.cpp:1421
virtual void onPlay()
This function is called when a source starts playing.
Definition audio.cpp:1411
FILE * pFile
File stream.
Definition audio.h:36
int Filesize
Holds file size.
Definition audio.h:34
bool Valid
Holds if valid
Definition audio.h:32