Magnum::Audio::AbstractImporter class

Base for audio importer plugins.

Provides interface for importing various audio formats. See Loading and using plugins for more information and *Importer classes in Audio namespace for available importer plugins.

Data dependency

The data returned from various functions by design have no dependency on the importer instance and neither on the dynamic plugin module. In other words, you don't need to keep the importer instance (or the plugin manager instance) around in order to have the returned data valid. Moreover, all returned Corrade::Containers::Array instances are only allowed to have default deleters — this is to avoid potential dangling function pointer calls when destructing such instances after the plugin module has been unloaded.


Plugin implements function doFeatures(), doIsOpened(), one of or both doOpenData() and doOpenFile() functions, function doClose() and data access functions doFormat(), doFrequency() and doData().

You don't need to do most of the redundant sanity checks, these things are checked by the implementation:

Derived classes

class AnyImporter
Any audio importer plugin.
class DrFlacImporter
FLAC audio importer plugin using dr_flac.
class DrMp3Importer new in 2019.10
MP3 audio importer plugin using dr_mp3.
class DrWavImporter
WAV audio importer plugin using dr_wav.
class Faad2Importer
AAC audio importer plugin using FAAD2.
class StbVorbisImporter
OGG audio importer plugin using stb_vorbis.
class WavImporter
WAV importer plugin.

Public types

using Feature = ImporterFeature deprecated in 2020.06
Features supported by an audio importer.
using Features = ImporterFeatures deprecated in 2020.06
Features supported by an audio importer.

Public static functions

static auto pluginInterface() -> std::string
Plugin interface.
static auto pluginSearchPaths() -> std::vector<std::string>
Plugin search paths.

Constructors, destructors, conversion operators

AbstractImporter() explicit
Default constructor.
AbstractImporter(PluginManager::Manager<AbstractImporter>& manager) explicit
Constructor with access to plugin manager.
AbstractImporter(PluginManager::AbstractManager& manager, const std::string& plugin) explicit
Plugin manager constructor.

Public functions

auto features() const -> ImporterFeatures
Features supported by this importer.
auto isOpened() const -> bool
Whether any file is opened.
auto openData(Containers::ArrayView<const char> data) -> bool
Open raw data.
auto openFile(const std::string& filename) -> bool
Open file.
void close()
Close file.

Private functions

auto doFeatures() const -> ImporterFeatures pure virtual
Implementation for features()
auto doIsOpened() const -> bool pure virtual
Implementation for isOpened()
void doOpenData(Containers::ArrayView<const char> data) virtual
Implementation for openData()
void doOpenFile(const std::string& filename) virtual
Implementation for openFile()
void doClose() pure virtual
Implementation for close()
auto doFormat() const -> BufferFormat pure virtual
Implementation for format()
auto doFrequency() const -> UnsignedInt pure virtual
Implementation for frequency()
auto doData() -> Containers::Array<char> pure virtual
Implementation for data()

Data access

auto format() const -> BufferFormat
Sample format.
auto frequency() const -> UnsignedInt
Sample frequency.
auto data() -> Containers::Array<char>
Sample data.

Typedef documentation

typedef ImporterFeature Magnum::Audio::AbstractImporter::Feature

Features supported by an audio importer.

typedef ImporterFeatures Magnum::Audio::AbstractImporter::Features

Features supported by an audio importer.

Function documentation

static std::string Magnum::Audio::AbstractImporter::pluginInterface()

Plugin interface.


static std::vector<std::string> Magnum::Audio::AbstractImporter::pluginSearchPaths()

Plugin search paths.

Looks into magnum/audioimporters/ or magnum-d/audioimporters/ next to the dynamic Trade library, next to the executable and elsewhere according to the rules documented in Corrade::PluginManager::implicitPluginSearchPaths(). The search directory can be also hardcoded using the MAGNUM_PLUGINS_DIR CMake variables, see Downloading and building for more information.

Not defined on platforms without dynamic plugin support.

bool Magnum::Audio::AbstractImporter::openData(Containers::ArrayView<const char> data)

Open raw data.

Closes previous file, if it was opened, and tries to open given file. Available only if ImporterFeature::OpenData is supported. Returns true on success, false otherwise.

bool Magnum::Audio::AbstractImporter::openFile(const std::string& filename)

Open file.

Closes previous file, if it was opened, and tries to open given file. Returns true on success, false otherwise.

void Magnum::Audio::AbstractImporter::doOpenFile(const std::string& filename) virtual private

Implementation for openFile()

If ImporterFeature::OpenData is supported, default implementation opens the file and calls doOpenData() with its contents.