-
Notifications
You must be signed in to change notification settings - Fork 2
/
ass.h
2363 lines (1982 loc) · 74.5 KB
/
ass.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ASS - Audio Stupidly Simple
#pragma once
#include <SDL2/SDL.h>
#define WITH_NULL
#define WITH_SDL2 // SDL2
#define WITH_SDL2_STATIC // SDL2
#define WITH_ALSA // asound
#if _WIN32
#define WITH_XAUDIO2
#define WITH_WINMM
#endif
#ifdef __APPLE__
#define WITH_COREAUDIO // AudioToolbox.framework
#endif
/*
SoLoud audio engine
Copyright (c) 2013-2018 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_H
#define SOLOUD_H
#include <stdlib.h> // rand
#include <math.h> // sin
#ifdef SOLOUD_NO_ASSERTS
#define SOLOUD_ASSERT(x)
#else
#ifdef _MSC_VER
#include <stdio.h> // for sprintf in asserts
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#include <windows.h> // only needed for OutputDebugStringA, should be solved somehow.
#define SOLOUD_ASSERT(x) if (!(x)) { char temp[200]; sprintf(temp, "%s(%d): assert(%s) failed.\n", __FILE__, __LINE__, #x); OutputDebugStringA(temp); __debugbreak(); }
#else
#include <assert.h> // assert
#define SOLOUD_ASSERT(x) assert(x)
#endif
#endif
#ifdef WITH_SDL
#undef WITH_SDL2
#undef WITH_SDL1
#define WITH_SDL1
#define WITH_SDL2
#endif
#ifdef WITH_SDL_STATIC
#undef WITH_SDL1_STATIC
#define WITH_SDL1_STATIC
#endif
#ifndef M_PI
#define M_PI 3.14159265359
#endif
#if defined(_WIN32)||defined(_WIN64)
#define WINDOWS_VERSION
#endif
#if !defined(DISABLE_SIMD)
#if defined(__x86_64__) || defined( _M_X64 ) || defined( __i386 ) || defined( _M_IX86 )
#define SOLOUD_SSE_INTRINSICS
#endif
#endif
#define SOLOUD_VERSION 201811
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Configuration defines
// Maximum number of filters per stream
#define FILTERS_PER_STREAM 8
// Number of samples to process on one go
#define SAMPLE_GRANULARITY 512
// Maximum number of concurrent voices (hard limit is 4095)
#define VOICE_COUNT 1024
// Use linear resampler
#define RESAMPLER_LINEAR
// 1)mono, 2)stereo 4)quad 6)5.1 8)7.1
#define MAX_CHANNELS 8
//
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
// Typedefs have to be made before the includes, as the
// includes depend on them.
namespace SoLoud
{
class Soloud;
typedef void (*mutexCallFunction)(void *aMutexPtr);
typedef void (*soloudCallFunction)(Soloud *aSoloud);
typedef unsigned int result;
typedef unsigned int handle;
typedef double time;
};
namespace SoLoud
{
// Class that handles aligned allocations to support vectorized operations
class AlignedFloatBuffer
{
public:
float *mData; // aligned pointer
unsigned char *mBasePtr; // raw allocated pointer (for delete)
int mFloats; // size of buffer (w/out padding)
// ctor
AlignedFloatBuffer();
// Allocate and align buffer
result init(unsigned int aFloats);
// Clear data to zero.
void clear();
// dtor
~AlignedFloatBuffer();
};
// Lightweight class that handles small aligned buffer to support vectorized operations
class TinyAlignedFloatBuffer
{
public:
float *mData; // aligned pointer
unsigned char mActualData[sizeof(float) * 16 + 16];
// ctor
TinyAlignedFloatBuffer();
};
};
// including file: soloud_filter.h
// BEGIN file: #include "soloud_filter.h"
/*
SoLoud audio engine
Copyright (c) 2013-2014 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_FILTER_H
#define SOLOUD_FILTER_H
// #include "soloud.h"
namespace SoLoud
{
class Fader;
class FilterInstance
{
public:
unsigned int mNumParams;
unsigned int mParamChanged;
float *mParam;
Fader *mParamFader;
FilterInstance();
virtual result initParams(int aNumParams);
virtual void updateParams(time aTime);
virtual void filter(float *aBuffer, unsigned int aSamples, unsigned int aChannels, float aSamplerate, time aTime);
virtual void filterChannel(float *aBuffer, unsigned int aSamples, float aSamplerate, time aTime, unsigned int aChannel, unsigned int aChannels);
virtual float getFilterParameter(unsigned int aAttributeId);
virtual void setFilterParameter(unsigned int aAttributeId, float aValue);
virtual void fadeFilterParameter(unsigned int aAttributeId, float aTo, time aTime, time aStartTime);
virtual void oscillateFilterParameter(unsigned int aAttributeId, float aFrom, float aTo, time aTime, time aStartTime);
virtual ~FilterInstance();
};
class Filter
{
public:
Filter();
virtual FilterInstance *createInstance() = 0;
virtual ~Filter();
};
};
#endif
// END file: #include "soloud_filter.h"
// including file: soloud_fader.h
// BEGIN file: #include "soloud_fader.h"
/*
SoLoud audio engine
Copyright (c) 2013-2014 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_FADER_H
#define SOLOUD_FADER_H
// #include "soloud.h"
namespace SoLoud
{
// Helper class to process faders
class Fader
{
public:
// Value to fade from
float mFrom;
// Value to fade to
float mTo;
// Delta between from and to
float mDelta;
// Total time to fade
time mTime;
// Time fading started
time mStartTime;
// Time fading will end
time mEndTime;
// Current value. Used in case time rolls over.
float mCurrent;
// Active flag; 0 means disabled, 1 is active, 2 is LFO, -1 means was active, but stopped
int mActive;
// Ctor
Fader();
// Set up LFO
void setLFO(float aFrom, float aTo, time aTime, time aStartTime);
// Set up fader
void set(float aFrom, float aTo, time aTime, time aStartTime);
// Get the current fading value
float get(time aCurrentTime);
};
};
#endif
// END file: #include "soloud_fader.h"
// including file: soloud_audiosource.h
// BEGIN file: #include "soloud_audiosource.h"
/*
SoLoud audio engine
Copyright (c) 2013-2015 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_AUDIOSOURCE_H
#define SOLOUD_AUDIOSOURCE_H
// #include "soloud.h"
// #include "soloud_fader.h"
// #include "soloud_filter.h"
namespace SoLoud
{
class AudioSource;
class AudioSourceInstance;
class AudioSourceInstance3dData;
class AudioCollider
{
public:
// Calculate volume multiplier. Assumed to return value between 0 and 1.
virtual float collide(Soloud *aSoloud, AudioSourceInstance3dData *aAudioInstance3dData, int aUserData) = 0;
};
class AudioAttenuator
{
public:
virtual float attenuate(float aDistance, float aMinDistance, float aMaxDistance, float aRolloffFactor) = 0;
};
class AudioSourceInstance3dData
{
public:
// ctor
AudioSourceInstance3dData();
// Set settings from audiosource
void init(AudioSource &aSource);
// 3d position
float m3dPosition[3];
// 3d velocity
float m3dVelocity[3];
// 3d cone direction
/*
float m3dConeDirection[3];
// 3d cone inner angle
float m3dConeInnerAngle;
// 3d cone outer angle
float m3dConeOuterAngle;
// 3d cone outer volume multiplier
float m3dConeOuterVolume;
*/
// 3d min distance
float m3dMinDistance;
// 3d max distance
float m3dMaxDistance;
// 3d attenuation rolloff factor
float m3dAttenuationRolloff;
// 3d attenuation model
unsigned int m3dAttenuationModel;
// 3d doppler factor
float m3dDopplerFactor;
// Pointer to a custom audio collider object
AudioCollider *mCollider;
// Pointer to a custom audio attenuator object
AudioAttenuator *mAttenuator;
// User data related to audio collider
int mColliderData;
// Doppler sample rate multiplier
float mDopplerValue;
// Overall 3d volume
float m3dVolume;
// Channel volume
float mChannelVolume[MAX_CHANNELS];
// Copy of flags
unsigned int mFlags;
// Latest handle for this voice
handle mHandle;
};
// Base class for audio instances
class AudioSourceInstance
{
public:
enum FLAGS
{
// This audio instance loops (if supported)
LOOPING = 1,
// This audio instance is protected - won't get stopped if we run out of voices
PROTECTED = 2,
// This audio instance is paused
PAUSED = 4,
// This audio instance is affected by 3d processing
PROCESS_3D = 8,
// This audio instance has listener-relative 3d coordinates
LISTENER_RELATIVE = 16,
// Currently inaudible
INAUDIBLE = 32,
// If inaudible, should be killed (default = don't kill kill)
INAUDIBLE_KILL = 64,
// If inaudible, should still be ticked (default = pause)
INAUDIBLE_TICK = 128
};
// Ctor
AudioSourceInstance();
// Dtor
virtual ~AudioSourceInstance();
// Play index; used to identify instances from handles
unsigned int mPlayIndex;
// Loop count
unsigned int mLoopCount;
// Flags; see AudioSourceInstance::FLAGS
unsigned int mFlags;
// Pan value, for getPan()
float mPan;
// Volume for each channel (panning)
float mChannelVolume[MAX_CHANNELS];
// Set volume
float mSetVolume;
// Overall volume overall = set * 3d
float mOverallVolume;
// Base samplerate; samplerate = base samplerate * relative play speed
float mBaseSamplerate;
// Samplerate; samplerate = base samplerate * relative play speed
float mSamplerate;
// Number of channels this audio source produces
unsigned int mChannels;
// Relative play speed; samplerate = base samplerate * relative play speed
float mSetRelativePlaySpeed;
// Overall relative plays peed; overall = set * 3d
float mOverallRelativePlaySpeed;
// How long this stream has played, in seconds.
time mStreamTime;
// Position of this stream, in seconds.
time mStreamPosition;
// Fader for the audio panning
Fader mPanFader;
// Fader for the audio volume
Fader mVolumeFader;
// Fader for the relative play speed
Fader mRelativePlaySpeedFader;
// Fader used to schedule pausing of the stream
Fader mPauseScheduler;
// Fader used to schedule stopping of the stream
Fader mStopScheduler;
// Affected by some fader
int mActiveFader;
// Current channel volumes, used to ramp the volume changes to avoid clicks
float mCurrentChannelVolume[MAX_CHANNELS];
// ID of the sound source that generated this instance
unsigned int mAudioSourceID;
// Handle of the bus this audio instance is playing on. 0 for root.
unsigned int mBusHandle;
// Filter pointer
FilterInstance *mFilter[FILTERS_PER_STREAM];
// Initialize instance. Mostly internal use.
void init(AudioSource &aSource, int aPlayIndex);
// Buffers for the resampler
AlignedFloatBuffer *mResampleData[2];
// Sub-sample playhead; 16.16 fixed point
unsigned int mSrcOffset;
// Samples left over from earlier pass
unsigned int mLeftoverSamples;
// Number of samples to delay streaming
unsigned int mDelaySamples;
// When looping, start playing from this time
time mLoopPoint;
// Get N samples from the stream to the buffer. Report samples written.
virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize) = 0;
// Has the stream ended?
virtual bool hasEnded() = 0;
// Seek to certain place in the stream. Base implementation is generic "tape" seek (and slow).
virtual result seek(time aSeconds, float *mScratch, unsigned int mScratchSize);
// Rewind stream. Base implementation returns NOT_IMPLEMENTED, meaning it can't rewind.
virtual result rewind();
// Get information. Returns 0 by default.
virtual float getInfo(unsigned int aInfoKey);
};
class Soloud;
// Base class for audio sources
class AudioSource
{
public:
enum FLAGS
{
// The instances from this audio source should loop
SHOULD_LOOP = 1,
// Only one instance of this audio source should play at the same time
SINGLE_INSTANCE = 2,
// Visualization data gathering enabled. Only for busses.
VISUALIZATION_DATA = 4,
// Audio instances created from this source are affected by 3d processing
PROCESS_3D = 8,
// Audio instances created from this source have listener-relative 3d coordinates
LISTENER_RELATIVE = 16,
// Delay start of sound by the distance from listener
DISTANCE_DELAY = 32,
// If inaudible, should be killed (default)
INAUDIBLE_KILL = 64,
// If inaudible, should still be ticked (default = pause)
INAUDIBLE_TICK = 128
};
enum ATTENUATION_MODELS
{
// No attenuation
NO_ATTENUATION = 0,
// Inverse distance attenuation model
INVERSE_DISTANCE = 1,
// Linear distance attenuation model
LINEAR_DISTANCE = 2,
// Exponential distance attenuation model
EXPONENTIAL_DISTANCE = 3
};
// Flags. See AudioSource::FLAGS
unsigned int mFlags;
// Base sample rate, used to initialize instances
float mBaseSamplerate;
// Default volume for created instances
float mVolume;
// Number of channels this audio source produces
unsigned int mChannels;
// Sound source ID. Assigned by SoLoud the first time it's played.
unsigned int mAudioSourceID;
// 3d min distance
float m3dMinDistance;
// 3d max distance
float m3dMaxDistance;
// 3d attenuation rolloff factor
float m3dAttenuationRolloff;
// 3d attenuation model
unsigned int m3dAttenuationModel;
// 3d doppler factor
float m3dDopplerFactor;
// Filter pointer
Filter *mFilter[FILTERS_PER_STREAM];
// Pointer to the Soloud object. Needed to stop all instances in dtor.
Soloud *mSoloud;
// Pointer to a custom audio collider object
AudioCollider *mCollider;
// Pointer to custom attenuator object
AudioAttenuator *mAttenuator;
// User data related to audio collider
int mColliderData;
// When looping, start playing from this time
time mLoopPoint;
// CTor
AudioSource();
// Set default volume for instances
void setVolume(float aVolume);
// Set the looping of the instances created from this audio source
void setLooping(bool aLoop);
// Set whether only one instance of this sound should ever be playing at the same time
void setSingleInstance(bool aSingleInstance);
// Set the minimum and maximum distances for 3d audio source (closer to min distance = max vol)
void set3dMinMaxDistance(float aMinDistance, float aMaxDistance);
// Set attenuation model and rolloff factor for 3d audio source
void set3dAttenuation(unsigned int aAttenuationModel, float aAttenuationRolloffFactor);
// Set doppler factor to reduce or enhance doppler effect, default = 1.0
void set3dDopplerFactor(float aDopplerFactor);
// Set the coordinates for this audio source to be relative to listener's coordinates.
void set3dListenerRelative(bool aListenerRelative);
// Enable delaying the start of the sound based on the distance.
void set3dDistanceDelay(bool aDistanceDelay);
// Set a custom 3d audio collider. Set to NULL to disable.
void set3dCollider(AudioCollider *aCollider, int aUserData = 0);
// Set a custom attenuator. Set to NULL to disable.
void set3dAttenuator(AudioAttenuator *aAttenuator);
// Set behavior for inaudible sounds
void setInaudibleBehavior(bool aMustTick, bool aKill);
// Set time to jump to when looping
void setLoopPoint(time aLoopPoint);
// Get current loop point value
time getLoopPoint();
// Set filter. Set to NULL to clear the filter.
virtual void setFilter(unsigned int aFilterId, Filter *aFilter);
// DTor
virtual ~AudioSource();
// Create instance from the audio source. Called from within Soloud class.
virtual AudioSourceInstance *createInstance() = 0;
// Stop all instances of this audio source
void stop();
};
};
#endif
// END file: #include "soloud_audiosource.h"
// including file: soloud_bus.h
// BEGIN file: #include "soloud_bus.h"
/*
SoLoud audio engine
Copyright (c) 2013-2014 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_BUS_H
#define SOLOUD_BUS_H
// #include "soloud.h"
namespace SoLoud
{
class Bus;
class BusInstance : public AudioSourceInstance
{
Bus *mParent;
unsigned int mScratchSize;
AlignedFloatBuffer mScratch;
public:
// Approximate volume for channels.
float mVisualizationChannelVolume[MAX_CHANNELS];
// Mono-mixed wave data for visualization and for visualization FFT input
float mVisualizationWaveData[256];
BusInstance(Bus *aParent);
virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize);
virtual bool hasEnded();
virtual ~BusInstance();
};
class Bus : public AudioSource
{
public:
Bus();
virtual BusInstance *createInstance();
// Set filter. Set to NULL to clear the filter.
virtual void setFilter(unsigned int aFilterId, Filter *aFilter);
// Play sound through the bus
handle play(AudioSource &aSound, float aVolume = 1.0f, float aPan = 0.0f, bool aPaused = 0);
// Play sound through the bus, delayed in relation to other sounds called via this function.
handle playClocked(time aSoundTime, AudioSource &aSound, float aVolume = 1.0f, float aPan = 0.0f);
// Start playing a 3d audio source through the bus
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);
// Start playing a 3d audio source through the bus, delayed in relation to other sounds called via this function.
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);
// Set number of channels for the bus (default 2)
result setChannels(unsigned int aChannels);
// Enable or disable visualization data gathering
void setVisualizationEnable(bool aEnable);
// Calculate and get 256 floats of FFT data for visualization. Visualization has to be enabled before use.
float *calcFFT();
// Get 256 floats of wave data for visualization. Visualization has to be enabled before use.
float *getWave();
// Get approximate volume for output channel for visualization. Visualization has to be enabled before use.
float getApproximateVolume(unsigned int aChannel);
public:
BusInstance *mInstance;
unsigned int mChannelHandle;
// FFT output data
float mFFTData[256];
// Snapshot of wave data for visualization
float mWaveData[256];
// Internal: find the bus' channel
void findBusHandle();
};
};
#endif
// END file: #include "soloud_bus.h"
// including file: soloud_queue.h
// BEGIN file: #include "soloud_queue.h"
/*
SoLoud audio engine
Copyright (c) 2013-2018 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_QUEUE_H
#define SOLOUD_QUEUE_H
// #include "soloud.h"
#define SOLOUD_QUEUE_MAX 32
namespace SoLoud
{
class Queue;
class QueueInstance : public AudioSourceInstance
{
Queue *mParent;
public:
QueueInstance(Queue *aParent);
virtual unsigned int getAudio(float *aBuffer, unsigned int aSamplesToRead, unsigned int aBufferSize);
virtual bool hasEnded();
virtual ~QueueInstance();
};
class Queue : public AudioSource
{
public:
Queue();
virtual QueueInstance *createInstance();
// Play sound through the queue
result play(AudioSource &aSound);
// Number of audio sources queued for replay
unsigned int getQueueCount();
// Is this audio source currently playing?
bool isCurrentlyPlaying(AudioSource &aSound);
// Set params by reading them from an audio source
result setParamsFromAudioSource(AudioSource &aSound);
// Set params manually
result setParams(float aSamplerate, unsigned int aChannels = 2);
public:
unsigned int mReadIndex, mWriteIndex, mCount;
AudioSourceInstance *mSource[SOLOUD_QUEUE_MAX];
QueueInstance *mInstance;
handle mQueueHandle;
void findQueueHandle();
};
};
#endif
// END file: #include "soloud_queue.h"
// including file: soloud_error.h
// BEGIN file: #include "soloud_error.h"
/*
SoLoud audio engine
Copyright (c) 2013-2014 Jari Komppa
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#ifndef SOLOUD_ERROR_H
#define SOLOUD_ERROR_H
namespace SoLoud
{
enum SOLOUD_ERRORS
{
SO_NO_ERROR = 0, // No error
INVALID_PARAMETER = 1, // Some parameter is invalid
FILE_NOT_FOUND = 2, // File not found
FILE_LOAD_FAILED = 3, // File found, but could not be loaded
DLL_NOT_FOUND = 4, // DLL not found, or wrong DLL
OUT_OF_MEMORY = 5, // Out of memory
NOT_IMPLEMENTED = 6, // Feature not implemented
UNKNOWN_ERROR = 7 // Other error
};
};
#endif
// END file: #include "soloud_error.h"
namespace SoLoud
{
// Soloud core class.
class Soloud
{
public:
// Back-end data; content is up to the back-end implementation.
void * mBackendData;
// Pointer for the audio thread mutex.
void * mAudioThreadMutex;
// Flag for when we're inside the mutex, used for debugging.
bool mInsideAudioThreadMutex;
// Called by SoLoud to shut down the back-end. If NULL, not called. Should be set by back-end.
soloudCallFunction mBackendCleanupFunc;
// CTor
Soloud();
// DTor
~Soloud();
enum BACKENDS
{
AUTO = 0,
SDL1,
SDL2,
PORTAUDIO,
WINMM,
XAUDIO2,
WASAPI,
ALSA,
OSS,
OPENAL,
COREAUDIO,
OPENSLES,
VITA_HOMEBREW,
NULLDRIVER,
BACKEND_MAX,
};
enum FLAGS
{
// Use round-off clipper
CLIP_ROUNDOFF = 1,
ENABLE_VISUALIZATION = 2,
LEFT_HANDED_3D = 4
};
// Initialize SoLoud. Must be called before SoLoud can be used.
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);
// Deinitialize SoLoud. Must be called before shutting down.
void deinit();
// Query SoLoud version number (should equal to SOLOUD_VERSION macro)
unsigned int getVersion() const;
// Translate error number to an asciiz string
const char * getErrorString(result aErrorCode) const;
// Returns current backend ID (BACKENDS enum)
unsigned int getBackendId();
// Returns current backend string. May be NULL.
const char * getBackendString();
// Returns current backend channel count (1 mono, 2 stereo, etc)
unsigned int getBackendChannels();
// Returns current backend sample rate
unsigned int getBackendSamplerate();
// Returns current backend buffer size
unsigned int getBackendBufferSize();
// Set speaker position in 3d space
result setSpeakerPosition(unsigned int aChannel, float aX, float aY, float aZ);
// Get speaker position in 3d space
result getSpeakerPosition(unsigned int aChannel, float &aX, float &aY, float &aZ);
// 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.
handle play(AudioSource &aSound, float aVolume = -1.0f, float aPan = 0.0f, bool aPaused = 0, unsigned int aBus = 0);
// Start playing a sound delayed in relation to other sounds called via this function. Negative volume means to use default.
handle playClocked(time aSoundTime, AudioSource &aSound, float aVolume = -1.0f, float aPan = 0.0f, unsigned int aBus = 0);
// Start playing a 3d audio source
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);
// Start playing a 3d audio source, delayed in relation to other sounds called via this function.
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);
// Start playing a sound without any panning. It will be played at full volume.
handle playBackground(AudioSource &aSound, float aVolume = -1.0f, bool aPaused = 0, unsigned int aBus = 0);
// Seek the audio stream to certain point in time. Some streams can't seek backwards. Relative play speed affects time.
result seek(handle aVoiceHandle, time aSeconds);
// Stop the sound.
void stop(handle aVoiceHandle);
// Stop all voices.
void stopAll();
// Stop all voices that play this sound source
void stopAudioSource(AudioSource &aSound);
// Count voices that play this audio source
int countAudioSource(AudioSource &aSound);
// Set a live filter parameter. Use 0 for the global filters.
void setFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aValue);
// Get a live filter parameter. Use 0 for the global filters.
float getFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId);
// Fade a live filter parameter. Use 0 for the global filters.
void fadeFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aTo, time aTime);
// Oscillate a live filter parameter. Use 0 for the global filters.
void oscillateFilterParameter(handle aVoiceHandle, unsigned int aFilterId, unsigned int aAttributeId, float aFrom, float aTo, time aTime);
// Get current play time, in seconds.
time getStreamTime(handle aVoiceHandle);
// Get current sample position, in seconds.
time getStreamPosition(handle aVoiceHandle);
// Get current pause state.
bool getPause(handle aVoiceHandle);
// Get current volume.
float getVolume(handle aVoiceHandle);
// Get current overall volume (set volume * 3d volume)
float getOverallVolume(handle aVoiceHandle);
// Get current pan.
float getPan(handle aVoiceHandle);
// Get current sample rate.
float getSamplerate(handle aVoiceHandle);
// Get current voice protection state.
bool getProtectVoice(handle aVoiceHandle);
// Get the current number of busy voices.
unsigned int getActiveVoiceCount();
// Get the current number of voices in SoLoud
unsigned int getVoiceCount();
// Check if the handle is still valid, or if the sound has stopped.
bool isValidVoiceHandle(handle aVoiceHandle);
// Get current relative play speed.
float getRelativePlaySpeed(handle aVoiceHandle);
// Get current post-clip scaler value.
float getPostClipScaler() const;
// Get current global volume
float getGlobalVolume() const;
// Get current maximum active voice setting
unsigned int getMaxActiveVoiceCount() const;
// Query whether a voice is set to loop.
bool getLooping(handle aVoiceHandle);
// Get voice loop point value
time getLoopPoint(handle aVoiceHandle);
// Set voice loop point value
void setLoopPoint(handle aVoiceHandle, time aLoopPoint);
// Set voice's loop state
void setLooping(handle aVoiceHandle, bool aLooping);
// Set current maximum active voice setting
result setMaxActiveVoiceCount(unsigned int aVoiceCount);
// Set behavior for inaudible sounds
void setInaudibleBehavior(handle aVoiceHandle, bool aMustTick, bool aKill);
// Set the global volume
void setGlobalVolume(float aVolume);
// Set the post clip scaler value
void setPostClipScaler(float aScaler);
// Set the pause state
void setPause(handle aVoiceHandle, bool aPause);
// Pause all voices
void setPauseAll(bool aPause);
// Set the relative play speed
result setRelativePlaySpeed(handle aVoiceHandle, float aSpeed);
// Set the voice protection state
void setProtectVoice(handle aVoiceHandle, bool aProtect);