diff --git a/src/Audio/Source.cpp b/src/Audio/Source.cpp index 8eba148bc..379df219d 100644 --- a/src/Audio/Source.cpp +++ b/src/Audio/Source.cpp @@ -35,6 +35,24 @@ Source& Source::setBuffer(Buffer* buffer) { return *this; } +Source& Source::queueBuffers(std::initializer_list buffers) { + ALuint* ids = new ALuint[buffers.size()]; + for(auto it = buffers.begin(); it != buffers.end(); ++it) + ids[it-buffers.begin()] = *it ? (*it)->id() : 0; + + alSourceQueueBuffers(_id, buffers.size(), ids); + delete[] ids; + return *this; +} + +Source& Source::queueBuffers(const std::vector& buffers) { + ALuint* ids = new ALuint[buffers.size()]; + for(auto it = buffers.begin(); it != buffers.end(); ++it) + ids[it-buffers.begin()] = *it ? (*it)->id() : 0; + + alSourceQueueBuffers(_id, buffers.size(), ids); +} + namespace { const ALuint* sourceIds(const std::initializer_list& sources) { diff --git a/src/Audio/Source.h b/src/Audio/Source.h index f96de05c1..57ccecb5c 100644 --- a/src/Audio/Source.h +++ b/src/Audio/Source.h @@ -42,8 +42,14 @@ namespace Magnum { namespace Audio { /** @brief %Source -Manages positional audio source. -@todo Expose convenient API for buffer queuing +Manages positional audio source. The audio can be played either from static +buffer or from buffer queue. + +@section Audio-Source-queue Buffer queuing + +@code +??? TODO +@endcode */ class MAGNUM_AUDIO_EXPORT Source { public: @@ -355,6 +361,38 @@ class MAGNUM_AUDIO_EXPORT Source { */ Source& setBuffer(Buffer* buffer); + /** + * @brief Queue buffers for streaming + * @param buffers Buffers to queue + * + * Changes source type to @ref Type "Type::Streaming". You can + * repurpose the queued buffers later using @ref unqueueBuffers(). See + * class documentation for example usage. + * @see @ref type(), @fn_al{SourceQueueBuffers} + * @todo Make it possible to have one buffer used in more than one + * queue preserving RAII encapsulation (i.e. not having one buffer + * ID in two Buffer objects) -- might use pointers and on + * unqueuing map the IDs back to pointers, would the additional + * memory requirements and possible dangling reference issues be + * worth it? + */ + void queueBuffers(std::vector& buffers); + + /** @overload */ + void queueBuffers(std::vector&& buffers) { + queueBuffers(buffers); + } + + /** + * @brief Unqueue buffers for streaming + * @param count Count of buffers to unqueue + * + * Moves unqueued buffers back in to the arguments. See class + * documentation for example usage. + * @see @ref type(), @fn_al{SourceUnqueueBuffers} + */ + std::vector unqueueBuffers(ALsizei count); + /*@}*/ /** @{ @name State management */