Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
4,892 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
provides=FlacAudioImporter |
100 changes: 100 additions & 0 deletions
100
src/MagnumPlugins/DrFlacAudioImporter/DrFlacImporter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
}} |
Oops, something went wrong.