Skip to content

Commit

Permalink
Merge 45774a1 into ac7a9e3
Browse files Browse the repository at this point in the history
  • Loading branch information
Alice committed Sep 12, 2016
2 parents ac7a9e3 + 45774a1 commit f78d409
Show file tree
Hide file tree
Showing 30 changed files with 4,892 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Expand Up @@ -59,6 +59,7 @@ option(WITH_STBIMAGEIMPORTER "Build StbImageImporter plugin" OFF)
option(WITH_STBPNGIMAGECONVERTER "Build StbPngImageConverter plugin" OFF)
option(WITH_STBTRUETYPEFONT "Build StbTrueTypeFont plugin" OFF)
option(WITH_STBVORBISAUDIOIMPORTER "Build StbVorbisAudioImporter plugin" OFF)
option(WITH_DRFLACAUDIOIMPORTER "Build DrFlacAudioImporter plugin" OFF)

include(CMakeDependentOption)
option(BUILD_TESTS "Build unit tests" OFF)
Expand Down
2 changes: 2 additions & 0 deletions doc/building-plugins.dox
Expand Up @@ -87,6 +87,8 @@ By default no plugins are built and you need to select them manually:
plugin.
- `WITH_STBVORBISAUDIOIMPORTER` -- @ref Audio::StbVorbisImporter "StbVorbisAudioImporter"
plugin.
- `WITH_DRFLACAUDIOIMPORTER` -- @ref Audio::DrFlacImporter "DrFlacAudioImporter"
plugin.

Note that each plugin class contains more detailed information about
dependencies, availability on particular platform and also guide how to enable
Expand Down
2 changes: 2 additions & 0 deletions doc/cmake-plugins.dox
Expand Up @@ -86,6 +86,8 @@ This command will not try to find any actual plugin. The plugins are:
- `StbTrueTypeFont` -- @ref Text::StbTrueTypeFont "StbTrueTypeFont" plugin
- `StbVorbisAudioImporter` -- @ref Audio::StbVorbisImporter "StbVorbisAudioImporter"
plugin
- `DrFlacAudioImporter` -- @ref Audio::DrFlacImporter "DrFlacAudioImporter"
plugin

