18 #if defined(ALURE_STATIC_LIB)
21 #define ALURE_API __declspec(dllimport)
22 #elif defined(__GNUC__) || (defined(__has_attribute) && __has_attribute(visibility))
23 #define ALURE_API __attribute__((visibility("default")))
27 #endif /* ALURE_API */
29 #ifndef EFXEAXREVERBPROPERTIES_DEFINED
30 #define EFXEAXREVERBPROPERTIES_DEFINED
40 float flReflectionsGain
;
41 float flReflectionsDelay
;
42 float flReflectionsPan
[3];
43 float flLateReverbGain
;
44 float flLateReverbDelay
;
45 float flLateReverbPan
[3];
48 float flModulationTime
;
49 float flModulationDepth
;
50 float flAirAbsorptionGainHF
;
53 float flRoomRolloffFactor
;
55 } EFXEAXREVERBPROPERTIES
, *LPEFXEAXREVERBPROPERTIES
;
61 class DeviceManagerImpl
;
73 class SourceGroupImpl
;
74 class AuxiliaryEffectSlot
;
75 class AuxiliaryEffectSlotImpl
;
82 // Convenience aliases
83 template<typename T
> using RemoveRefT
= typename
std::remove_reference
<T
>::type
;
84 template<bool B
> using EnableIfT
= typename
std::enable_if
<B
>::type
;
87 // Duration in seconds, using double precision
88 using Seconds
= std::chrono::duration
<double>;
90 // A SharedPtr implementation, defaults to C++11's std::shared_ptr. If this is
91 // changed, you must recompile the library.
92 template<typename
... Args
> using SharedPtr
= std::shared_ptr
<Args
...>;
93 template<typename T
, typename
... Args
>
94 constexpr inline SharedPtr
<T
> MakeShared(Args
&&... args
)
96 return std::make_shared
<T
>(std::forward
<Args
>(args
)...);
99 // A UniquePtr implementation, defaults to C++11's std::unique_ptr. If this is
100 // changed, you must recompile the library.
101 template<typename
... Args
> using UniquePtr
= std::unique_ptr
<Args
...>;
102 template<typename T
, typename
... Args
>
103 constexpr inline UniquePtr
<T
> MakeUnique(Args
&&... args
)
105 #if __cplusplus >= 201402L
106 return std::make_unique
<T
>(std::forward
<Args
>(args
)...);
108 return std::unique_ptr
<T
>(new T(std::forward
<Args
>(args
)...));
112 // A Promise/Future (+SharedFuture) implementation, defaults to C++11's
113 // std::promise, std::future, and std::shared_future. If this is changed, you
114 // must recompile the library.
115 template<typename
... Args
> using Promise
= std::promise
<Args
...>;
116 template<typename
... Args
> using Future
= std::future
<Args
...>;
117 template<typename
... Args
> using SharedFuture
= std::shared_future
<Args
...>;
119 // A Vector implementation, defaults to C++'s std::vector. If this is changed,
120 // you must recompile the library.
121 template<typename
... Args
> using Vector
= std::vector
<Args
...>;
123 // A static-sized Array implementation, defaults to C++11's std::array. If this
124 // is changed, you must recompile the library.
125 template<typename T
, std::size_t N
> using Array
= std::array
<T
, N
>;
127 // A String implementation, default's to C++'s std::string. If this is changed,
128 // you must recompile the library.
129 template<typename
... Args
> using BasicString
= std::basic_string
<Args
...>;
130 using String
= BasicString
<std::string::value_type
>;
132 // Tag specific containers that guarantee contiguous storage. The standard
133 // provides no such mechanism, so we have to manually specify which are
135 template<typename T
> struct IsContiguousTag
: std::false_type
{};
136 template<typename T
, size_t N
> struct IsContiguousTag
<Array
<T
,N
>> : std::true_type
{};
137 template<typename T
> struct IsContiguousTag
<Vector
<T
>> : std::true_type
{};
138 template<typename T
> struct IsContiguousTag
<BasicString
<T
>> : std::true_type
{};
140 // A rather simple ArrayView container. This allows accepting various array
141 // types (Array, Vector, a static-sized array, a dynamic array + size) without
142 // copying its elements.
146 using value_type
= T
;
148 using iterator
= const value_type
*;
149 using const_iterator
= const value_type
*;
151 using size_type
= size_t;
153 static constexpr size_type npos
= static_cast<size_type
>(-1);
156 const value_type
*mElems
;
160 ArrayView() noexcept
: mElems(nullptr), mNumElems(0) { }
161 ArrayView(const ArrayView
&) noexcept
= default;
162 ArrayView(ArrayView
&&) noexcept
= default;
163 ArrayView(const value_type
*elems
, size_type num_elems
) noexcept
164 : mElems(elems
), mNumElems(num_elems
) { }
165 template<typename OtherT
> ArrayView(RemoveRefT
<OtherT
>&&) = delete;
166 template<typename OtherT
,
167 typename
= EnableIfT
<IsContiguousTag
<RemoveRefT
<OtherT
>>::value
>>
168 ArrayView(const OtherT
&rhs
) noexcept
: mElems(rhs
.data()), mNumElems(rhs
.size()) { }
170 ArrayView(const value_type (&elems
)[N
]) noexcept
: mElems(elems
), mNumElems(N
) { }
172 ArrayView
& operator=(const ArrayView
&) noexcept
= default;
174 const value_type
*data() const noexcept
{ return mElems
; }
176 size_type
size() const noexcept
{ return mNumElems
; }
177 bool empty() const noexcept
{ return mNumElems
== 0; }
179 const value_type
& operator[](size_t i
) const { return mElems
[i
]; }
181 const value_type
& front() const { return mElems
[0]; }
182 const value_type
& back() const { return mElems
[mNumElems
-1]; }
184 const value_type
& at(size_t i
) const
187 throw std::out_of_range("alure::ArrayView::at: element out of range");
191 const_iterator
begin() const noexcept
{ return mElems
; }
192 const_iterator
cbegin() const noexcept
{ return mElems
; }
194 const_iterator
end() const noexcept
{ return mElems
+ mNumElems
; }
195 const_iterator
cend() const noexcept
{ return mElems
+ mNumElems
; }
197 ArrayView
slice(size_type pos
, size_type len
= npos
) const noexcept
200 return ArrayView(data()+size(), 0);
201 if(len
== npos
|| size()-pos
>= len
)
202 return ArrayView(data()+pos
, size()-pos
);
203 return ArrayView(data()+pos
, len
);
207 template<typename T
, typename Tr
=std::char_traits
<T
>>
208 class BasicStringView
: public ArrayView
<T
> {
209 using BaseT
= ArrayView
<T
>;
210 using StringT
= BasicString
<T
,Tr
>;
213 using typename
BaseT::value_type
;
214 using typename
BaseT::size_type
;
216 using traits_type
= Tr
;
218 BasicStringView() noexcept
= default;
219 BasicStringView(const BasicStringView
&) noexcept
= default;
220 BasicStringView(const value_type
*elems
, size_type num_elems
) noexcept
221 : ArrayView
<T
>(elems
, num_elems
) { }
222 BasicStringView(const value_type
*elems
) : ArrayView
<T
>(elems
, std::strlen(elems
)) { }
223 BasicStringView(StringT
&&) = delete;
224 BasicStringView(const StringT
&rhs
) noexcept
: ArrayView
<T
>(rhs
) { }
225 #if __cplusplus >= 201703L
226 BasicStringView(const std::basic_string_view
<T
> &rhs
) noexcept
227 : ArrayView
<T
>(rhs
.data(), rhs
.length()) { }
230 BasicStringView
& operator=(const BasicStringView
&) noexcept
= default;
232 size_type
length() const { return BaseT::size(); }
234 explicit operator StringT() const { return StringT(BaseT::data(), length()); }
235 #if __cplusplus >= 201703L
236 operator std::basic_string_view
<T
,Tr
>() const noexcept
237 { return std::basic_string_view
<T
,Tr
>(BaseT::data(), length()); }
240 StringT
operator+(const StringT
&rhs
) const
242 StringT ret
= StringT(*this);
246 StringT
operator+(const typename
StringT::value_type
*rhs
) const
248 StringT ret
= StringT(*this);
253 int compare(BasicStringView other
) const noexcept
255 int ret
= traits_type::compare(
256 BaseT::data(), other
.data(), std::min
<size_t>(length(), other
.length())
260 if(length() > other
.length()) return 1;
261 if(length() < other
.length()) return -1;
266 bool operator==(BasicStringView rhs
) const noexcept
{ return compare(rhs
) == 0; }
267 bool operator!=(BasicStringView rhs
) const noexcept
{ return compare(rhs
) != 0; }
268 bool operator<=(BasicStringView rhs
) const noexcept
{ return compare(rhs
) <= 0; }
269 bool operator>=(BasicStringView rhs
) const noexcept
{ return compare(rhs
) >= 0; }
270 bool operator<(BasicStringView rhs
) const noexcept
{ return compare(rhs
) < 0; }
271 bool operator>(BasicStringView rhs
) const noexcept
{ return compare(rhs
) > 0; }
273 BasicStringView
substr(size_type pos
, size_type len
= npos
) const noexcept
274 { return BaseT::slice(pos
, len
); }
276 using StringView
= BasicStringView
<String::value_type
>;
278 // Inline operators to concat String and C-style strings with StringViews.
279 template<typename T
, typename Tr
>
280 inline BasicString
<T
,Tr
> operator+(const BasicString
<T
,Tr
> &lhs
, BasicStringView
<T
,Tr
> rhs
)
281 { return BasicString
<T
,Tr
>(lhs
).append(rhs
.data(), rhs
.size()); }
282 template<typename T
, typename Tr
>
283 inline BasicString
<T
,Tr
> operator+(BasicString
<T
,Tr
> lhs
, BasicStringView
<T
,Tr
> rhs
)
284 { return std::move(lhs
.append(rhs
.data(), rhs
.size())); }
285 template<typename T
, typename Tr
>
286 inline BasicString
<T
,Tr
> operator+(const typename BasicString
<T
,Tr
>::value_type
*lhs
, BasicStringView
<T
,Tr
> rhs
)
287 { return lhs
+ BasicString
<T
,Tr
>(rhs
); }
288 template<typename T
, typename Tr
>
289 inline BasicString
<T
,Tr
>& operator+=(BasicString
<T
,Tr
> &lhs
, BasicStringView
<T
,Tr
> rhs
)
290 { return lhs
.append(rhs
.data(), rhs
.size()); }
292 // Inline operators to compare String and C-style strings with StringViews.
293 #define ALURE_DECL_STROP(op) \
294 template<typename T, typename Tr> \
295 inline bool operator op(const BasicString<T,Tr> &lhs, BasicStringView<T,Tr> rhs) \
296 { return BasicStringView<T,Tr>(lhs) op rhs; } \
297 template<typename T, typename Tr> \
298 inline bool operator op(const typename BasicString<T,Tr>::value_type *lhs, \
299 BasicStringView<T,Tr> rhs) \
300 { return BasicStringView<T,Tr>(lhs) op rhs; }
307 #undef ALURE_DECL_STROP
309 // Inline operator to write out a StringView to an ostream
310 template<typename T
, typename Tr
>
311 inline std::basic_ostream
<T
>& operator<<(std::basic_ostream
<T
,Tr
> &lhs
, BasicStringView
<T
,Tr
> rhs
)
320 * An attribute pair, for passing attributes to Device::createContext and
323 using AttributePair
= std::pair
<ALCint
,ALCint
>;
324 static_assert(sizeof(AttributePair
) == sizeof(ALCint
[2]), "Bad AttributePair size");
327 struct FilterParams
{
329 ALfloat mGainHF
; // For low-pass and band-pass filters
330 ALfloat mGainLF
; // For high-pass and band-pass filters
335 Array
<ALfloat
,3> mValue
;
338 constexpr Vector3() noexcept
339 : mValue
{{0.0f
, 0.0f
, 0.0f
}}
341 constexpr Vector3(const Vector3
&rhs
) noexcept
342 : mValue
{{rhs
.mValue
[0], rhs
.mValue
[1], rhs
.mValue
[2]}}
344 constexpr Vector3(ALfloat val
) noexcept
345 : mValue
{{val
, val
, val
}}
347 constexpr Vector3(ALfloat x
, ALfloat y
, ALfloat z
) noexcept
350 Vector3(const ALfloat
*vec
) noexcept
351 : mValue
{{vec
[0], vec
[1], vec
[2]}}
354 const ALfloat
*getPtr() const noexcept
355 { return mValue
.data(); }
357 ALfloat
& operator[](size_t i
) noexcept
358 { return mValue
[i
]; }
359 constexpr const ALfloat
& operator[](size_t i
) const noexcept
360 { return mValue
[i
]; }
362 #define ALURE_DECL_OP(op) \
363 constexpr Vector3 operator op(const Vector3 &rhs) const noexcept \
365 return Vector3(mValue[0] op rhs.mValue[0], \
366 mValue[1] op rhs.mValue[1], \
367 mValue[2] op rhs.mValue[2]); \
374 #define ALURE_DECL_OP(op) \
375 Vector3& operator op(const Vector3 &rhs) noexcept \
377 mValue[0] op rhs.mValue[0]; \
378 mValue[1] op rhs.mValue[1]; \
379 mValue[2] op rhs.mValue[2]; \
388 #define ALURE_DECL_OP(op) \
389 constexpr Vector3 operator op(ALfloat scale) const noexcept \
391 return Vector3(mValue[0] op scale, \
392 mValue[1] op scale, \
393 mValue[2] op scale); \
398 #define ALURE_DECL_OP(op) \
399 Vector3& operator op(ALfloat scale) noexcept \
401 mValue[0] op scale; \
402 mValue[1] op scale; \
403 mValue[2] op scale; \
410 constexpr ALfloat
getLengthSquared() const noexcept
411 { return mValue
[0]*mValue
[0] + mValue
[1]*mValue
[1] + mValue
[2]*mValue
[2]; }
412 ALfloat
getLength() const noexcept
413 { return std::sqrt(getLengthSquared()); }
415 constexpr ALfloat
getDistanceSquared(const Vector3
&pos
) const noexcept
416 { return (pos
- *this).getLengthSquared(); }
417 ALfloat
getDistance(const Vector3
&pos
) const noexcept
418 { return (pos
- *this).getLength(); }
420 static_assert(sizeof(Vector3
) == sizeof(ALfloat
[3]), "Bad Vector3 size");
423 enum class SampleType
{
429 ALURE_API
const char *GetSampleTypeName(SampleType type
);
431 enum class ChannelConfig
{
432 /** 1-channel mono sound. */
434 /** 2-channel stereo sound. */
436 /** 2-channel rear sound (back-left and back-right). */
438 /** 4-channel surround sound. */
440 /** 5.1 surround sound. */
442 /** 6.1 surround sound. */
444 /** 7.1 surround sound. */
446 /** 3-channel B-Format, using FuMa channel ordering and scaling. */
448 /** 4-channel B-Format, using FuMa channel ordering and scaling. */
451 ALURE_API
const char *GetChannelConfigName(ChannelConfig cfg
);
453 ALURE_API ALuint
FramesToBytes(ALuint frames
, ChannelConfig chans
, SampleType type
);
454 ALURE_API ALuint
BytesToFrames(ALuint bytes
, ChannelConfig chans
, SampleType type
);
457 /** Class for storing a major.minor version number. */
463 constexpr Version(ALuint _maj
, ALuint _min
) : mMajor(_maj
), mMinor(_min
) { }
465 constexpr ALuint
getMajor() const noexcept
{ return mMajor
; }
466 constexpr ALuint
getMinor() const noexcept
{ return mMinor
; }
467 constexpr bool isZero() const noexcept
{ return mMajor
== 0 && mMinor
== 0; }
470 #define MAKE_PIMPL(BaseT, ImplT) \
475 using handle_type = ImplT*; \
477 BaseT() : pImpl(nullptr) { } \
478 BaseT(ImplT *impl) : pImpl(impl) { } \
479 BaseT(const BaseT&) = default; \
480 BaseT(BaseT&& rhs) : pImpl(rhs.pImpl) { rhs.pImpl = nullptr; } \
482 BaseT& operator=(const BaseT&) = default; \
483 BaseT& operator=(BaseT&& rhs) \
485 pImpl = rhs.pImpl; rhs.pImpl = nullptr; \
489 bool operator==(const BaseT &rhs) const { return pImpl == rhs.pImpl; } \
490 bool operator==(BaseT&& rhs) const { return pImpl == rhs.pImpl; } \
492 operator bool() const { return !!pImpl; } \
494 handle_type getHandle() const { return pImpl; }
496 enum class DeviceEnumeration
{
497 Basic
= ALC_DEVICE_SPECIFIER
,
498 Full
= ALC_ALL_DEVICES_SPECIFIER
,
499 Capture
= ALC_CAPTURE_DEVICE_SPECIFIER
502 enum class DefaultDeviceType
{
503 Basic
= ALC_DEFAULT_DEVICE_SPECIFIER
,
504 Full
= ALC_DEFAULT_ALL_DEVICES_SPECIFIER
,
505 Capture
= ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
509 * A class managing Device objects and other related functionality. This class
510 * is a singleton, only one instance will exist in a process.
512 class ALURE_API DeviceManager
{
513 DeviceManagerImpl
*pImpl
;
515 DeviceManager(DeviceManagerImpl
*impl
) : pImpl(impl
) { }
516 friend class ALDeviceManager
;
519 DeviceManager(const DeviceManager
&) = default;
520 DeviceManager(DeviceManager
&& rhs
) : pImpl(rhs
.pImpl
) { }
522 /** Retrieves the DeviceManager instance. */
523 static DeviceManager
get();
525 /** Queries the existence of a non-device-specific ALC extension. */
526 bool queryExtension(const String
&name
) const;
527 bool queryExtension(const char *name
) const;
529 /** Enumerates available device names of the given type. */
530 Vector
<String
> enumerate(DeviceEnumeration type
) const;
531 /** Retrieves the default device of the given type. */
532 String
defaultDeviceName(DefaultDeviceType type
) const;
535 * Opens the playback device given by name, or the default if blank. Throws
536 * an exception on error.
538 Device
openPlayback(const String
&name
=String());
539 Device
openPlayback(const char *name
);
542 * Opens the playback device given by name, or the default if blank.
543 * Returns an empty Device on error.
545 Device
openPlayback(const String
&name
, const std::nothrow_t
&);
546 Device
openPlayback(const char *name
, const std::nothrow_t
&);
548 /** Opens the default playback device. Returns an empty Device on error. */
549 Device
openPlayback(const std::nothrow_t
&);
553 enum class PlaybackName
{
554 Basic
= ALC_DEVICE_SPECIFIER
,
555 Full
= ALC_ALL_DEVICES_SPECIFIER
558 class ALURE_API Device
{
559 MAKE_PIMPL(Device
, DeviceImpl
)
562 /** Retrieves the device name as given by type. */
563 String
getName(PlaybackName type
=PlaybackName::Full
) const;
564 /** Queries the existence of an ALC extension on this device. */
565 bool queryExtension(const String
&name
) const;
566 bool queryExtension(const char *name
) const;
568 /** Retrieves the ALC version supported by this device. */
569 Version
getALCVersion() const;
572 * Retrieves the EFX version supported by this device. If the ALC_EXT_EFX
573 * extension is unsupported, this will be 0.0.
575 Version
getEFXVersion() const;
577 /** Retrieves the device's playback frequency, in hz. */
578 ALCuint
getFrequency() const;
581 * Retrieves the maximum number of auxiliary source sends. If ALC_EXT_EFX
582 * is unsupported, this will be 0.
584 ALCuint
getMaxAuxiliarySends() const;
587 * Enumerates available HRTF names. The names are sorted as OpenAL gives
588 * them, such that the index of a given name is the ID to use with
591 * Requires the ALC_SOFT_HRTF extension.
593 Vector
<String
> enumerateHRTFNames() const;
596 * Retrieves whether HRTF is enabled on the device or not.
598 * Requires the ALC_SOFT_HRTF extension.
600 bool isHRTFEnabled() const;
603 * Retrieves the name of the HRTF currently being used by this device.
605 * Requires the ALC_SOFT_HRTF extension.
607 String
getCurrentHRTF() const;
610 * Resets the device, using the specified attributes.
612 * Requires the ALC_SOFT_HRTF extension.
614 void reset(ArrayView
<AttributePair
> attributes
);
617 * Creates a new Context on this device, using the specified attributes.
619 Context
createContext(ArrayView
<AttributePair
> attributes
=ArrayView
<AttributePair
>());
622 * Pauses device processing, stopping updates for its contexts. Multiple
623 * calls are allowed but it is not reference counted, so the device will
624 * resume after one resumeDSP call.
626 * Requires the ALC_SOFT_pause_device extension.
631 * Resumes device processing, restarting updates for its contexts. Multiple
632 * calls are allowed and will no-op.
637 * Closes and frees the device. All previously-created contexts must first
644 enum class DistanceModel
{
645 InverseClamped
= AL_INVERSE_DISTANCE_CLAMPED
,
646 LinearClamped
= AL_LINEAR_DISTANCE_CLAMPED
,
647 ExponentClamped
= AL_EXPONENT_DISTANCE_CLAMPED
,
648 Inverse
= AL_INVERSE_DISTANCE
,
649 Linear
= AL_LINEAR_DISTANCE
,
650 Exponent
= AL_EXPONENT_DISTANCE
,
654 class ALURE_API Context
{
655 MAKE_PIMPL(Context
, ContextImpl
)
658 /** Makes the specified context current for OpenAL operations. */
659 static void MakeCurrent(Context context
);
660 /** Retrieves the current context used for OpenAL operations. */
661 static Context
GetCurrent();
664 * Makes the specified context current for OpenAL operations on the calling
665 * thread only. Requires the ALC_EXT_thread_local_context extension on both
666 * the context's device and the DeviceManager.
668 static void MakeThreadCurrent(Context context
);
669 /** Retrieves the thread-specific context used for OpenAL operations. */
670 static Context
GetThreadCurrent();
673 * Destroys the context. The context must not be current when this is
678 /** Retrieves the Device this context was created from. */
685 * Retrieves a Listener instance for this context. Each context will only
686 * have one listener, which is automatically destroyed with the context.
688 Listener
getListener();
691 * Sets a MessageHandler instance which will be used to provide certain
692 * messages back to the application. Only one handler may be set for a
693 * context at a time. The previously set handler will be returned.
695 SharedPtr
<MessageHandler
> setMessageHandler(SharedPtr
<MessageHandler
> handler
);
697 /** Gets the currently-set message handler. */
698 SharedPtr
<MessageHandler
> getMessageHandler() const;
701 * Specifies the desired interval that the background thread will be woken
702 * up to process tasks, e.g. keeping streaming sources filled. An interval
703 * of 0 means the background thread will only be woken up manually with
704 * calls to update. The default is 0.
706 void setAsyncWakeInterval(std::chrono::milliseconds interval
);
709 * Retrieves the current interval used for waking up the background thread.
711 std::chrono::milliseconds
getAsyncWakeInterval() const;
713 // Functions below require the context to be current
716 * Creates a Decoder instance for the given audio file or resource name.
718 SharedPtr
<Decoder
> createDecoder(StringView name
);
721 * Queries if the channel configuration and sample type are supported by
724 bool isSupported(ChannelConfig channels
, SampleType type
) const;
727 * Queries the list of resamplers supported by the context. If the
728 * AL_SOFT_source_resampler extension is unsupported this will be an empty
729 * array, otherwise there will be at least one entry.
731 ArrayView
<String
> getAvailableResamplers();
733 * Queries the context's default resampler index. Be aware, if the
734 * AL_SOFT_source_resampler extension is unsupported the resampler list
735 * will be empty and this will resturn 0. If you try to access the
736 * resampler list with this index without the extension, undefined behavior
737 * will occur (accessing an out of bounds array index).
739 ALsizei
getDefaultResamplerIndex() const;
742 * Creates and caches a Buffer for the given audio file or resource name.
743 * Multiple calls with the same name will return the same Buffer object.
744 * Cached buffers must be freed using removeBuffer before destroying the
745 * context. If the buffer can't be loaded it will throw an exception.
747 Buffer
getBuffer(StringView name
);
750 * Asynchronously prepares a cached Buffer for the given audio file or
751 * resource name. Multiple calls with the same name will return multiple
752 * SharedFutures for the same Buffer object. Once called, the buffer must
753 * be freed using removeBuffer before destroying the context, even if you
754 * never get the Buffer from the SharedFuture.
756 * The Buffer will be scheduled to load asynchronously, and the caller gets
757 * back a SharedFuture that can be checked later (or waited on) to get the
758 * actual Buffer when it's ready. The application must take care to handle
759 * exceptions from the SharedFuture in case an unrecoverable error ocurred
762 SharedFuture
<Buffer
> getBufferAsync(StringView name
);
765 * Asynchronously prepares cached Buffers for the given audio file or
766 * resource names. Duplicate names and buffers already cached are ignored.
767 * Cached buffers must be freed using removeBuffer before destroying the
770 * The Buffer objects will be scheduled for loading asynchronously, and
771 * should be retrieved later when needed using getBufferAsync or getBuffer.
772 * Buffers that cannot be loaded, for example due to an unsupported format,
773 * will be ignored and a later call to getBuffer or getBufferAsync will
774 * throw an exception.
776 * Note that you should avoid trying to asynchronously cache more than 16
777 * buffers at a time. The internal ringbuffer used to communicate with the
778 * background thread can only hold 16 async load requests, and trying to
779 * add more will cause the call to stall until the background thread
780 * completes some loads for more to be filled in.
782 void precacheBuffersAsync(ArrayView
<StringView
> names
);
785 * Creates and caches a Buffer using the given name. The name may alias an
786 * audio file, but it must not currently exist in the buffer cache.
788 Buffer
createBufferFrom(StringView name
, SharedPtr
<Decoder
> decoder
);
791 * Asynchronously prepares a cached Buffer using the given name. The name
792 * may alias an audio file, but it must not currently exist in the buffer
793 * cache. Once called, the buffer must be freed using removeBuffer before
794 * destroying the context, even if you never get the Buffer from the
797 * The Buffer will be scheduled to load asynchronously, and the caller gets
798 * back a SharedFuture that can be checked later (or waited on) to get the
799 * actual Buffer when it's ready. The application must take care to handle
800 * exceptions from the SharedFuture in case an unrecoverable error ocurred
801 * during the load. The decoder must not have its read or seek methods
802 * called while the buffer is not ready.
804 SharedFuture
<Buffer
> createBufferAsyncFrom(StringView name
, SharedPtr
<Decoder
> decoder
);
807 * Deletes the cached Buffer object for the given audio file or resource
808 * name. The buffer must not be in use by a Source.
810 void removeBuffer(StringView name
);
812 * Deletes the given cached buffer. The buffer must not be in use by a
815 void removeBuffer(Buffer buffer
);
818 * Creates a new Source. There is no practical limit to the number of
819 * sources you may create. You must call Source::release when the source is
822 Source
createSource();
824 AuxiliaryEffectSlot
createAuxiliaryEffectSlot();
826 Effect
createEffect();
828 SourceGroup
createSourceGroup(StringView name
);
829 SourceGroup
getSourceGroup(StringView name
);
831 /** Sets the doppler factor to apply to all source calculations. */
832 void setDopplerFactor(ALfloat factor
);
835 * Sets the speed of sound propagation, in units per second, to calculate
836 * the doppler effect along with other distance-related time effects. The
837 * default is 343.3 units per second (a realistic speed assuming 1 meter
838 * per unit). If this is adjusted for a different unit scale,
839 * Listener::setMetersPerUnit should also be adjusted.
841 void setSpeedOfSound(ALfloat speed
);
843 void setDistanceModel(DistanceModel model
);
845 /** Updates the context and all sources belonging to this context. */
849 class ALURE_API Listener
{
850 MAKE_PIMPL(Listener
, ListenerImpl
)
853 /** Sets the "master" gain for all context output. */
854 void setGain(ALfloat gain
);
857 * Specifies the listener's 3D position, velocity, and orientation
860 void set3DParameters(const Vector3
&position
, const Vector3
&velocity
, std::pair
<Vector3
,Vector3
> orientation
);
862 /** Specifies the listener's 3D position. */
863 void setPosition(ALfloat x
, ALfloat y
, ALfloat z
);
864 void setPosition(const ALfloat
*pos
);
867 * Specifies the listener's 3D velocity, in units per second. As with
868 * OpenAL, this does not actually alter the listener's position, and
869 * instead just alters the pitch as determined by the doppler effect.
871 void setVelocity(ALfloat x
, ALfloat y
, ALfloat z
);
872 void setVelocity(const ALfloat
*vel
);
875 * Specifies the listener's 3D orientation, using position-relative 'at'
876 * and 'up' direction vectors.
878 void setOrientation(ALfloat x1
, ALfloat y1
, ALfloat z1
, ALfloat x2
, ALfloat y2
, ALfloat z2
);
879 void setOrientation(const ALfloat
*at
, const ALfloat
*up
);
880 void setOrientation(const ALfloat
*ori
);
883 * Sets the number of meters per unit, used for various effects that rely
884 * on the distance in meters (including air absorption and initial reverb
885 * decay). If this is changed, it's strongly recommended to also set the
886 * speed of sound (e.g. context.setSpeedOfSound(343.3 / m_u) to maintain a
887 * realistic 343.3m/s for sound propagation).
889 void setMetersPerUnit(ALfloat m_u
);
893 class ALURE_API Buffer
{
894 MAKE_PIMPL(Buffer
, BufferImpl
)
897 /** Retrieves the length of the buffer in sample frames. */
898 ALuint
getLength() const;
900 /** Retrieves the buffer's frequency in hz. */
901 ALuint
getFrequency() const;
903 /** Retrieves the buffer's sample configuration. */
904 ChannelConfig
getChannelConfig() const;
906 /** Retrieves the buffer's sample type. */
907 SampleType
getSampleType() const;
909 /** Retrieves the storage size used by the buffer, in bytes. */
910 ALuint
getSize() const;
913 * Sets the buffer's loop points, used for looping sources. If the current
914 * context does not support the AL_SOFT_loop_points extension, start and
915 * end must be 0 and getLength() respectively. Otherwise, start must be
916 * less than end, and end must be less than or equal to getLength().
918 * The buffer must not be in use when this method is called.
920 * \param start The starting point, in sample frames (inclusive).
921 * \param end The ending point, in sample frames (exclusive).
923 void setLoopPoints(ALuint start
, ALuint end
);
925 /** Retrieves the current loop points as a [start,end) pair. */
926 std::pair
<ALuint
,ALuint
> getLoopPoints() const;
929 * Retrieves the Source objects currently playing the buffer. Stopping the
930 * returned sources will allow the buffer to be removed from the context.
932 Vector
<Source
> getSources() const;
934 /** Retrieves the name the buffer was created with. */
935 const String
&getName() const;
937 /** Queries if the buffer is in use and can't be removed. */
938 bool isInUse() const;
942 enum class Spatialize
{
945 Auto
= 0x0002 /* AL_AUTO_SOFT */
948 class ALURE_API Source
{
949 MAKE_PIMPL(Source
, SourceImpl
)
953 * Plays the source using buffer. The same buffer may be played from
954 * multiple sources simultaneously.
956 void play(Buffer buffer
);
958 * Plays the source by streaming audio from decoder. This will use
959 * queuesize buffers, each with updatelen sample frames. The given decoder
960 * must *NOT* have its read or seek methods called from elsewhere while in
963 void play(SharedPtr
<Decoder
> decoder
, ALuint updatelen
, ALuint queuesize
);
964 /** Stops playback, releasing the buffer or decoder reference. */
967 /** Pauses the source if it is playing. */
970 /** Resumes the source if it is paused. */
973 /** Specifies if the source is currently playing. */
974 bool isPlaying() const;
976 /** Specifies if the source is currently paused. */
977 bool isPaused() const;
980 * Specifies the source's playback priority. Lowest priority sources will
981 * be evicted first when higher priority sources are played.
983 void setPriority(ALuint priority
);
984 /** Retrieves the source's priority. */
985 ALuint
getPriority() const;
988 * Sets the source's offset, in sample frames. If the source is playing or
989 * paused, it will go to that offset immediately, otherwise the source will
990 * start at the specified offset the next time it's played.
992 void setOffset(uint64_t offset
);
994 * Retrieves the source offset in sample frames and its latency in nano-
995 * seconds. For streaming sources this will be the offset based on the
996 * decoder's read position.
998 * If the AL_SOFT_source_latency extension is unsupported, the latency will
1001 std::pair
<uint64_t,std::chrono::nanoseconds
> getSampleOffsetLatency() const;
1002 uint64_t getSampleOffset() const { return std::get
<0>(getSampleOffsetLatency()); }
1004 * Retrieves the source offset and latency in seconds. For streaming
1005 * sources this will be the offset based on the decoder's read position.
1007 * If the AL_SOFT_source_latency extension is unsupported, the latency will
1010 std::pair
<Seconds
,Seconds
> getSecOffsetLatency() const;
1011 Seconds
getSecOffset() const { return std::get
<0>(getSecOffsetLatency()); }
1014 * Specifies if the source should loop on the Buffer or Decoder object's
1017 void setLooping(bool looping
);
1018 bool getLooping() const;
1021 * Specifies a linear pitch shift base. A value of 1.0 is the default
1024 void setPitch(ALfloat pitch
);
1025 ALfloat
getPitch() const;
1028 * Specifies the base linear gain. A value of 1.0 is the default normal
1031 void setGain(ALfloat gain
);
1032 ALfloat
getGain() const;
1035 * Specifies the minimum and maximum gain. The source's gain is clamped to
1036 * this range after distance attenuation and cone attenuation are applied
1037 * to the gain base, although before the filter gain adjustements.
1039 void setGainRange(ALfloat mingain
, ALfloat maxgain
);
1040 std::pair
<ALfloat
,ALfloat
> getGainRange() const;
1041 ALfloat
getMinGain() const { return std::get
<0>(getGainRange()); }
1042 ALfloat
getMaxGain() const { return std::get
<1>(getGainRange()); }
1045 * Specifies the reference distance and maximum distance the source will
1046 * use for the current distance model. For Clamped distance models, the
1047 * source's calculated distance is clamped to the specified range before
1048 * applying distance-related attenuation.
1050 * For all distance models, the reference distance is the distance at which
1051 * the source's volume will not have any extra attenuation (an effective
1052 * gain multiplier of 1).
1054 void setDistanceRange(ALfloat refdist
, ALfloat maxdist
);
1055 std::pair
<ALfloat
,ALfloat
> getDistanceRange() const;
1056 ALfloat
getReferenceDistance() const { return std::get
<0>(getDistanceRange()); }
1057 ALfloat
getMaxDistance() const { return std::get
<1>(getDistanceRange()); }
1059 /** Specifies the source's 3D position, velocity, and direction together. */
1060 void set3DParameters(const Vector3
&position
, const Vector3
&velocity
, const Vector3
&direction
);
1062 /** Specifies the source's 3D position, velocity, and orientation together. */
1063 void set3DParameters(const Vector3
&position
, const Vector3
&velocity
, std::pair
<Vector3
,Vector3
> orientation
);
1065 /** Specifies the source's 3D position. */
1066 void setPosition(ALfloat x
, ALfloat y
, ALfloat z
);
1067 void setPosition(const ALfloat
*pos
);
1068 Vector3
getPosition() const;
1071 * Specifies the source's 3D velocity, in units per second. As with OpenAL,
1072 * this does not actually alter the source's position, and instead just
1073 * alters the pitch as determined by the doppler effect.
1075 void setVelocity(ALfloat x
, ALfloat y
, ALfloat z
);
1076 void setVelocity(const ALfloat
*vel
);
1077 Vector3
getVelocity() const;
1080 * Specifies the source's 3D facing direction. Deprecated in favor of
1083 void setDirection(ALfloat x
, ALfloat y
, ALfloat z
);
1084 void setDirection(const ALfloat
*dir
);
1085 Vector3
getDirection() const;
1088 * Specifies the source's 3D orientation. Note: unlike the AL_EXT_BFORMAT
1089 * extension this property comes from, this also affects the facing
1090 * direction, superceding setDirection.
1092 void setOrientation(ALfloat x1
, ALfloat y1
, ALfloat z1
, ALfloat x2
, ALfloat y2
, ALfloat z2
);
1093 void setOrientation(const ALfloat
*at
, const ALfloat
*up
);
1094 void setOrientation(const ALfloat
*ori
);
1095 std::pair
<Vector3
,Vector3
> getOrientation() const;
1098 * Specifies the source's cone angles, in degrees. The inner angle is the
1099 * area within which the listener will hear the source with no extra
1100 * attenuation, while the listener being outside of the outer angle will
1101 * hear the source attenuated according to the outer cone gains.
1103 void setConeAngles(ALfloat inner
, ALfloat outer
);
1104 std::pair
<ALfloat
,ALfloat
> getConeAngles() const;
1105 ALfloat
getInnerConeAngle() const { return std::get
<0>(getConeAngles()); }
1106 ALfloat
getOuterConeAngle() const { return std::get
<1>(getConeAngles()); }
1109 * Specifies the linear gain multiplier when the listener is outside of the
1110 * source's outer cone area. The specified gain applies to all frequencies,
1111 * while gainhf applies extra attenuation to high frequencies.
1113 * \param gainhf has no effect without the ALC_EXT_EFX extension.
1115 void setOuterConeGains(ALfloat gain
, ALfloat gainhf
=1.0f
);
1116 std::pair
<ALfloat
,ALfloat
> getOuterConeGains() const;
1117 ALfloat
getOuterConeGain() const { return std::get
<0>(getOuterConeGains()); }
1118 ALfloat
getOuterConeGainHF() const { return std::get
<1>(getOuterConeGains()); }
1121 * Specifies the rolloff factors for the direct and send paths. This is
1122 * effectively a distance scaling relative to the reference distance. Note:
1123 * the room rolloff factor is 0 by default, disabling distance attenuation
1124 * for send paths. This is because the reverb engine will, by default,
1125 * apply a more realistic room decay based on the reverb decay time and
1128 void setRolloffFactors(ALfloat factor
, ALfloat roomfactor
=0.0f
);
1129 std::pair
<ALfloat
,ALfloat
> getRolloffFactors() const;
1130 ALfloat
getRolloffFactor() const { return std::get
<0>(getRolloffFactors()); }
1131 ALfloat
getRoomRolloffFactor() const { return std::get
<1>(getRolloffFactors()); }
1134 * Specifies the doppler factor for the doppler effect's pitch shift. This
1135 * effectively scales the source and listener velocities for the doppler
1138 void setDopplerFactor(ALfloat factor
);
1139 ALfloat
getDopplerFactor() const;
1142 * Specifies if the source's position, velocity, and direction/orientation
1143 * are relative to the listener.
1145 void setRelative(bool relative
);
1146 bool getRelative() const;
1149 * Specifies the source's radius. This causes the source to behave as if
1150 * every point within the spherical area emits sound.
1152 * Has no effect without the AL_EXT_SOURCE_RADIUS extension.
1154 void setRadius(ALfloat radius
);
1155 ALfloat
getRadius() const;
1158 * Specifies the left and right channel angles, in radians, when playing a
1159 * stereo buffer or stream. The angles go counter-clockwise, with 0 being
1160 * in front and positive values going left.
1162 * Has no effect without the AL_EXT_STEREO_ANGLES extension.
1164 void setStereoAngles(ALfloat leftAngle
, ALfloat rightAngle
);
1165 std::pair
<ALfloat
,ALfloat
> getStereoAngles() const;
1168 * Specifies if the source always has 3D spatialization features (On),
1169 * never has 3D spatialization features (Off), or if spatialization is
1170 * enabled based on playing a mono sound or not (Auto, default).
1172 * Has no effect without the AL_SOFT_source_spatialize extension.
1174 void set3DSpatialize(Spatialize spatialize
);
1175 Spatialize
get3DSpatialize() const;
1177 void setResamplerIndex(ALsizei index
);
1178 ALsizei
getResamplerIndex() const;
1181 * Specifies a multiplier for the amount of atmospheric high-frequency
1182 * absorption, ranging from 0 to 10. A factor of 1 results in a nominal
1183 * -0.05dB per meter, with higher values simulating foggy air and lower
1184 * values simulating dryer air. The default is 0.
1186 void setAirAbsorptionFactor(ALfloat factor
);
1187 ALfloat
getAirAbsorptionFactor() const;
1189 void setGainAuto(bool directhf
, bool send
, bool sendhf
);
1190 std::tuple
<bool,bool,bool> getGainAuto() const;
1191 bool getDirectGainHFAuto() const { return std::get
<0>(getGainAuto()); }
1192 bool getSendGainAuto() const { return std::get
<1>(getGainAuto()); }
1193 bool getSendGainHFAuto() const { return std::get
<2>(getGainAuto()); }
1195 /** Sets the filter properties on the direct path signal. */
1196 void setDirectFilter(const FilterParams
&filter
);
1198 * Sets the filter properties on the given send path signal. Any auxiliary
1199 * effect slot on the send path remains in place.
1201 void setSendFilter(ALuint send
, const FilterParams
&filter
);
1203 * Connects the effect slot to the given send path. Any filter properties
1204 * on the send path remain as they were.
1206 void setAuxiliarySend(AuxiliaryEffectSlot slot
, ALuint send
);
1208 * Connects the effect slot to the given send path, using the filter
1211 void setAuxiliarySendFilter(AuxiliaryEffectSlot slot
, ALuint send
, const FilterParams
&filter
);
1214 * Releases the source, stopping playback, releasing resources, and
1215 * returning it to the system.
1221 class ALURE_API SourceGroup
{
1222 MAKE_PIMPL(SourceGroup
, SourceGroupImpl
)
1225 /** Retrieves the associated name of the source group. */
1226 const String
&getName() const;
1229 * Adds source to the source group. A source may only be part of one group
1230 * at a time, and will automatically be removed from its current group as
1233 void addSource(Source source
);
1234 /** Removes source from the source group. */
1235 void removeSource(Source source
);
1237 /** Adds a list of sources to the group at once. */
1238 void addSources(ArrayView
<Source
> sources
);
1239 /** Removes a list of sources from the source group. */
1240 void removeSources(ArrayView
<Source
> sources
);
1243 * Adds group as a subgroup of the source group. This method will throw an
1244 * exception if group is being added to a group it has as a sub-group (i.e.
1245 * it would create a circular sub-group chain).
1247 void addSubGroup(SourceGroup group
);
1248 /** Removes group from the source group. */
1249 void removeSubGroup(SourceGroup group
);
1251 /** Returns the list of sources currently in the group. */
1252 Vector
<Source
> getSources() const;
1254 /** Returns the list of subgroups currently in the group. */
1255 Vector
<SourceGroup
> getSubGroups() const;
1257 /** Sets the source group gain, which accumulates with its sources. */
1258 void setGain(ALfloat gain
);
1259 /** Gets the source group gain. */
1260 ALfloat
getGain() const;
1262 /** Sets the source group pitch, which accumulates with its sources. */
1263 void setPitch(ALfloat pitch
);
1264 /** Gets the source group pitch. */
1265 ALfloat
getPitch() const;
1268 * Pauses all currently-playing sources that are under this group,
1269 * including sub-groups.
1271 void pauseAll() const;
1273 * Resumes all paused sources that are under this group, including
1276 void resumeAll() const;
1278 /** Stops all sources that are under this group, including sub-groups. */
1279 void stopAll() const;
1282 * Releases the source group, removing all sources from it before being
1294 class ALURE_API AuxiliaryEffectSlot
{
1295 MAKE_PIMPL(AuxiliaryEffectSlot
, AuxiliaryEffectSlotImpl
)
1298 void setGain(ALfloat gain
);
1300 * If set to true, the reverb effect will automatically apply adjustments
1301 * to the source's send slot gains based on the effect properties.
1303 * Has no effect when using non-reverb effects. Default is true.
1305 void setSendAuto(bool sendauto
);
1308 * Updates the effect slot with a new effect. The given effect object may
1309 * be altered or destroyed without affecting the effect slot.
1311 void applyEffect(Effect effect
);
1314 * Releases the effect slot, returning it to the system. It must not be in
1320 * Retrieves each Source object and its pairing send this effect slot is
1321 * set on. Setting a different (or null) effect slot on each source's given
1322 * send will allow the effect slot to be released.
1324 Vector
<SourceSend
> getSourceSends() const;
1326 /** Determines if the effect slot is in use by a source. */
1327 bool isInUse() const;
1331 class ALURE_API Effect
{
1332 MAKE_PIMPL(Effect
, EffectImpl
)
1336 * Updates the effect with the specified reverb properties. If the
1337 * EAXReverb effect is not supported, it will automatically attempt to
1338 * downgrade to the Standard Reverb effect.
1340 void setReverbProperties(const EFXEAXREVERBPROPERTIES
&props
);
1347 * Audio decoder interface. Applications may derive from this, implementing the
1348 * necessary methods, and use it in places the API wants a Decoder object.
1350 class ALURE_API Decoder
{
1354 /** Retrieves the sample frequency, in hz, of the audio being decoded. */
1355 virtual ALuint
getFrequency() const = 0;
1356 /** Retrieves the channel configuration of the audio being decoded. */
1357 virtual ChannelConfig
getChannelConfig() const = 0;
1358 /** Retrieves the sample type of the audio being decoded. */
1359 virtual SampleType
getSampleType() const = 0;
1362 * Retrieves the total length of the audio, in sample frames. If unknown,
1363 * returns 0. Note that if the returned length is 0, the decoder may not be
1364 * used to load a Buffer.
1366 virtual uint64_t getLength() const = 0;
1368 * Seek to pos, specified in sample frames. Returns true if the seek was
1371 virtual bool seek(uint64_t pos
) = 0;
1374 * Retrieves the loop points, in sample frames, as a [start,end) pair. If
1375 * start >= end, use all available data.
1377 virtual std::pair
<uint64_t,uint64_t> getLoopPoints() const = 0;
1380 * Decodes count sample frames, writing them to ptr, and returns the number
1381 * of sample frames written. Returning less than the requested count
1382 * indicates the end of the audio.
1384 virtual ALuint
read(ALvoid
*ptr
, ALuint count
) = 0;
1388 * Audio decoder factory interface. Applications may derive from this,
1389 * implementing the necessary methods, and use it in places the API wants a
1390 * DecoderFactory object.
1392 class ALURE_API DecoderFactory
{
1394 virtual ~DecoderFactory();
1397 * Creates and returns a Decoder instance for the given resource file. If
1398 * the decoder needs to retain the file handle for reading as-needed, it
1399 * should move the UniquePtr to internal storage.
1401 * \return nullptr if a decoder can't be created from the file.
1403 virtual SharedPtr
<Decoder
> createDecoder(UniquePtr
<std::istream
> &file
) = 0;
1407 * Registers a decoder factory for decoding audio. Registered factories are
1408 * used in lexicographical order, e.g. if Factory1 is registered with name1 and
1409 * Factory2 is registered with name2, Factory1 will be used before Factory2 if
1410 * name1 < name2. Internal decoder factories are always used after registered
1413 * Alure retains a reference to the DecoderFactory instance and will release it
1414 * (destructing the object) when the library unloads.
1416 * \param name A unique name identifying this decoder factory.
1417 * \param factory A DecoderFactory instance used to create Decoder instances.
1419 ALURE_API
void RegisterDecoder(StringView name
, UniquePtr
<DecoderFactory
> factory
);
1422 * Unregisters a decoder factory by name. Alure returns the instance back to
1425 * \param name The unique name identifying a previously-registered decoder
1428 * \return The unregistered decoder factory instance, or 0 (nullptr) if a
1429 * decoder factory with the given name doesn't exist.
1431 ALURE_API UniquePtr
<DecoderFactory
> UnregisterDecoder(StringView name
);
1435 * A file I/O factory interface. Applications may derive from this and set an
1436 * instance to be used by the audio decoders. By default, the library uses
1439 class ALURE_API FileIOFactory
{
1442 * Sets the factory instance to be used by the audio decoders. If a
1443 * previous factory was set, it's returned to the application. Passing in a
1444 * nullptr reverts to the default.
1446 static UniquePtr
<FileIOFactory
> set(UniquePtr
<FileIOFactory
> factory
);
1449 * Gets the current FileIOFactory instance being used by the audio
1452 static FileIOFactory
&get();
1454 virtual ~FileIOFactory();
1456 /** Opens a read-only binary file for the given name. */
1457 virtual UniquePtr
<std::istream
> openFile(const String
&name
) = 0;
1462 * A message handler interface. Applications may derive from this and set an
1463 * instance on a context to receive messages. The base methods are no-ops, so
1464 * derived classes only need to implement methods for relevant messages.
1466 * It's recommended that applications mark their handler methods using the
1467 * override keyword, to ensure they're properly overriding the base methods in
1470 class ALURE_API MessageHandler
{
1472 virtual ~MessageHandler();
1475 * Called when the given device has been disconnected and is no longer
1476 * usable for output. As per the ALC_EXT_disconnect specification,
1477 * disconnected devices remain valid, however all playing sources are
1478 * automatically stopped, any sources that are attempted to play will
1479 * immediately stop, and new contexts may not be created on the device.
1481 * Note that connection status is checked during Context::update calls, so
1482 * that method must be called regularly to be notified when a device is
1483 * disconnected. This method may not be called if the device lacks support
1484 * for the ALC_EXT_disconnect extension.
1486 virtual void deviceDisconnected(Device device
);
1489 * Called when the given source reaches the end of the buffer or stream.
1491 * Sources that stopped automatically will be detected upon a call to
1494 virtual void sourceStopped(Source source
);
1497 * Called when the given source was forced to stop. This can be because
1498 * either there were no more system sources and a higher-priority source
1499 * preempted it, or it's part of a SourceGroup (or sub-group thereof) that
1500 * had its SourceGroup::stopAll method called.
1502 virtual void sourceForceStopped(Source source
);
1505 * Called when a new buffer is about to be created and loaded. May be
1506 * called asynchronously for buffers being loaded asynchronously.
1508 * \param name The resource name, as passed to Context::getBuffer.
1509 * \param channels Channel configuration of the given audio data.
1510 * \param type Sample type of the given audio data.
1511 * \param samplerate Sample rate of the given audio data.
1512 * \param data The audio data that is about to be fed to the OpenAL buffer.
1514 virtual void bufferLoading(StringView name
, ChannelConfig channels
, SampleType type
, ALuint samplerate
, ArrayView
<ALbyte
> data
);
1517 * Called when a resource isn't found, allowing the app to substitute in a
1518 * different resource. For buffers created with Context::getBuffer or
1519 * Context::getBufferAsync, the original name will still be used for the
1520 * cache map so the app doesn't have to keep track of substituted resource
1523 * This will be called again if the new name isn't found.
1525 * \param name The resource name that was not found.
1526 * \return The replacement resource name to use instead. Returning an empty
1527 * string means to stop trying.
1529 virtual String
resourceNotFound(StringView name
);
1534 } // namespace alure
1536 #endif /* AL_ALURE2_H */