soloud.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. /*
  2. SoLoud audio engine
  3. Copyright (c) 2013-2020 Jari Komppa
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source
  17. distribution.
  18. */
  19. #ifndef SOLOUD_H
  20. #define SOLOUD_H
  21. #include <stdlib.h> // rand
  22. #include <math.h> // sin
  23. #ifdef SOLOUD_NO_ASSERTS
  24. #define SOLOUD_ASSERT(x)
  25. #else
  26. #ifdef _MSC_VER
  27. #include <stdio.h> // for sprintf in asserts
  28. #ifndef VC_EXTRALEAN
  29. #define VC_EXTRALEAN
  30. #endif
  31. #ifndef WIN32_LEAN_AND_MEAN
  32. #define WIN32_LEAN_AND_MEAN
  33. #endif
  34. #include <windows.h> // only needed for OutputDebugStringA, should be solved somehow.
  35. #define SOLOUD_ASSERT(x) if (!(x)) { char temp[200]; sprintf(temp, "%s(%d): assert(%s) failed.\n", __FILE__, __LINE__, #x); OutputDebugStringA(temp); __debugbreak(); }
  36. #else
  37. #include <assert.h> // assert
  38. #define SOLOUD_ASSERT(x) assert(x)
  39. #endif
  40. #endif
  41. #ifdef WITH_SDL
  42. #undef WITH_SDL2
  43. #undef WITH_SDL1
  44. #define WITH_SDL1
  45. #define WITH_SDL2
  46. #endif
  47. #ifdef WITH_SDL_STATIC
  48. #undef WITH_SDL1_STATIC
  49. #define WITH_SDL1_STATIC
  50. #endif
  51. #ifndef M_PI
  52. #define M_PI 3.14159265359
  53. #endif
  54. #if defined(_WIN32)||defined(_WIN64)
  55. #define WINDOWS_VERSION
  56. #endif
  57. #if !defined(DISABLE_SIMD)
  58. #if defined(__x86_64__) || defined( _M_X64 ) || defined( __i386 ) || defined( _M_IX86 )
  59. #define SOLOUD_SSE_INTRINSICS
  60. #endif
  61. #endif
  62. #define SOLOUD_VERSION 202002
  63. /////////////////////////////////////////////////////////////////////
  64. /////////////////////////////////////////////////////////////////////
  65. // Configuration defines
  66. // Maximum number of filters per stream
  67. #define FILTERS_PER_STREAM 8
  68. // Number of samples to process on one go
  69. #define SAMPLE_GRANULARITY 512
  70. // Maximum number of concurrent voices (hard limit is 4095)
  71. #define VOICE_COUNT 1024
  72. // 1)mono, 2)stereo 4)quad 6)5.1 8)7.1
  73. #define MAX_CHANNELS 8
  74. // Default resampler for both main and bus mixers
  75. #define SOLOUD_DEFAULT_RESAMPLER SoLoud::Soloud::RESAMPLER_LINEAR
  76. //
  77. /////////////////////////////////////////////////////////////////////
  78. /////////////////////////////////////////////////////////////////////
  79. // Typedefs have to be made before the includes, as the
  80. // includes depend on them.
  81. namespace SoLoud
  82. {
  83. class Soloud;
  84. typedef void (*mutexCallFunction)(void *aMutexPtr);
  85. typedef void (*soloudCallFunction)(Soloud *aSoloud);
  86. typedef unsigned int result;
  87. typedef result (*soloudResultFunction)(Soloud *aSoloud);
  88. typedef unsigned int handle;
  89. typedef double time;
  90. };
  91. namespace SoLoud
  92. {
  93. // Class that handles aligned allocations to support vectorized operations
  94. class AlignedFloatBuffer
  95. {
  96. public:
  97. float *mData; // aligned pointer
  98. unsigned char *mBasePtr; // raw allocated pointer (for delete)
  99. int mFloats; // size of buffer (w/out padding)
  100. // ctor
  101. AlignedFloatBuffer();
  102. // Allocate and align buffer
  103. result init(unsigned int aFloats);
  104. // Clear data to zero.
  105. void clear();
  106. // dtor
  107. ~AlignedFloatBuffer();
  108. };
  109. // Lightweight class that handles small aligned buffer to support vectorized operations
  110. class TinyAlignedFloatBuffer
  111. {
  112. public:
  113. float *mData; // aligned pointer
  114. unsigned char mActualData[sizeof(float) * 16 + 16];
  115. // ctor
  116. TinyAlignedFloatBuffer();
  117. };
  118. };
  119. #include "soloud_filter.h"
  120. #include "soloud_fader.h"
  121. #include "soloud_audiosource.h"
  122. #include "soloud_bus.h"
  123. #include "soloud_queue.h"
  124. #include "soloud_error.h"
  125. namespace SoLoud
  126. {
  127. // Soloud core class.
  128. class Soloud
  129. {
  130. public:
  131. // Back-end data; content is up to the back-end implementation.
  132. void * mBackendData;
  133. // Pointer for the audio thread mutex.
  134. void * mAudioThreadMutex;
  135. // Flag for when we're inside the mutex, used for debugging.
  136. bool mInsideAudioThreadMutex;
  137. // Called by SoLoud to shut down the back-end. If NULL, not called. Should be set by back-end.
  138. soloudCallFunction mBackendCleanupFunc;
  139. // Some backends like CoreAudio on iOS must be paused/resumed in some cases. On incoming call as instance.
  140. soloudResultFunction mBackendPauseFunc;
  141. soloudResultFunction mBackendResumeFunc;
  142. // CTor
  143. Soloud();
  144. // DTor
  145. ~Soloud();
  146. enum BACKENDS
  147. {
  148. AUTO = 0,
  149. SDL1,
  150. SDL2,
  151. PORTAUDIO,
  152. WINMM,
  153. XAUDIO2,
  154. WASAPI,
  155. ALSA,
  156. JACK,
  157. OSS,
  158. OPENAL,
  159. COREAUDIO,
  160. OPENSLES,
  161. VITA_HOMEBREW,
  162. MINIAUDIO,
  163. NOSOUND,
  164. NULLDRIVER,
  165. BACKEND_MAX,
  166. };
  167. enum FLAGS
  168. {
  169. // Use round-off clipper
  170. CLIP_ROUNDOFF = 1,
  171. ENABLE_VISUALIZATION = 2,
  172. LEFT_HANDED_3D = 4,
  173. NO_FPU_REGISTER_CHANGE = 8
  174. };
  175. enum WAVEFORM
  176. {
  177. WAVE_SQUARE = 0,
  178. WAVE_SAW,
  179. WAVE_SIN,
  180. WAVE_TRIANGLE,
  181. WAVE_BOUNCE,
  182. WAVE_JAWS,
  183. WAVE_HUMPS,
  184. WAVE_FSQUARE,
  185. WAVE_FSAW
  186. };
  187. enum RESAMPLER
  188. {
  189. RESAMPLER_POINT,
  190. RESAMPLER_LINEAR,
  191. RESAMPLER_CATMULLROM
  192. };
  193. // Initialize SoLoud. Must be called before SoLoud can be used.
  194. result init(unsigned int aFlags = Soloud::CLIP_ROUNDOFF, unsigned int aBackend = Soloud::AUTO, unsigned int aSamplerate = Soloud::AUTO, unsigned int aBufferSize = Soloud::AUTO, unsigned int aChannels = 2);
  195. result pause();
  196. result resume();
  197. // Deinitialize SoLoud. Must be called before shutting down.
  198. void deinit();
  199. // Query SoLoud version number (should equal to SOLOUD_VERSION macro)
  200. unsigned int getVersion() const;
  201. // Translate error number to an asciiz string
  202. const char * getErrorString(result aErrorCode) const;
  203. // Returns current backend ID (BACKENDS enum)
  204. unsigned int getBackendId();
  205. // Returns current backend string. May be NULL.
  206. const char * getBackendString();
  207. // Returns current backend channel count (1 mono, 2 stereo, etc)
  208. unsigned int getBackendChannels();
  209. // Returns current backend sample rate
  210. unsigned int getBackendSamplerate();
  211. // Returns current backend buffer size
  212. unsigned int getBackendBufferSize();
  213. // Set speaker position in 3d space
  214. result setSpeakerPosition(unsigned int aChannel, float aX, float aY, float aZ);
  215. // Get speaker position in 3d space
  216. result getSpeakerPosition(unsigned int aChannel, float &aX, float &aY, float &aZ);
  217. // Start playing a sound. Returns voice handle, which can be ignored or used to alter the playing sound's parameters. Negative volume means to use default.
  218. handle play(AudioSource &aSound, float aVolume = -1.0f, float aPan = 0.0f, bool aPaused = 0, unsigned int aBus = 0);
  219. // Start playing a sound delayed in relation to other sounds called via this function. Negative volume means to use default.
  220. handle playClocked(time aSoundTime, AudioSource &aSound, float aVolume = -1.0f, float aPan = 0.0f, unsigned int aBus = 0);
  221. // Start playing a 3d audio source
  222. handle play3d(AudioSource &aSound, float aPosX, float aPosY, float aPosZ, float aVelX = 0.0f, float aVelY = 0.0f, float aVelZ = 0.0f, float aVolume = 1.0f, bool aPaused = 0, unsigned int aBus = 0);
  223. // Start playing a 3d audio source, delayed in relation to other sounds called via this function.
  224. handle play3dClocked(time aSoundTime, AudioSource &aSound, float aPosX, float aPosY, float aPosZ, float aVelX = 0.0f, float aVelY = 0.0f, float aVelZ = 0.0f, float aVolume = 1.0f, unsigned int aBus = 0);
  225. // Start playing a sound without any panning. It will be played at full volume.
  226. handle playBackground(AudioSource &aSound, float aVolume = -1.0f, bool aPaused = 0, unsigned int aBus = 0);
  227. // Seek the audio stream to certain point in time. Some streams can't seek backwards. Relative play speed affects time.
  228. result seek(handle aVoiceHandle, time aSeconds);
  229. // Stop the sound.
  230. void stop(handle aVoiceHandle);
  231. // Stop all voices.
  232. void stopAll();
  233. // Stop all voices that play this sound source
  234. void stopAudioSource(AudioSource &aSound);
  235. // Count voices that play this audio source
  236. int countAudioSource(AudioSource &aSound);
  237. // Set a live filter parameter. Use 0 for the global filters.
  238. void setFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aValue);
  239. // Get a live filter parameter. Use 0 for the global filters.
  240. float getFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId);
  241. // Fade a live filter parameter. Use 0 for the global filters.
  242. void fadeFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aTo, time aTime);
  243. // Oscillate a live filter parameter. Use 0 for the global filters.
  244. void oscillateFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aFrom, float aTo, time aTime);
  245. // Get current play time, in seconds.
  246. time getStreamTime(handle aVoiceHandle);
  247. // Get current sample position, in seconds.
  248. time getStreamPosition(handle aVoiceHandle);
  249. // Get current pause state.
  250. bool getPause(handle aVoiceHandle);
  251. // Get current volume.
  252. float getVolume(handle aVoiceHandle);
  253. // Get current overall volume (set volume * 3d volume)
  254. float getOverallVolume(handle aVoiceHandle);
  255. // Get current pan.
  256. float getPan(handle aVoiceHandle);
  257. // Get current sample rate.
  258. float getSamplerate(handle aVoiceHandle);
  259. // Get current voice protection state.
  260. bool getProtectVoice(handle aVoiceHandle);
  261. // Get the current number of busy voices.
  262. unsigned int getActiveVoiceCount();
  263. // Get the current number of voices in SoLoud
  264. unsigned int getVoiceCount();
  265. // Check if the handle is still valid, or if the sound has stopped.
  266. bool isValidVoiceHandle(handle aVoiceHandle);
  267. // Get current relative play speed.
  268. float getRelativePlaySpeed(handle aVoiceHandle);
  269. // Get current post-clip scaler value.
  270. float getPostClipScaler() const;
  271. // Get the current main resampler
  272. unsigned int getMainResampler() const;
  273. // Get current global volume
  274. float getGlobalVolume() const;
  275. // Get current maximum active voice setting
  276. unsigned int getMaxActiveVoiceCount() const;
  277. // Query whether a voice is set to loop.
  278. bool getLooping(handle aVoiceHandle);
  279. // Query whether a voice is set to auto-stop when it ends.
  280. bool getAutoStop(handle aVoiceHandle);
  281. // Get voice loop point value
  282. time getLoopPoint(handle aVoiceHandle);
  283. // Set voice loop point value
  284. void setLoopPoint(handle aVoiceHandle, time aLoopPoint);
  285. // Set voice's loop state
  286. void setLooping(handle aVoiceHandle, bool aLooping);
  287. // Set whether sound should auto-stop when it ends
  288. void setAutoStop(handle aVoiceHandle, bool aAutoStop);
  289. // Set current maximum active voice setting
  290. result setMaxActiveVoiceCount(unsigned int aVoiceCount);
  291. // Set behavior for inaudible sounds
  292. void setInaudibleBehavior(handle aVoiceHandle, bool aMustTick, bool aKill);
  293. // Set the global volume
  294. void setGlobalVolume(float aVolume);
  295. // Set the post clip scaler value
  296. void setPostClipScaler(float aScaler);
  297. // Set the main resampler
  298. void setMainResampler(unsigned int aResampler);
  299. // Set the pause state
  300. void setPause(handle aVoiceHandle, bool aPause);
  301. // Pause all voices
  302. void setPauseAll(bool aPause);
  303. // Set the relative play speed
  304. result setRelativePlaySpeed(handle aVoiceHandle, float aSpeed);
  305. // Set the voice protection state
  306. void setProtectVoice(handle aVoiceHandle, bool aProtect);
  307. // Set the sample rate
  308. void setSamplerate(handle aVoiceHandle, float aSamplerate);
  309. // Set panning value; -1 is left, 0 is center, 1 is right
  310. void setPan(handle aVoiceHandle, float aPan);
  311. // Set absolute left/right volumes
  312. void setPanAbsolute(handle aVoiceHandle, float aLVolume, float aRVolume);
  313. // Set channel volume (volume for a specific speaker)
  314. void setChannelVolume(handle aVoiceHandle, unsigned int aChannel, float aVolume);
  315. // Set overall volume
  316. void setVolume(handle aVoiceHandle, float aVolume);
  317. // Set delay, in samples, before starting to play samples. Calling this on a live sound will cause glitches.
  318. void setDelaySamples(handle aVoiceHandle, unsigned int aSamples);
  319. // Set up volume fader
  320. void fadeVolume(handle aVoiceHandle, float aTo, time aTime);
  321. // Set up panning fader
  322. void fadePan(handle aVoiceHandle, float aTo, time aTime);
  323. // Set up relative play speed fader
  324. void fadeRelativePlaySpeed(handle aVoiceHandle, float aTo, time aTime);
  325. // Set up global volume fader
  326. void fadeGlobalVolume(float aTo, time aTime);
  327. // Schedule a stream to pause
  328. void schedulePause(handle aVoiceHandle, time aTime);
  329. // Schedule a stream to stop
  330. void scheduleStop(handle aVoiceHandle, time aTime);
  331. // Set up volume oscillator
  332. void oscillateVolume(handle aVoiceHandle, float aFrom, float aTo, time aTime);
  333. // Set up panning oscillator
  334. void oscillatePan(handle aVoiceHandle, float aFrom, float aTo, time aTime);
  335. // Set up relative play speed oscillator
  336. void oscillateRelativePlaySpeed(handle aVoiceHandle, float aFrom, float aTo, time aTime);
  337. // Set up global volume oscillator
  338. void oscillateGlobalVolume(float aFrom, float aTo, time aTime);
  339. // Set global filters. Set to NULL to clear the filter.
  340. void setGlobalFilter(unsigned int aFilterId, Filter *aFilter);
  341. // Enable or disable visualization data gathering
  342. void setVisualizationEnable(bool aEnable);
  343. // Calculate and get 256 floats of FFT data for visualization. Visualization has to be enabled before use.
  344. float *calcFFT();
  345. // Get 256 floats of wave data for visualization. Visualization has to be enabled before use.
  346. float *getWave();
  347. // Get approximate output volume for a channel for visualization. Visualization has to be enabled before use.
  348. float getApproximateVolume(unsigned int aChannel);
  349. // Get current loop count. Returns 0 if handle is not valid. (All audio sources may not update loop count)
  350. unsigned int getLoopCount(handle aVoiceHandle);
  351. // Get audiosource-specific information from a voice.
  352. float getInfo(handle aVoiceHandle, unsigned int aInfoKey);
  353. // Create a voice group. Returns 0 if unable (out of voice groups / out of memory)
  354. handle createVoiceGroup();
  355. // Destroy a voice group.
  356. result destroyVoiceGroup(handle aVoiceGroupHandle);
  357. // Add a voice handle to a voice group
  358. result addVoiceToGroup(handle aVoiceGroupHandle, handle aVoiceHandle);
  359. // Is this handle a valid voice group?
  360. bool isVoiceGroup(handle aVoiceGroupHandle);
  361. // Is this voice group empty?
  362. bool isVoiceGroupEmpty(handle aVoiceGroupHandle);
  363. // Perform 3d audio parameter update
  364. void update3dAudio();
  365. // Set the speed of sound constant for doppler
  366. result set3dSoundSpeed(float aSpeed);
  367. // Get the current speed of sound constant for doppler
  368. float get3dSoundSpeed();
  369. // Set 3d listener parameters
  370. void set3dListenerParameters(float aPosX, float aPosY, float aPosZ, float aAtX, float aAtY, float aAtZ, float aUpX, float aUpY, float aUpZ, float aVelocityX = 0.0f, float aVelocityY = 0.0f, float aVelocityZ = 0.0f);
  371. // Set 3d listener position
  372. void set3dListenerPosition(float aPosX, float aPosY, float aPosZ);
  373. // Set 3d listener "at" vector
  374. void set3dListenerAt(float aAtX, float aAtY, float aAtZ);
  375. // set 3d listener "up" vector
  376. void set3dListenerUp(float aUpX, float aUpY, float aUpZ);
  377. // Set 3d listener velocity
  378. void set3dListenerVelocity(float aVelocityX, float aVelocityY, float aVelocityZ);
  379. // Set 3d audio source parameters
  380. void set3dSourceParameters(handle aVoiceHandle, float aPosX, float aPosY, float aPosZ, float aVelocityX = 0.0f, float aVelocityY = 0.0f, float aVelocityZ = 0.0f);
  381. // Set 3d audio source position
  382. void set3dSourcePosition(handle aVoiceHandle, float aPosX, float aPosY, float aPosZ);
  383. // Set 3d audio source velocity
  384. void set3dSourceVelocity(handle aVoiceHandle, float aVelocityX, float aVelocityY, float aVelocityZ);
  385. // Set 3d audio source min/max distance (distance < min means max volume)
  386. void set3dSourceMinMaxDistance(handle aVoiceHandle, float aMinDistance, float aMaxDistance);
  387. // Set 3d audio source attenuation parameters
  388. void set3dSourceAttenuation(handle aVoiceHandle, unsigned int aAttenuationModel, float aAttenuationRolloffFactor);
  389. // Set 3d audio source doppler factor to reduce or enhance doppler effect. Default = 1.0
  390. void set3dSourceDopplerFactor(handle aVoiceHandle, float aDopplerFactor);
  391. // Rest of the stuff is used internally.
  392. // Returns mixed float samples in buffer. Called by the back-end, or user with null driver.
  393. void mix(float *aBuffer, unsigned int aSamples);
  394. // Returns mixed 16-bit signed integer samples in buffer. Called by the back-end, or user with null driver.
  395. void mixSigned16(short *aBuffer, unsigned int aSamples);
  396. public:
  397. // Mix N samples * M channels. Called by other mix_ functions.
  398. void mix_internal(unsigned int aSamples, unsigned int aStride);
  399. // Handle rest of initialization (called from backend)
  400. void postinit_internal(unsigned int aSamplerate, unsigned int aBufferSize, unsigned int aFlags, unsigned int aChannels);
  401. // Update list of active voices
  402. void calcActiveVoices_internal();
  403. // Map resample buffers to active voices
  404. void mapResampleBuffers_internal();
  405. // Perform mixing for a specific bus
  406. void mixBus_internal(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize, float *aScratch, unsigned int aBus, float aSamplerate, unsigned int aChannels, unsigned int aResampler);
  407. // Find a free voice, stopping the oldest if no free voice is found.
  408. int findFreeVoice_internal();
  409. // Converts handle to voice, if the handle is valid. Returns -1 if not.
  410. int getVoiceFromHandle_internal(handle aVoiceHandle) const;
  411. // Converts voice + playindex into handle
  412. handle getHandleFromVoice_internal(unsigned int aVoice) const;
  413. // Stop voice (not handle).
  414. void stopVoice_internal(unsigned int aVoice);
  415. // Set voice (not handle) pan.
  416. void setVoicePan_internal(unsigned int aVoice, float aPan);
  417. // Set voice (not handle) relative play speed.
  418. result setVoiceRelativePlaySpeed_internal(unsigned int aVoice, float aSpeed);
  419. // Set voice (not handle) volume.
  420. void setVoiceVolume_internal(unsigned int aVoice, float aVolume);
  421. // Set voice (not handle) pause state.
  422. void setVoicePause_internal(unsigned int aVoice, int aPause);
  423. // Update overall volume from set and 3d volumes
  424. void updateVoiceVolume_internal(unsigned int aVoice);
  425. // Update overall relative play speed from set and 3d speeds
  426. void updateVoiceRelativePlaySpeed_internal(unsigned int aVoice);
  427. // Perform 3d audio calculation for array of voices
  428. void update3dVoices_internal(unsigned int *aVoiceList, unsigned int aVoiceCount);
  429. // Clip the samples in the buffer
  430. void clip_internal(AlignedFloatBuffer &aBuffer, AlignedFloatBuffer &aDestBuffer, unsigned int aSamples, float aVolume0, float aVolume1);
  431. // Remove all non-active voices from group
  432. void trimVoiceGroup_internal(handle aVoiceGroupHandle);
  433. // Get pointer to the zero-terminated array of voice handles in a voice group
  434. handle * voiceGroupHandleToArray_internal(handle aVoiceGroupHandle) const;
  435. // Lock audio thread mutex.
  436. void lockAudioMutex_internal();
  437. // Unlock audio thread mutex.
  438. void unlockAudioMutex_internal();
  439. // Max. number of active voices. Busses and tickable inaudibles also count against this.
  440. unsigned int mMaxActiveVoices;
  441. // Highest voice in use so far
  442. unsigned int mHighestVoice;
  443. // Scratch buffer, used for resampling.
  444. AlignedFloatBuffer mScratch;
  445. // Current size of the scratch, in samples.
  446. unsigned int mScratchSize;
  447. // Output scratch buffer, used in mix_().
  448. AlignedFloatBuffer mOutputScratch;
  449. // Pointers to resampler buffers, two per active voice.
  450. float **mResampleData;
  451. // Actual allocated memory for resampler buffers
  452. AlignedFloatBuffer mResampleDataBuffer;
  453. // Owners of the resample data
  454. AudioSourceInstance **mResampleDataOwner;
  455. // Audio voices.
  456. AudioSourceInstance *mVoice[VOICE_COUNT];
  457. // Resampler for the main bus
  458. unsigned int mResampler;
  459. // Output sample rate (not float)
  460. unsigned int mSamplerate;
  461. // Output channel count
  462. unsigned int mChannels;
  463. // Current backend ID
  464. unsigned int mBackendID;
  465. // Current backend string
  466. const char * mBackendString;
  467. // Maximum size of output buffer; used to calculate needed scratch.
  468. unsigned int mBufferSize;
  469. // Flags; see Soloud::FLAGS
  470. unsigned int mFlags;
  471. // Global volume. Applied before clipping.
  472. float mGlobalVolume;
  473. // Post-clip scaler. Applied after clipping.
  474. float mPostClipScaler;
  475. // Current play index. Used to create audio handles.
  476. unsigned int mPlayIndex;
  477. // Current sound source index. Used to create sound source IDs.
  478. unsigned int mAudioSourceID;
  479. // Fader for the global volume.
  480. Fader mGlobalVolumeFader;
  481. // Global stream time, for the global volume fader.
  482. time mStreamTime;
  483. // Last time seen by the playClocked call
  484. time mLastClockedTime;
  485. // Global filter
  486. Filter *mFilter[FILTERS_PER_STREAM];
  487. // Global filter instance
  488. FilterInstance *mFilterInstance[FILTERS_PER_STREAM];
  489. // Approximate volume for channels.
  490. float mVisualizationChannelVolume[MAX_CHANNELS];
  491. // Mono-mixed wave data for visualization and for visualization FFT input
  492. float mVisualizationWaveData[256];
  493. // FFT output data
  494. float mFFTData[256];
  495. // Snapshot of wave data for visualization
  496. float mWaveData[256];
  497. // 3d listener position
  498. float m3dPosition[3];
  499. // 3d listener look-at
  500. float m3dAt[3];
  501. // 3d listener up
  502. float m3dUp[3];
  503. // 3d listener velocity
  504. float m3dVelocity[3];
  505. // 3d speed of sound (for doppler)
  506. float m3dSoundSpeed;
  507. // 3d position of speakers
  508. float m3dSpeakerPosition[3 * MAX_CHANNELS];
  509. // Data related to 3d processing, separate from AudioSource so we can do 3d calculations without audio mutex.
  510. AudioSourceInstance3dData m3dData[VOICE_COUNT];
  511. // For each voice group, first int is number of ints alocated.
  512. unsigned int **mVoiceGroup;
  513. unsigned int mVoiceGroupCount;
  514. // List of currently active voices
  515. unsigned int mActiveVoice[VOICE_COUNT];
  516. // Number of currently active voices
  517. unsigned int mActiveVoiceCount;
  518. // Active voices list needs to be recalculated
  519. bool mActiveVoiceDirty;
  520. };
  521. };
  522. #endif