Browse Source

WavAudioImporter: minor cleanup, improved static assertions.

pull/176/head
Vladimír Vondruš 10 years ago
parent
commit
cbdad2dfe0
  1. 1
      src/MagnumPlugins/WavAudioImporter/CMakeLists.txt
  2. 1
      src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt
  3. 7
      src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp
  4. 38
      src/MagnumPlugins/WavAudioImporter/WavHeader.cpp
  5. 4
      src/MagnumPlugins/WavAudioImporter/WavHeader.h
  6. 5
      src/MagnumPlugins/WavAudioImporter/WavImporter.cpp

1
src/MagnumPlugins/WavAudioImporter/CMakeLists.txt

@ -24,6 +24,7 @@
#
set(WavAudioImporter_SRCS
WavHeader.cpp
WavImporter.cpp)
set(WavAudioImporter_HEADERS

1
src/MagnumPlugins/WavAudioImporter/Test/CMakeLists.txt

@ -36,7 +36,6 @@ corrade_add_test(WavAudioImporterTest WavImporterTest.cpp LIBRARIES MagnumWavAud
target_include_directories(WavAudioImporterTest PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
if(CORRADE_TARGET_EMSCRIPTEN)
emscripten_embed_file(WavAudioImporterTest mono8.wav "/mono8.wav")
emscripten_embed_file(WavAudioImporterTest mono8.wav "/mono8junk.wav")

7
src/MagnumPlugins/WavAudioImporter/Test/WavImporterTest.cpp

@ -63,21 +63,22 @@ class WavImporterTest: public TestSuite::Tester {
};
WavImporterTest::WavImporterTest() {
addTests({
&WavImporterTest::wrongSize,
addTests({&WavImporterTest::wrongSize,
&WavImporterTest::wrongSignature,
&WavImporterTest::unsupportedFormat,
&WavImporterTest::unsupportedChannelCount,
&WavImporterTest::mono8,
&WavImporterTest::mono8junk,
&WavImporterTest::mono8ALaw,
&WavImporterTest::mono8MuLaw,
&WavImporterTest::mono16,
&WavImporterTest::stereo8,
&WavImporterTest::stereo8ALaw,
&WavImporterTest::stereo8MuLaw,
&WavImporterTest::stereo16,
&WavImporterTest::mono32f,
&WavImporterTest::stereo32f,
&WavImporterTest::stereo64f,

38
src/MagnumPlugins/WavAudioImporter/WavHeader.cpp

@ -0,0 +1,38 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
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 "WavHeader.h"
#include <Corrade/Utility/Debug.h>
#include "Magnum/Magnum.h"
namespace Magnum { namespace Audio {
static_assert(sizeof(RiffChunk) == 8, "RiffChunk size is not 8 bytes");
static_assert(sizeof(WavHeaderChunk) == 12, "WavHeaderChunk size is not 12 bytes");
static_assert(sizeof(WavFormatChunk) == 24, "WavFormatChunk size is not 18 bytes");
}}

4
src/MagnumPlugins/WavAudioImporter/WavHeader.h

@ -26,7 +26,7 @@
*/
/** @file
* @brief Struct @ref Magnum::Audio::WavHeader
* @brief Struct @ref Magnum::Audio::RiffChunk, @ref Magnum::Audio::WavHeaderChunk, @ref Magnum::Audio::WavFormatChunk, enum @ref Magnum::Audio::WavAudioFormat
*/
#include "Magnum/Types.h"
@ -62,8 +62,6 @@ struct WavFormatChunk {
};
#pragma pack()
static_assert(sizeof(WavHeaderChunk) + sizeof(WavFormatChunk) + sizeof(RiffChunk) == 44, "WavHeader size is not 44 bytes");
}}
#endif

5
src/MagnumPlugins/WavAudioImporter/WavImporter.cpp

@ -141,6 +141,7 @@ void WavImporter::doOpenData(Containers::ArrayView<const char> data) {
<< "bits per sample";
return;
}
/* Check IEEE Float format */
} else if(formatChunk->audioFormat == WAVE_FORMAT_IEEE_FLOAT) {
if(formatChunk->numChannels == 1 && formatChunk->bitsPerSample == 32)
@ -157,6 +158,7 @@ void WavImporter::doOpenData(Containers::ArrayView<const char> data) {
<< "bits per sample";
return;
}
/* Check ALAW format */
} else if(formatChunk->audioFormat == WAVE_FORMAT_ALAW) {
if(formatChunk->numChannels == 1)
@ -169,6 +171,7 @@ void WavImporter::doOpenData(Containers::ArrayView<const char> data) {
<< "bits per sample";
return;
}
/* Check MULAW format */
} else if(formatChunk->audioFormat == WAVE_FORMAT_MULAW) {
if(formatChunk->numChannels == 1)
@ -204,8 +207,6 @@ void WavImporter::doOpenData(Containers::ArrayView<const char> data) {
return;
}
/* Save frequency */
_frequency = formatChunk->sampleRate;

Loading…
Cancel
Save