Browse Source

Audio: add getters to Buffer.

pull/300/head
Guillaume Jacquemin 7 years ago committed by Vladimír Vondruš
parent
commit
f5302edcc1
  1. 39
      src/Magnum/Audio/Buffer.h
  2. 20
      src/Magnum/Audio/Test/BufferALTest.cpp

39
src/Magnum/Audio/Buffer.h

@ -5,6 +5,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2019 Guillaume Jacquemin <williamjcm@users.noreply.github.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -102,6 +103,44 @@ class Buffer {
return *this;
}
/**
* @brief Get buffer size
* @return The buffer's size in bytes
*/
ALint size() {
ALint size;
alGetBufferi(_id, AL_SIZE, &size);
return size;
}
/**
* @brief Get buffer channels
* @return The buffer's number of channels
*/
ALint channels() {
ALint channels;
alGetBufferi(_id, AL_CHANNELS, &channels);
return channels;
}
/**
* @brief Get buffer bit depth
* @return The buffer's bit depth
*/
ALint bitDepth() {
ALint bitDepth;
alGetBufferi(_id, AL_BITS, &bitDepth);
return bitDepth;
}
/**
* @brief Get buffer length
* @return The buffer's length in samples
*/
ALint length() {
return size() * 8 / (channels() * bitDepth());
}
private:
ALuint _id;
};

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

@ -3,6 +3,7 @@
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2019 Guillaume Jacquemin <williamjcm@users.noreply.github.com>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
@ -26,6 +27,7 @@
#include <Corrade/TestSuite/Tester.h>
#include "Magnum/Audio/Buffer.h"
#include "Magnum/Audio/BufferFormat.h"
#include "Magnum/Audio/Context.h"
namespace Magnum { namespace Audio { namespace Test { namespace {
@ -35,11 +37,15 @@ struct BufferALTest: TestSuite::Tester {
void construct();
void properties();
Context _context;
};
BufferALTest::BufferALTest() {
addTests({&BufferALTest::construct});
addTests({&BufferALTest::construct,
&BufferALTest::properties});
}
void BufferALTest::construct() {
@ -47,6 +53,18 @@ void BufferALTest::construct() {
CORRADE_VERIFY(buf.id() != 0);
}
void BufferALTest::properties() {
Buffer buf;
constexpr char data[] { 25, 17, 24, 122, 67, 24, 48, 96 };
buf.setData(BufferFormat::Mono8, data, 22050);
CORRADE_COMPARE(buf.size(), 8);
CORRADE_COMPARE(buf.channels(), 1);
CORRADE_COMPARE(buf.bitDepth(), 8);
CORRADE_COMPARE(buf.length(), 8);
}
}}}}
CORRADE_TEST_MAIN(Magnum::Audio::Test::BufferALTest)

Loading…
Cancel
Save