Browse Source

Audio: minor cleanup, rename Buffer::length() to sampleCount().

* use Magnum types in public API
 * make getters const consistently to Source getters
 * Buffer::length() could be confused with size(), rename it to make it
   more explicit.
pull/300/head
Vladimír Vondruš 7 years ago
parent
commit
cdb69423ec
  1. 53
      src/Magnum/Audio/Buffer.h
  2. 27
      src/Magnum/Audio/Test/BufferALTest.cpp

53
src/Magnum/Audio/Buffer.h

@ -105,42 +105,44 @@ class MAGNUM_AUDIO_EXPORT Buffer {
} }
/** /**
* @brief Get buffer size * @brief Buffer size in bytes
* @return The buffer's size in bytes *
* @see @ref channels(), @ref bitDepth(), @ref sampleCount()
*/ */
ALint size() { Int size() const {
ALint size; Int size;
alGetBufferi(_id, AL_SIZE, &size); alGetBufferi(_id, AL_SIZE, &size);
return size; return size;
} }
/** /**
* @brief Get buffer channels * @brief Buffer channel count
* @return The buffer's number of channels *
* @see @ref size(), @ref bitDepth(), @ref sampleCount()
*/ */
ALint channels() { Int channels() const {
ALint channels; ALint channels;
alGetBufferi(_id, AL_CHANNELS, &channels); alGetBufferi(_id, AL_CHANNELS, &channels);
return channels; return channels;
} }
/** /**
* @brief Get buffer bit depth * @brief Buffer bit depth
* @return The buffer's bit depth *
* @see @ref size(), @ref channels(), @ref sampleCount()
*/ */
ALint bitDepth() { Int bitDepth() const {
ALint bitDepth; ALint bitDepth;
alGetBufferi(_id, AL_BITS, &bitDepth); alGetBufferi(_id, AL_BITS, &bitDepth);
return bitDepth; return bitDepth;
} }
/** /**
* @brief Get buffer length * @brief Buffer sample count
* @return The buffer's length in samples *
* Calculated from @ref size(), @ref channels() and @ref bitDepth().
*/ */
ALint length() { Int sampleCount() const { return size()*8/(channels()*bitDepth()); }
return size() * 8 / (channels() * bitDepth());
}
/** /**
* @brief Get buffer loop points * @brief Get buffer loop points
@ -148,8 +150,8 @@ class MAGNUM_AUDIO_EXPORT Buffer {
* *
* @requires_al_extension Extension @al_extension{SOFT,loop_points} * @requires_al_extension Extension @al_extension{SOFT,loop_points}
*/ */
std::pair<ALint, ALint> loopPoints() { std::pair<Int, Int> loopPoints() const {
std::pair<ALint, ALint> points{0, 0}; std::pair<Int, Int> points{0, 0};
alGetBufferiv(_id, AL_LOOP_POINTS_SOFT, &(points.first)); alGetBufferiv(_id, AL_LOOP_POINTS_SOFT, &(points.first));
return points; return points;
} }
@ -160,8 +162,8 @@ class MAGNUM_AUDIO_EXPORT Buffer {
* @param loopEnd The loop's end point in samples * @param loopEnd The loop's end point in samples
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* The buffer needs to not be attached to a source for this operation to * The buffer needs to not be attached to a source for this operation
* succeed. * to succeed.
* @requires_al_extension Extension @al_extension{SOFT,loop_points} * @requires_al_extension Extension @al_extension{SOFT,loop_points}
*/ */
Buffer& setLoopPoints(Int loopStart, Int loopEnd); Buffer& setLoopPoints(Int loopStart, Int loopEnd);
@ -171,9 +173,8 @@ class MAGNUM_AUDIO_EXPORT Buffer {
* @param loopEnd The loop's end point in samples * @param loopEnd The loop's end point in samples
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Equivalent to calling @ref setLoopPoints() with @p loopStart equal to * Equivalent to calling @ref setLoopPoints() with @p loopStart equal
* 0. * to @cpp 0 @ce.
*
* @requires_al_extension Extension @al_extension{SOFT,loop_points} * @requires_al_extension Extension @al_extension{SOFT,loop_points}
*/ */
Buffer& setLoopUntil(Int loopEnd) { Buffer& setLoopUntil(Int loopEnd) {
@ -186,8 +187,7 @@ class MAGNUM_AUDIO_EXPORT Buffer {
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Equivalent to calling @ref setLoopPoints() with @p loopEnd equal to * Equivalent to calling @ref setLoopPoints() with @p loopEnd equal to
* @p INT_MAX. * @cpp INT_MAX @ce.
*
* @requires_al_extension Extension @al_extension{SOFT,loop_points} * @requires_al_extension Extension @al_extension{SOFT,loop_points}
*/ */
Buffer& setLoopSince(Int loopStart) { Buffer& setLoopSince(Int loopStart) {
@ -198,9 +198,8 @@ class MAGNUM_AUDIO_EXPORT Buffer {
* @brief Resets the loop points * @brief Resets the loop points
* @return Reference to self (for method chaining) * @return Reference to self (for method chaining)
* *
* Equivalent to calling @ref setLoopPoints() with @p loopStart equal to * Equivalent to calling @ref setLoopPoints() with @p loopStart equal
* 0, and @p loopEnd equal to @p INT_MAX. * to @cpp 0 @ce, and @p loopEnd equal to @cpp INT_MAX @ce.
*
* @requires_al_extension Extension @al_extension{SOFT,loop_points} * @requires_al_extension Extension @al_extension{SOFT,loop_points}
*/ */
Buffer& resetLoopPoints() { Buffer& resetLoopPoints() {

27
src/Magnum/Audio/Test/BufferALTest.cpp

@ -75,13 +75,12 @@ void BufferALTest::properties() {
CORRADE_COMPARE(buf.size(), 8); CORRADE_COMPARE(buf.size(), 8);
CORRADE_COMPARE(buf.channels(), 1); CORRADE_COMPARE(buf.channels(), 1);
CORRADE_COMPARE(buf.bitDepth(), 8); CORRADE_COMPARE(buf.bitDepth(), 8);
CORRADE_COMPARE(buf.length(), 8); CORRADE_COMPARE(buf.sampleCount(), 8);
} }
void BufferALTest::loopPoints() { void BufferALTest::loopPoints() {
if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>()) { if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>())
CORRADE_SKIP("Extension AL_SOFT_loop_points isn't supported on this system."); CORRADE_SKIP(Extensions::AL::SOFT::loop_points::string() + std::string{" is not supported."});
}
Buffer buf; Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 }; constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };
@ -91,9 +90,8 @@ void BufferALTest::loopPoints() {
} }
void BufferALTest::setLoopPoints() { void BufferALTest::setLoopPoints() {
if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>()) { if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>())
CORRADE_SKIP("Extension AL_SOFT_loop_points isn't supported on this system."); CORRADE_SKIP(Extensions::AL::SOFT::loop_points::string() + std::string{" is not supported."});
}
Buffer buf; Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 }; constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };
@ -103,9 +101,8 @@ void BufferALTest::setLoopPoints() {
} }
void BufferALTest::setLoopSince() { void BufferALTest::setLoopSince() {
if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>()) { if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>())
CORRADE_SKIP("Extension AL_SOFT_loop_points isn't supported on this system."); CORRADE_SKIP(Extensions::AL::SOFT::loop_points::string() + std::string{" is not supported."});
}
Buffer buf; Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 }; constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };
@ -115,9 +112,8 @@ void BufferALTest::setLoopSince() {
} }
void BufferALTest::setLoopUntil() { void BufferALTest::setLoopUntil() {
if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>()) { if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>())
CORRADE_SKIP("Extension AL_SOFT_loop_points isn't supported on this system."); CORRADE_SKIP(Extensions::AL::SOFT::loop_points::string() + std::string{" is not supported."});
}
Buffer buf; Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 }; constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };
@ -127,9 +123,8 @@ void BufferALTest::setLoopUntil() {
} }
void BufferALTest::resetLoopPoints() { void BufferALTest::resetLoopPoints() {
if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>()) { if(!_context.isExtensionSupported<Audio::Extensions::AL::SOFT::loop_points>())
CORRADE_SKIP("Extension AL_SOFT_loop_points isn't supported on this system."); CORRADE_SKIP(Extensions::AL::SOFT::loop_points::string() + std::string{" is not supported."});
}
Buffer buf; Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 }; constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };

Loading…
Cancel
Save