Note that each plugin class contains more detailed information about
dependencies, availability on particular platform and also guide how to enable
Expand Down
1 change: 1 addition & 0 deletions package/ci/appveyor-desktop-mingw.bat
Expand Up @@ -67,6 +67,7 @@ cmake .. ^
-DWITH_ANYIMAGEIMPORTER=ON ^
-DWITH_ANYSCENEIMPORTER=ON ^
-DWITH_DDSIMPORTER=ON ^
-DWITH_DRFLACAUDIOIMPORTER=ON ^
-DWITH_FREETYPEFONT=OFF ^
-DWITH_HARFBUZZFONT=OFF ^
-DWITH_JPEGIMPORTER=ON ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/appveyor-desktop.bat
Expand Up @@ -66,6 +66,7 @@ cmake .. ^
-DWITH_ANYIMAGEIMPORTER=ON ^
-DWITH_ANYSCENEIMPORTER=ON ^
-DWITH_DDSIMPORTER=ON ^
-DWITH_DRFLACAUDIOIMPORTER=ON ^
-DWITH_FREETYPEFONT=OFF ^
-DWITH_HARFBUZZFONT=OFF ^
-DWITH_JPEGIMPORTER=ON ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/appveyor-rt.bat
Expand Up @@ -78,6 +78,7 @@ cmake .. ^
-DWITH_ANYIMAGEIMPORTER=ON ^
-DWITH_ANYSCENEIMPORTER=ON ^
-DWITH_DDSIMPORTER=ON ^
-DWITH_DRFLACAUDIOIMPORTER=ON ^
-DWITH_FREETYPEFONT=OFF ^
-DWITH_HARFBUZZFONT=OFF ^
-DWITH_JPEGIMPORTER=OFF ^
Expand Down
1 change: 1 addition & 0 deletions package/ci/jenkins-android.xml
Expand Up @@ -91,6 +91,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
`#-DWITH_COLLADAIMPORTER=ON` \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
`#-DWITH_FREETYPEFONT=ON` \
`#-DWITH_HARFBUZZFONT=ON` \
`#-DWITH_JPEGIMPORTER=ON` \
Expand Down
1 change: 1 addition & 0 deletions package/ci/jenkins-emscripten.xml
Expand Up @@ -76,6 +76,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
`#-DWITH_COLLADAIMPORTER=ON` \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
`#-DWITH_FREETYPEFONT=ON` \
`#-DWITH_HARFBUZZFONT=ON` \
`#-DWITH_JPEGIMPORTER=ON` \
Expand Down
1 change: 1 addition & 0 deletions package/ci/jenkins-mingw-w64.xml
Expand Up @@ -90,6 +90,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
`#-DWITH_COLLADAIMPORTER=ON` \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=ON \
`#-DWITH_HARFBUZZFONT=ON` \
-DWITH_JPEGIMPORTER=ON \
Expand Down
1 change: 1 addition & 0 deletions package/ci/jenkins-nacl.xml
Expand Up @@ -75,6 +75,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
`#-DWITH_COLLADAIMPORTER=ON` \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
`#-DWITH_FREETYPEFONT=ON` \
`#-DWITH_HARFBUZZFONT=ON` \
`#-DWITH_JPEGIMPORTER=ON` \
Expand Down
1 change: 1 addition & 0 deletions package/ci/jenkins.xml
Expand Up @@ -124,6 +124,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
-DWITH_COLLADAIMPORTER=ON \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=ON \
-DWITH_HARFBUZZFONT=ON \
-DWITH_JPEGIMPORTER=ON \
Expand Down
1 change: 1 addition & 0 deletions package/ci/travis-desktop.sh
Expand Up @@ -50,6 +50,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
-DWITH_COLLADAIMPORTER=$WITH_COLLADAIMPORTER \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=ON \
-DWITH_HARFBUZZFONT=ON \
-DWITH_JPEGIMPORTER=ON \
Expand Down
1 change: 1 addition & 0 deletions package/ci/travis-emscripten.sh
Expand Up @@ -75,6 +75,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
-DWITH_COLLADAIMPORTER=OFF \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=OFF \
-DWITH_HARFBUZZFONT=OFF \
-DWITH_JPEGIMPORTER=OFF \
Expand Down
1 change: 1 addition & 0 deletions package/ci/travis-ios-simulator.sh
Expand Up @@ -78,6 +78,7 @@ cmake .. \
-DWITH_ANYSCENEIMPORTER=ON \
-DWITH_COLLADAIMPORTER=OFF \
-DWITH_DDSIMPORTER=ON \
-DWITH_DRFLACAUDIOIMPORTER=ON \
-DWITH_FREETYPEFONT=OFF \
-DWITH_HARFBUZZFONT=OFF \
-DWITH_JPEGIMPORTER=OFF \
Expand Down
2 changes: 2 additions & 0 deletions src/MagnumPlugins/AnyAudioImporter/AnyImporter.cpp
Expand Up @@ -53,6 +53,8 @@ void AnyImporter::doOpenFile(const std::string& filename) {
plugin = "VorbisAudioImporter";
else if(Utility::String::endsWith(filename, ".wav"))
plugin = "WavAudioImporter";
else if(Utility::String::endsWith(filename, ".flac"))
plugin = "FlacAudioImporter";
else {
Error() << "Audio::AnyImporter::openFile(): cannot determine type of file" << filename;
return;
Expand Down
1 change: 1 addition & 0 deletions src/MagnumPlugins/AnyAudioImporter/AnyImporter.h
Expand Up @@ -68,6 +68,7 @@ Supported formats:
`VorbisAudioImporter`
- WAV (`*.wav`), loaded with @ref WavImporter "WavAudioImporter" or any other
plugin that provides it
- FLAC (`*.flac`), loaded with any plugin that provides `FlacAudioImporter`
Only loading from files is supported.
*/
Expand Down
4 changes: 4 additions & 0 deletions src/MagnumPlugins/CMakeLists.txt
Expand Up @@ -103,3 +103,7 @@ endif()
if(WITH_STBVORBISAUDIOIMPORTER)
add_subdirectory(StbVorbisAudioImporter)
endif()

if(WITH_DRFLACAUDIOIMPORTER)
add_subdirectory(DrFlacAudioImporter)
endif()
85 changes: 85 additions & 0 deletions src/MagnumPlugins/DrFlacAudioImporter/CMakeLists.txt
@@ -0,0 +1,85 @@
#
# This file is part of Magnum.
#
# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
# Vladimír Vondruš <mosra@centrum.cz>
# Copyright © 2016 Alice Margatroid <loveoverwhelming@gmail.com>
#
# 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.
#

find_package(Magnum REQUIRED Audio)

if(BUILD_STATIC)
set(MAGNUM_DRFLACAUDIOIMPORTER_BUILD_STATIC 1)
endif()

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/configure.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/configure.h)

set(DrFlacAudioImporter_SRCS
DrFlacImporter.cpp)

set(DrFlacAudioImporter_HEADERS
DrFlacImporter.h)

# Objects shared between plugin and test library
add_library(DrFlacAudioImporterObjects OBJECT
${DrFlacAudioImporter_SRCS}
${DrFlacAudioImporter_HEADERS})
target_include_directories(DrFlacAudioImporterObjects PUBLIC
$<TARGET_PROPERTY:Magnum::Audio,INTERFACE_INCLUDE_DIRECTORIES>
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src)
target_compile_definitions(DrFlacAudioImporterObjects PRIVATE "DrFlacAudioImporterObjects_EXPORTS")
# Include the stb_*.h files as a system directory to supress warnings
target_include_directories(DrFlacAudioImporterObjects SYSTEM PRIVATE ${PROJECT_SOURCE_DIR}/src/external/dr)
if(NOT BUILD_PLUGINS_STATIC OR BUILD_STATIC_PIC)
set_target_properties(DrFlacAudioImporterObjects PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()

# DrFlacImporter plugin
add_plugin(DrFlacAudioImporter ${MAGNUM_PLUGINS_AUDIOIMPORTER_DEBUG_INSTALL_DIR} ${MAGNUM_PLUGINS_AUDIOIMPORTER_RELEASE_INSTALL_DIR}
DrFlacAudioImporter.conf
$<TARGET_OBJECTS:DrFlacAudioImporterObjects>
pluginRegistration.cpp)
if(BUILD_STATIC_PIC)
set_target_properties(DrFlacAudioImporter PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(DrFlacAudioImporter PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src)
target_link_libraries(DrFlacAudioImporter Magnum::Magnum Magnum::Audio)

install(FILES ${DrFlacAudioImporter_HEADERS} DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/DrFlacAudioImporter)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/configure.h DESTINATION ${MAGNUM_PLUGINS_INCLUDE_INSTALL_DIR}/DrFlacAudioImporter)

if(BUILD_TESTS)
add_library(MagnumDrFlacAudioImporterTestLib STATIC
$<TARGET_OBJECTS:DrFlacAudioImporterObjects>
${PROJECT_SOURCE_DIR}/src/dummy.cpp) # XCode workaround, see file comment for details
target_include_directories(MagnumDrFlacAudioImporterTestLib PUBLIC
${PROJECT_SOURCE_DIR}/src
${PROJECT_BINARY_DIR}/src)
target_link_libraries(MagnumDrFlacAudioImporterTestLib Magnum::Magnum Magnum::Audio)
add_subdirectory(Test)
endif()

# MagnumPlugins DrFlacAudioImporter target alias for superprojects
add_library(MagnumPlugins::DrFlacAudioImporter ALIAS DrFlacAudioImporter)
@@ -0,0 +1 @@
provides=FlacAudioImporter
100 changes: 100 additions & 0 deletions src/MagnumPlugins/DrFlacAudioImporter/DrFlacImporter.cpp
@@ -0,0 +1,100 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016
Vladimír Vondruš <mosra@centrum.cz>
Copyright © 2016 Alice Margatroid <loveoverwhelming@gmail.com>
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 "DrFlacImporter.h"

#include <Corrade/Utility/Assert.h>
#include <Corrade/Utility/Debug.h>
#include <Corrade/Utility/Endianness.h>

#define DR_FLAC_IMPLEMENTATION
#include "dr_flac.h"

namespace Magnum { namespace Audio {

DrFlacImporter::DrFlacImporter() = default;

DrFlacImporter::DrFlacImporter(PluginManager::AbstractManager& manager, std::string plugin): AbstractImporter(manager, std::move(plugin)) {}

auto DrFlacImporter::doFeatures() const -> Features { return Feature::OpenData; }

bool DrFlacImporter::doIsOpened() const { return _data; }

void DrFlacImporter::doOpenData(Containers::ArrayView<const char> data) {

drflac* _handle = drflac_open_memory(reinterpret_cast<const UnsignedByte*>(data.data()), data.size());

if(_handle == NULL) {
Error() << "Audio::DrFlacImporter::openData(): failed to open and decode FLAC data";
return;
}

uint64_t samples = _handle->totalSampleCount;
uint32_t frequency = _handle->sampleRate;
uint8_t numChannels = _handle->channels;
uint8_t bitsPerSample = _handle->bitsPerSample;

_frequency = frequency;

if(numChannels == 1 && bitsPerSample == 8)
_format = Buffer::Format::Mono8;
else if(numChannels == 1 && bitsPerSample == 16)
_format = Buffer::Format::Mono16;
else if(numChannels == 2 && bitsPerSample == 8)
_format = Buffer::Format::Stereo8;
else if(numChannels == 2 && bitsPerSample == 16)
_format = Buffer::Format::Stereo16;
else {
Error() << "Audio::DrFlacImporter::openData(): unsupported channel count"
<< numChannels << "with" << bitsPerSample
<< "bits per sample";

drflac_close(_handle);
return;
}

Containers::Array<char> tempData(samples * sizeof(int32_t));

drflac_read_s32(_handle, samples, (int32_t*)tempData.begin());
drflac_close(_handle);

_data = std::move(tempData);
return;
}

void DrFlacImporter::doClose() { _data = nullptr; }

Buffer::Format DrFlacImporter::doFormat() const { return _format; }

UnsignedInt DrFlacImporter::doFrequency() const { return _frequency; }

Containers::Array<char> DrFlacImporter::doData() {
Containers::Array<char> copy(_data.size());
std::copy(_data.begin(), _data.end(), copy.begin());
return copy;
}

}}

0 comments on commit f78d409

Please sign in to comment.