mirror of https://github.com/mosra/magnum.git
7 changed files with 220 additions and 1 deletions
@ -0,0 +1,44 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include "Buffer.h" |
||||||
|
|
||||||
|
#include <Utility/Debug.h> |
||||||
|
|
||||||
|
namespace Magnum { namespace Audio { |
||||||
|
|
||||||
|
Debug operator<<(Debug debug, const Buffer::Format value) { |
||||||
|
switch(value) { |
||||||
|
#define _c(value) case Buffer::Format::value: return debug << "Audio::Buffer::Format::" #value; |
||||||
|
_c(Mono8) |
||||||
|
_c(Mono16) |
||||||
|
_c(Stereo8) |
||||||
|
_c(Stereo16) |
||||||
|
#undef _c |
||||||
|
} |
||||||
|
|
||||||
|
return debug << "Audio::Buffer::Format::(invalid)"; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
@ -0,0 +1,120 @@ |
|||||||
|
#ifndef Magnum_Audio_Buffer_h |
||||||
|
#define Magnum_Audio_Buffer_h |
||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
/** @file
|
||||||
|
* @brief Class Magnum::Audio::Buffer |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <utility> |
||||||
|
#include <al.h> |
||||||
|
#include <Containers/Array.h> |
||||||
|
|
||||||
|
#include "Magnum.h" |
||||||
|
#include "Audio/magnumAudioVisibility.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Audio { |
||||||
|
|
||||||
|
/** @brief Sample buffer */ |
||||||
|
class Buffer { |
||||||
|
public: |
||||||
|
/**
|
||||||
|
* @brief Sample format |
||||||
|
* |
||||||
|
* @note Multi-channel format is played without 3D spatialization |
||||||
|
* (useful for background music) |
||||||
|
* @see @ref setData() |
||||||
|
*/ |
||||||
|
enum class Format: ALenum { |
||||||
|
Mono8 = AL_FORMAT_MONO8, /**< 8-bit unsigned mono */ |
||||||
|
Mono16 = AL_FORMAT_MONO16, /**< 16-bit signed mono */ |
||||||
|
Stereo8 = AL_FORMAT_STEREO8, /**< 8-bit interleaved unsigned stereo */ |
||||||
|
Stereo16 = AL_FORMAT_STEREO16 /**< 16-bit interleaved signed stereo */ |
||||||
|
}; |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Constructor |
||||||
|
* |
||||||
|
* Creates OpenAL buffer object. |
||||||
|
* @see @fn_al{GenBuffers} |
||||||
|
*/ |
||||||
|
explicit Buffer() { alGenBuffers(1, &_id); } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Destructor |
||||||
|
* |
||||||
|
* Deletes OpenAL buffer object. |
||||||
|
* @see @fn_al{DeleteBuffers} |
||||||
|
*/ |
||||||
|
~Buffer() { if(_id) alDeleteBuffers(1, &_id); } |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
Buffer(const Buffer&) = delete; |
||||||
|
|
||||||
|
/** @brief Move constructor */ |
||||||
|
Buffer(Buffer&& other); |
||||||
|
|
||||||
|
/** @brief Copying is not allowed */ |
||||||
|
Buffer& operator=(const Buffer&) = delete; |
||||||
|
|
||||||
|
/** @brief Move assignment */ |
||||||
|
Buffer& operator=(Buffer&& other); |
||||||
|
|
||||||
|
/** @brief OpenAL buffer ID */ |
||||||
|
ALuint id() const { return _id; } |
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set buffer data |
||||||
|
* @param format Sample format |
||||||
|
* @param data Data |
||||||
|
* @param frequency Frequency |
||||||
|
* @return Reference to self (for method chaining) |
||||||
|
* |
||||||
|
* @see @fn_al{BufferData} |
||||||
|
*/ |
||||||
|
Buffer& setData(Format format, Containers::ArrayReference<const void> data, ALsizei frequency) { |
||||||
|
alBufferData(_id, ALenum(format), data, data.size(), frequency); |
||||||
|
return *this; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
ALuint _id; |
||||||
|
}; |
||||||
|
|
||||||
|
/** @debugoperator{Magnum::Audio::Buffer} */ |
||||||
|
Debug MAGNUM_AUDIO_EXPORT operator<<(Debug debug, Buffer::Format value); |
||||||
|
|
||||||
|
inline Buffer::Buffer(Buffer&& other): _id(other._id) { |
||||||
|
other._id = 0; |
||||||
|
} |
||||||
|
|
||||||
|
inline Buffer& Buffer::operator=(Buffer&& other) { |
||||||
|
std::swap(_id, other._id); |
||||||
|
return *this; |
||||||
|
} |
||||||
|
|
||||||
|
}} |
||||||
|
|
||||||
|
#endif |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
/*
|
||||||
|
This file is part of Magnum. |
||||||
|
|
||||||
|
Copyright © 2010, 2011, 2012, 2013 Vladimír Vondruš <mosra@centrum.cz> |
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a |
||||||
|
copy of this software and associated documentation files (the "Software"), |
||||||
|
to deal in the Software without restriction, including without limitation |
||||||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||||||
|
and/or sell copies of the Software, and to permit persons to whom the |
||||||
|
Software is furnished to do so, subject to the following conditions: |
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included |
||||||
|
in all copies or substantial portions of the Software. |
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||||||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
||||||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
||||||
|
DEALINGS IN THE SOFTWARE. |
||||||
|
*/ |
||||||
|
|
||||||
|
#include <sstream> |
||||||
|
#include <TestSuite/Tester.h> |
||||||
|
|
||||||
|
#include "Audio/Buffer.h" |
||||||
|
|
||||||
|
namespace Magnum { namespace Audio { namespace Test { |
||||||
|
|
||||||
|
class BufferTest: public TestSuite::Tester { |
||||||
|
public: |
||||||
|
explicit BufferTest(); |
||||||
|
|
||||||
|
void debugFormat(); |
||||||
|
}; |
||||||
|
|
||||||
|
BufferTest::BufferTest() { |
||||||
|
addTests({&BufferTest::debugFormat}); |
||||||
|
} |
||||||
|
|
||||||
|
void BufferTest::debugFormat() { |
||||||
|
std::ostringstream out; |
||||||
|
Debug(&out) << Buffer::Format::Stereo16; |
||||||
|
CORRADE_COMPARE(out.str(), "Audio::Buffer::Format::Stereo16\n"); |
||||||
|
} |
||||||
|
|
||||||
|
}}} |
||||||
|
|
||||||
|
CORRADE_TEST_MAIN(Magnum::Audio::Test::BufferTest) |
||||||
Loading…
Reference in new issue