Add methods to get the source sends using a given effect slot
[alure.git] / include / AL / alure2.h
blob31f593c122eb7393f9d12fea9883c79b108a0b64
1 #ifndef AL_ALURE2_H
2 #define AL_ALURE2_H
4 #include <vector>
5 #include <string>
6 #include <memory>
7 #include <cmath>
9 #include "alc.h"
10 #include "al.h"
12 #ifndef EFXEAXREVERBPROPERTIES_DEFINED
13 #define EFXEAXREVERBPROPERTIES_DEFINED
14 typedef struct {
15 float flDensity;
16 float flDiffusion;
17 float flGain;
18 float flGainHF;
19 float flGainLF;
20 float flDecayTime;
21 float flDecayHFRatio;
22 float flDecayLFRatio;
23 float flReflectionsGain;
24 float flReflectionsDelay;
25 float flReflectionsPan[3];
26 float flLateReverbGain;
27 float flLateReverbDelay;
28 float flLateReverbPan[3];
29 float flEchoTime;
30 float flEchoDepth;
31 float flModulationTime;
32 float flModulationDepth;
33 float flAirAbsorptionGainHF;
34 float flHFReference;
35 float flLFReference;
36 float flRoomRolloffFactor;
37 int iDecayHFLimit;
38 } EFXEAXREVERBPROPERTIES, *LPEFXEAXREVERBPROPERTIES;
39 #endif
41 namespace alure {
43 class DeviceManager;
44 class Device;
45 class Context;
46 class Listener;
47 class Buffer;
48 class Source;
49 class AuxiliaryEffectSlot;
50 class Effect;
51 class Decoder;
52 class DecoderFactory;
53 class MessageHandler;
56 // A SharedPtr implementation, defaults to C++11's std::shared_ptr. If this is
57 // changed, you must recompile the library.
58 template<typename T>
59 using SharedPtr = std::shared_ptr<T>;
62 struct FilterParams {
63 ALfloat mGain;
64 ALfloat mGainHF; // For low-pass and band-pass filters
65 ALfloat mGainLF; // For high-pass and band-pass filters
69 class Vector3 {
70 ALfloat mValue[3];
72 public:
73 Vector3() { }
74 Vector3(const Vector3 &rhs) : mValue{rhs.mValue[0], rhs.mValue[1], rhs.mValue[2]}
75 { }
76 Vector3(ALfloat val) : mValue{val, val, val}
77 { }
78 Vector3(ALfloat x, ALfloat y, ALfloat z) : mValue{x, y, z}
79 { }
80 Vector3(const ALfloat *vec) : mValue{vec[0], vec[1], vec[2]}
81 { }
83 const ALfloat *getPtr() const
84 { return mValue; }
86 ALfloat& operator[](size_t i)
87 { return mValue[i]; }
88 const ALfloat& operator[](size_t i) const
89 { return mValue[i]; }
91 #define ALURE_DECL_OP(op) \
92 Vector3 operator op(const Vector3 &rhs) const \
93 { \
94 return Vector3(mValue[0] op rhs.mValue[0], \
95 mValue[1] op rhs.mValue[1], \
96 mValue[2] op rhs.mValue[2]); \
98 ALURE_DECL_OP(+)
99 ALURE_DECL_OP(-)
100 ALURE_DECL_OP(*)
101 ALURE_DECL_OP(/)
102 #undef ALURE_DECL_OP
103 #define ALURE_DECL_OP(op) \
104 Vector3& operator op(const Vector3 &rhs) \
106 mValue[0] op rhs.mValue[0]; \
107 mValue[1] op rhs.mValue[1]; \
108 mValue[2] op rhs.mValue[2]; \
109 return *this; \
111 ALURE_DECL_OP(+=)
112 ALURE_DECL_OP(-=)
113 ALURE_DECL_OP(*=)
114 ALURE_DECL_OP(/=)
115 #undef ALURE_DECL_OP
116 #define ALURE_DECL_OP(op) \
117 Vector3 operator op(ALfloat scale) const \
119 return Vector3(mValue[0] op scale, \
120 mValue[1] op scale, \
121 mValue[2] op scale); \
123 ALURE_DECL_OP(*)
124 ALURE_DECL_OP(/)
125 #undef ALURE_DECL_OP
126 #define ALURE_DECL_OP(op) \
127 Vector3& operator op(ALfloat scale) \
129 mValue[0] op scale; \
130 mValue[1] op scale; \
131 mValue[2] op scale; \
132 return *this; \
134 ALURE_DECL_OP(*=)
135 ALURE_DECL_OP(/=)
136 #undef ALURE_DECL_OP
138 ALfloat getLengthSquared() const
139 { return mValue[0]*mValue[0] + mValue[1]*mValue[1] + mValue[2]*mValue[2]; }
140 ALfloat getLength() const
141 { return sqrtf(getLengthSquared()); }
143 ALfloat getDistanceSquared(const Vector3 &pos) const
144 { return (pos - *this).getLengthSquared(); }
145 ALfloat getDistance(const Vector3 &pos) const
146 { return (pos - *this).getLength(); }
148 static_assert(sizeof(Vector3) == sizeof(ALfloat[3]), "Bad Vector3 size");
152 * Creates a version number value using the specified \param major and
153 * \param minor values.
155 inline ALCuint MakeVersion(ALCushort major, ALCushort minor)
156 { return (major<<16) | minor; }
159 * Retrieves the major version of a version number value created by
160 * \ref MakeVersion.
162 inline ALCuint MajorVersion(ALCuint version)
163 { return version>>16; }
165 * Retrieves the minor version of a version number value created by
166 * \ref MakeVersion.
168 inline ALCuint MinorVersion(ALCuint version)
169 { return version&0xffff; }
172 enum DeviceEnumeration {
173 DevEnum_Basic = ALC_DEVICE_SPECIFIER,
174 DevEnum_Complete = ALC_ALL_DEVICES_SPECIFIER,
175 DevEnum_Capture = ALC_CAPTURE_DEVICE_SPECIFIER
178 enum DefaultDeviceType {
179 DefaultDevType_Basic = ALC_DEFAULT_DEVICE_SPECIFIER,
180 DefaultDevType_Complete = ALC_DEFAULT_ALL_DEVICES_SPECIFIER,
181 DefaultDevType_Capture = ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER
185 * A class managing \ref Device objects and other related functionality. This
186 * class is a singleton, only one instance will exist in a process.
188 class DeviceManager {
189 public:
190 /** Retrieves the DeviceManager instance. */
191 static DeviceManager *get();
193 /** Queries the existence of a non-device-specific ALC extension. */
194 virtual bool queryExtension(const char *extname) const = 0;
196 /** Enumerates available device names of the given \param type. */
197 virtual std::vector<std::string> enumerate(DeviceEnumeration type) const = 0;
198 /** Retrieves the default device of the given \param type. */
199 virtual std::string defaultDeviceName(DefaultDeviceType type) const = 0;
201 /** Opens the playback device given by \param name, or the default if empty. */
202 virtual Device *openPlayback(const std::string &name=std::string()) = 0;
206 enum PlaybackDeviceType {
207 PlaybackDevType_Basic = ALC_DEVICE_SPECIFIER,
208 PlaybackDevType_Complete = ALC_ALL_DEVICES_SPECIFIER
211 class Device {
212 public:
213 /** Retrieves the device name as given by \param type. */
214 virtual std::string getName(PlaybackDeviceType type) const = 0;
215 /** Queries the existence of an ALC extension on this device. */
216 virtual bool queryExtension(const char *extname) const = 0;
219 * Retrieves the ALC version supported by this device, as constructed by
220 * \ref MakeVersion.
222 virtual ALCuint getALCVersion() const = 0;
225 * Retrieves the EFX version supported by this device, as constructed by
226 * \ref MakeVersion. If the ALC_EXT_EFX extension is unsupported, this
227 * will be 0.
229 virtual ALCuint getEFXVersion() const = 0;
231 /** Retrieves the device's playback frequency, in hz. */
232 virtual ALCuint getFrequency() const = 0;
235 * Retrieves the maximum number of auxiliary source sends. If ALC_EXT_EFX
236 * is unsupported, this will be 0.
238 virtual ALCuint getMaxAuxiliarySends() const = 0;
241 * Enumerates available HRTF names. The names are sorted as OpenAL gives
242 * them, such that the index of a given name is the ID to use with
243 * ALC_HRTF_ID_SOFT.
245 * Requires the ALC_SOFT_HRTF extension.
247 virtual std::vector<std::string> enumerateHRTFNames() const = 0;
250 * Retrieves whether HRTF is enabled on the device or not.
252 * Requires the ALC_SOFT_HRTF extension.
254 virtual bool isHRTFEnabled() const = 0;
257 * Retrieves the name of the HRTF currently being used by this device.
259 * Requires the ALC_SOFT_HRTF extension.
261 virtual std::string getCurrentHRTF() const = 0;
264 * Resets the device, using the specified \param attributes.
266 * Requires the ALC_SOFT_HRTF extension.
268 virtual void reset(ALCint *attributes) = 0;
271 * Creates a new \ref Context on this device, using the specified
272 * \param attributes.
274 virtual Context *createContext(ALCint *attributes=0) = 0;
277 * Pauses device processing, stopping updates for its contexts. Multiple
278 * calls are allowed but it is not reference counted, so the device will
279 * resume after one \ref resumeDSP call.
281 * Requires the ALC_SOFT_pause_device extension.
283 virtual void pauseDSP() = 0;
286 * Resumes device processing, restarting updates for its contexts. Multiple
287 * calls are allowed and will no-op.
289 virtual void resumeDSP() = 0;
292 * Closes and frees the device. All previously-created contexts must first
293 * be destroyed.
295 virtual void close() = 0;
299 enum DistanceModel {
300 DistanceModel_InverseClamped = AL_INVERSE_DISTANCE_CLAMPED,
301 DistanceModel_LinearClamped = AL_LINEAR_DISTANCE_CLAMPED,
302 DistanceModel_ExponentClamped = AL_EXPONENT_DISTANCE_CLAMPED,
303 DistanceModel_Inverse = AL_INVERSE_DISTANCE,
304 DistanceModel_Linear = AL_LINEAR_DISTANCE,
305 DistanceModel_Exponent = AL_EXPONENT_DISTANCE,
306 DistanceModel_None = AL_NONE,
309 class Context {
310 public:
311 /** Makes the specified \param context current for OpenAL operations. */
312 static void MakeCurrent(Context *context);
313 /** Retrieves the current context used for OpenAL operations. */
314 static Context *GetCurrent();
317 * Makes the specified \param context current for OpenAL operations on the
318 * calling thread only. Requires the ALC_EXT_thread_local_context extension.
320 static void MakeThreadCurrent(Context *context);
322 * Retrieves the thread-specific context used for OpenAL operations.
323 * Requires the ALC_EXT_thread_local_context extension.
325 static Context *GetThreadCurrent();
328 * Destroys the context. The context must not be current when this is
329 * called.
331 virtual void destroy() = 0;
333 /** Retrieves the \ref Device this context was created from. */
334 virtual Device *getDevice() = 0;
336 virtual void startBatch() = 0;
337 virtual void endBatch() = 0;
340 * Retrieves a \ref Listener instance for this context. Each context will
341 * only have one listener.
343 virtual Listener *getListener() = 0;
346 * Sets a MessageHandler instance which will be used to provide certain
347 * messages back to the application. Only one handler may be set for a
348 * context at a time. The previously set handler will be returned.
350 virtual SharedPtr<MessageHandler> setMessageHandler(SharedPtr<MessageHandler> handler) = 0;
352 /** Gets the currently-set message handler. */
353 virtual SharedPtr<MessageHandler> getMessageHandler() const = 0;
356 * Creates a \ref Decoder instance for the given audio file or resource
357 * \param name.
359 virtual SharedPtr<Decoder> createDecoder(const std::string &name) = 0;
361 // Functions below require the context to be current
364 * Creates and caches a \ref Buffer for the given audio file or resource
365 * \param name. Multiple calls with the same name will return the same
366 * \ref Buffer object.
368 virtual Buffer *getBuffer(const std::string &name) = 0;
371 * Creates and caches a \ref Buffer for the given audio file or resource
372 * \param name. Multiple calls with the same name will return the same
373 * \ref Buffer object.
375 * The returned \ref Buffer object will be scheduled for loading
376 * asynchronously, and must be checked with a call to
377 * \ref Buffer::getLoadStatus prior to being played.
379 virtual Buffer *getBufferAsync(const std::string &name) = 0;
382 * Deletes the cached \ref Buffer object for the given audio file or
383 * resource \param name. The buffer must not be in use by a \ref Source.
385 virtual void removeBuffer(const std::string &name) = 0;
387 * Deletes the given cached \param buffer instance. The buffer must not be
388 * in use by a \ref Source.
390 virtual void removeBuffer(Buffer *buffer) = 0;
393 * Gets a new \ref Source. There is no practical limit to the number of
394 * sources you may get.
396 virtual Source *getSource() = 0;
398 virtual AuxiliaryEffectSlot *createAuxiliaryEffectSlot() = 0;
400 virtual Effect *createEffect() = 0;
402 virtual void setDopplerFactor(ALfloat factor) = 0;
404 virtual void setSpeedOfSound(ALfloat speed) = 0;
406 virtual void setDistanceModel(DistanceModel model) = 0;
409 * Updates the context and all sources belonging to this context (you do
410 * not need to call the individual sources' update method if you call this
411 * function).
413 virtual void update() = 0;
417 enum SampleType {
418 SampleType_UInt8,
419 SampleType_Int16,
420 SampleType_Float32,
421 SampleType_Mulaw
423 const char *GetSampleTypeName(SampleType type);
425 enum ChannelConfig {
426 ChannelConfig_Mono,
427 ChannelConfig_Stereo,
428 ChannelConfig_Rear,
429 ChannelConfig_Quad,
430 ChannelConfig_X51,
431 ChannelConfig_X61,
432 ChannelConfig_X71,
433 ChannelConfig_BFmt_WXY,
434 ChannelConfig_BFmt_WXYZ
436 const char *GetChannelConfigName(ChannelConfig cfg);
438 enum BufferLoadStatus {
439 BufferLoad_Pending,
440 BufferLoad_Ready
443 class Listener {
444 public:
445 virtual void setGain(ALfloat gain) = 0;
447 virtual void setPosition(ALfloat x, ALfloat y, ALfloat z) = 0;
448 virtual void setPosition(const ALfloat *pos) = 0;
450 virtual void setVelocity(ALfloat x, ALfloat y, ALfloat z) = 0;
451 virtual void setVelocity(const ALfloat *vel) = 0;
453 virtual void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2) = 0;
454 virtual void setOrientation(const ALfloat *at, const ALfloat *up) = 0;
455 virtual void setOrientation(const ALfloat *ori) = 0;
457 virtual void setMetersPerUnit(ALfloat m_u) = 0;
461 class Buffer {
462 public:
464 * Retrieves the length of the buffer in sample frames. The buffer must be
465 * fully loaded before this method is called.
467 virtual ALuint getLength() const = 0;
469 /** Retrieves the buffer's frequency in hz. */
470 virtual ALuint getFrequency() const = 0;
472 /** Retrieves the buffer's sample configuration. */
473 virtual ChannelConfig getChannelConfig() const = 0;
475 /** Retrieves the buffer's sample type. */
476 virtual SampleType getSampleType() const = 0;
479 * Retrieves the storage size used by the buffer, in bytes. The buffer must
480 * be fully loaded before this method is called.
482 virtual ALuint getSize() const = 0;
485 * Sets the buffer's loop points, used for looping sources. If the current
486 * context does not support the AL_SOFT_loop_points extension, \param start
487 * and \param end must be 0 and \ref getLength() respectively. Otherwise,
488 * \param start must be less than \param end, and \param end must be less
489 * than or equal to \ref getLength().
491 * The buffer must not be in use when this method is called, and the buffer
492 * must be fully loaded.
494 * \param start The starting point, in sample frames (inclusive).
495 * \param end The ending point, in sample frames (exclusive).
497 virtual void setLoopPoints(ALuint start, ALuint end) = 0;
500 * Retrieves the current loop points as a [start,end) pair. The buffer must
501 * be fully loaded before this method is called.
503 virtual std::pair<ALuint,ALuint> getLoopPoints() const = 0;
506 * Retrieves the \ref Source objects currently playing the buffer. Stopping
507 * the returned sources will allow the buffer to be removed from the
508 * context.
510 virtual std::vector<Source*> getSources() const = 0;
513 * Queries the buffer's load status. A return of \ref BufferLoad_Pending
514 * indicates the buffer is not finished loading and can't be used with a
515 * call to \ref Source::play. Buffers created with \ref Context::getBuffer
516 * will always return \ref BufferLoad_Ready.
518 virtual BufferLoadStatus getLoadStatus() = 0;
520 /** Queries if the buffer is in use and can't be removed. */
521 virtual bool isInUse() const = 0;
525 class Source {
526 public:
528 * Plays the source using \param buffer. The same buffer may be played from
529 * multiple sources simultaneously.
531 virtual void play(Buffer *buffer) = 0;
533 * Plays the source by streaming audio from \param decoder. This will use
534 * \param queuelen buffers, each with \param updatelen sample frames. The
535 * given decoder must *NOT* have its read or seek methods called from
536 * elsewhere while in use.
538 virtual void play(SharedPtr<Decoder> decoder, ALuint updatelen, ALuint queuesize) = 0;
540 * Stops playback, releasing the buffer or decoder reference.
542 virtual void stop() = 0;
544 /** Pauses the source if it is playing. */
545 virtual void pause() = 0;
547 /** Resumes the source if it is paused. */
548 virtual void resume() = 0;
550 /** Specifies if the source is currently playing. */
551 virtual bool isPlaying() const = 0;
553 /** Specifies if the source is currently paused. */
554 virtual bool isPaused() const = 0;
557 * Specifies the source's playback priority. Lowest priority sources will
558 * be evicted first when higher priority sources are played.
560 virtual void setPriority(ALuint priority) = 0;
561 /** Retrieves the source's priority. */
562 virtual ALuint getPriority() const = 0;
565 * Sets the source's offset, in sample frames. If the source is playing or
566 * paused, it will go to that offset immediately, otherwise the source will
567 * start at the specified offset the next time it's played.
569 virtual void setOffset(uint64_t offset) = 0;
571 * Retrieves the source offset in sample frames. For streaming sources,
572 * this will be the offset from the beginning of the stream based on the
573 * decoder's reported position.
575 * \param latency If non-NULL and the device supports it, the source's
576 * latency, in nanoseconds, will be written to that location.
578 virtual uint64_t getOffset(uint64_t *latency=0) const = 0;
580 virtual void setLooping(bool looping) = 0;
581 virtual bool getLooping() const = 0;
583 virtual void setPitch(ALfloat pitch) = 0;
584 virtual ALfloat getPitch() const = 0;
586 virtual void setGain(ALfloat gain) = 0;
587 virtual ALfloat getGain() const = 0;
589 virtual void setGainRange(ALfloat mingain, ALfloat maxgain) = 0;
590 virtual ALfloat getMinGain() const = 0;
591 virtual ALfloat getMaxGain() const = 0;
593 virtual void setDistanceRange(ALfloat refdist, ALfloat maxdist) = 0;
594 virtual ALfloat getReferenceDistance() const = 0;
595 virtual ALfloat getMaxDistance() const = 0;
597 virtual void setPosition(ALfloat x, ALfloat y, ALfloat z) = 0;
598 virtual void setPosition(const ALfloat *pos) = 0;
599 virtual Vector3 getPosition() const = 0;
601 virtual void setVelocity(ALfloat x, ALfloat y, ALfloat z) = 0;
602 virtual void setVelocity(const ALfloat *vel) = 0;
603 virtual Vector3 getVelocity() const = 0;
605 virtual void setDirection(ALfloat x, ALfloat y, ALfloat z) = 0;
606 virtual void setDirection(const ALfloat *dir) = 0;
607 virtual Vector3 getDirection() const = 0;
609 virtual void setOrientation(ALfloat x1, ALfloat y1, ALfloat z1, ALfloat x2, ALfloat y2, ALfloat z2) = 0;
610 virtual void setOrientation(const ALfloat *at, const ALfloat *up) = 0;
611 virtual void setOrientation(const ALfloat *ori) = 0;
613 virtual void setConeAngles(ALfloat inner, ALfloat outer) = 0;
614 virtual ALfloat getInnerConeAngle() const = 0;
615 virtual ALfloat getOuterConeAngle() const = 0;
617 virtual void setOuterConeGains(ALfloat gain, ALfloat gainhf=1.0f) = 0;
618 virtual ALfloat getOuterConeGain() const = 0;
619 virtual ALfloat getOuterConeGainHF() const = 0;
621 virtual void setRolloffFactors(ALfloat factor, ALfloat roomfactor=0.0f) = 0;
622 virtual ALfloat getRolloffFactor() const = 0;
623 virtual ALfloat getRoomRolloffFactor() const = 0;
625 virtual void setDopplerFactor(ALfloat factor) = 0;
626 virtual ALfloat getDopplerFactor() const = 0;
628 virtual void setRelative(bool relative) = 0;
629 virtual bool getRelative() const = 0;
631 virtual void setAirAbsorptionFactor(ALfloat factor) = 0;
632 virtual ALfloat getAirAbsorptionFactor() const = 0;
634 virtual void setGainAuto(bool directhf, bool send, bool sendhf) = 0;
635 virtual bool getDirectGainHFAuto() const = 0;
636 virtual bool getSendGainAuto() const = 0;
637 virtual bool getSendGainHFAuto() const = 0;
639 virtual void setDirectFilter(const FilterParams &filter) = 0;
640 virtual void setSendFilter(ALuint send, const FilterParams &filter) = 0;
641 virtual void setAuxiliarySend(AuxiliaryEffectSlot *slot, ALuint send) = 0;
642 virtual void setAuxiliarySendFilter(AuxiliaryEffectSlot *slot, ALuint send, const FilterParams &filter) = 0;
645 * Updates the source, ensuring that streaming buffers are kept full and
646 * resources are released when playback is finished.
648 virtual void update() = 0;
651 * Releases the source, stopping playback, releasing resources, and
652 * returning it to the system.
654 virtual void release() = 0;
658 struct SourceSend {
659 Source *mSource;
660 ALuint mSend;
663 class AuxiliaryEffectSlot {
664 public:
665 virtual void setGain(ALfloat gain) = 0;
667 * If set to true, the reverb effect will automatically apply adjustments
668 * to the source's send slot based on the effect properties.
670 * Has no effect when using non-reverb effects. Default is true.
672 virtual void setSendAuto(bool sendauto) = 0;
675 * Updates the effect slot with a new \param effect. The given effect
676 * object may be altered or destroyed without affecting the effect slot.
678 virtual void applyEffect(const Effect *effect) = 0;
681 * Releases the effect slot, returning it to the system. It must not be in
682 * use by a source.
684 virtual void release() = 0;
687 * Retrieves each \ref Source object and its pairing send this effect slot
688 * is set on. Setting a different (or null) effect slot on each source's
689 * given send will allow the effect slot to be released.
691 virtual std::vector<SourceSend> getSourceSends() const = 0;
693 /** Determines if the effect slot is in use by a source. */
694 virtual bool isInUse() const = 0;
698 class Effect {
699 public:
701 * Updates the effect with the specified reverb properties \param props. If
702 * the EAXReverb effect is not supported, it will automatically attempt to
703 * downgrade to the Standard Reverb effect.
705 virtual void setReverbProperties(const EFXEAXREVERBPROPERTIES &props) = 0;
707 virtual void destroy() = 0;
712 * Audio decoder interface. Applications may derive from this, implementing the
713 * necessary methods, and use it in places the API wants a Decoder object.
715 class Decoder {
716 public:
717 virtual ~Decoder() { }
719 /** Retrieves the sample frequency, in hz, of the audio being decoded. */
720 virtual ALuint getFrequency() const = 0;
721 /** Retrieves the channel configuration of the audio being decoded. */
722 virtual ChannelConfig getChannelConfig() const = 0;
723 /** Retrieves the sample type of the audio being decoded. */
724 virtual SampleType getSampleType() const = 0;
727 * Retrieves the total length of the audio, in sample frames. If unknown,
728 * returns 0. Note that if the returned length is 0, the decoder may not be
729 * used to load a \ref Buffer.
731 virtual uint64_t getLength() = 0;
733 * Retrieves the current sample frame position (i.e. the number of sample
734 * frames from the beginning).
736 virtual uint64_t getPosition() = 0;
738 * Seek to \param pos, specified in sample frames. Returns true if the seek
739 * was successful.
741 virtual bool seek(uint64_t pos) = 0;
744 * Retrieves the loop points, in sample frames, as a [start,end) pair. If
745 * start >= end, use all available data.
747 virtual std::pair<uint64_t,uint64_t> getLoopPoints() const = 0;
750 * Decodes \param count sample frames, writing them to \param ptr, and
751 * returns the number of sample frames written. Returning less than the
752 * requested count indicates the end of the audio.
754 virtual ALuint read(ALvoid *ptr, ALuint count) = 0;
758 * Audio decoder factory interface. Applications may derive from this,
759 * implementing the necessary methods, and use it in places the API wants a
760 * DecoderFactory object.
762 class DecoderFactory {
763 public:
764 virtual ~DecoderFactory() { }
767 * Creates and returns a \ref Decoder instance for the given resource
768 * \param file. Returns NULL if a decoder can't be created from the file.
770 virtual SharedPtr<Decoder> createDecoder(SharedPtr<std::istream> file) = 0;
774 * Registers a decoder factory for decoding audio. Registered factories are
775 * used in lexicographical order, e.g. if Factory1 is registered with name1 and
776 * Factory2 is registered with name2, Factory1 will be used before Factory2 if
777 * name1 < name2. Internal decoder factories are always used after registered
778 * ones.
780 * Alure retains a reference to the DecoderFactory instance and will release it
781 * (potentially destroying the object) when the library unloads.
783 * \param name A unique name identifying this decoder factory.
784 * \param factory A DecoderFactory instance used to create Decoder instances.
786 void RegisterDecoder(const std::string &name, SharedPtr<DecoderFactory> factory);
789 * Unregisters a decoder factory by name. Alure gives a reference to the
790 * instance back to the application and releases its own.
792 * \param name The unique name identifying a previously-registered decoder
793 * factory.
795 * \return The unregistered decoder factory instance, or 0 (nullptr) if a
796 * decoder factory with the given name doesn't exist.
798 SharedPtr<DecoderFactory> UnregisterDecoder(const std::string &name);
802 * A file I/O factory interface. Applications may derive from this and set an
803 * instance to be used by the audio decoders. By default, the library uses
804 * standard I/O.
806 class FileIOFactory {
807 public:
809 * Sets the \param factory instance to be used by the audio decoders. If a
810 * previous factory was set, it's returned to the application. Passing in a
811 * NULL factory reverts to the default.
813 static SharedPtr<FileIOFactory> set(SharedPtr<FileIOFactory> factory);
816 * Gets the current FileIOFactory instance being used by the audio
817 * decoders.
819 static FileIOFactory &get();
821 virtual ~FileIOFactory() { }
823 /** Opens a read-only binary file for the given \param name. */
824 virtual SharedPtr<std::istream> openFile(const std::string &name) = 0;
829 * A message handler interface. Applications may derive from this and set an
830 * instance on a context to receive messages.
832 class MessageHandler {
833 public:
834 virtual ~MessageHandler() { }
837 * Called when a new buffer is about to be created and loaded. May be
838 * called asynchronously for buffers being loaded asynchronously.
840 * \param name The resource name, as passed to \ref Context::getBuffer.
841 * \param channels Channel configuration of the given audio data.
842 * \param type Sample type of the given audio data.
843 * \param samplerate Sample rate of the given audio data.
844 * \param data The audio data that is about to be fed to the OpenAL buffer.
846 virtual void bufferLoading(const std::string &name, ChannelConfig channels, SampleType type, ALuint samplerate, const std::vector<ALbyte> &data) = 0;
849 * Called when a resource isn't found, allowing the app to substitute in a
850 * different resource. For buffers created with \ref Context::getBuffer or
851 * \ref Context::getBufferAsync, the original name will still be used for
852 * the cache map so the app doesn't have to keep track of substituted
853 * resource names.
855 * This will be called again if the new name isn't found.
857 * \param name The resource name that was not found.
858 * \param newname The string to write in a resplacement resource name.
859 * \return True to look for a replacement resource, false to fail.
861 virtual bool resourceNotFound(const std::string &name, std::string &newname) = 0;
864 } // namespace alure
866 #endif /* AL_ALURE2_H */