
Brought to you by the inventor of QOI, QOA is a lossy audio codec that is, as the name says, quite okay in compressing audio data reasonably well without frequency transformation, mostly introducing some white noise in the background. This implementation of QOA is fully compatible with the qoa.h reference implementation as of 2023-02-25. Note that there may be changes to the QOA format before a specification is finalized, and there is currently no information on when that will happen and which changes will be made. This implementation of QOA can handle varying sample rate and varying channel count files. The reference implementation does not produce these files and cannot handle them, so their implementation is untested. The QOA loader is capable of seeking in constant-bitrate streams. QOA links: https://phoboslab.org/log/2023/02/qoa-time-domain-audio-compression https://github.com/phoboslab/qoa
83 lines
2.1 KiB
C++
83 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2018-2023, the SerenityOS developers.
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibAudio/FlacLoader.h>
|
|
#include <LibAudio/Loader.h>
|
|
#include <LibAudio/MP3Loader.h>
|
|
#include <LibAudio/QOALoader.h>
|
|
#include <LibAudio/WavLoader.h>
|
|
|
|
namespace Audio {
|
|
|
|
LoaderPlugin::LoaderPlugin(NonnullOwnPtr<SeekableStream> stream)
|
|
: m_stream(move(stream))
|
|
{
|
|
}
|
|
|
|
Loader::Loader(NonnullOwnPtr<LoaderPlugin> plugin)
|
|
: m_plugin(move(plugin))
|
|
{
|
|
}
|
|
|
|
Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::create_plugin(StringView path)
|
|
{
|
|
{
|
|
auto plugin = WavLoaderPlugin::create(path);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = FlacLoaderPlugin::create(path);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = MP3LoaderPlugin::create(path);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = QOALoaderPlugin::create(path);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
return LoaderError { "No loader plugin available" };
|
|
}
|
|
|
|
Result<NonnullOwnPtr<LoaderPlugin>, LoaderError> Loader::create_plugin(Bytes buffer)
|
|
{
|
|
{
|
|
auto plugin = WavLoaderPlugin::create(buffer);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = FlacLoaderPlugin::create(buffer);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = MP3LoaderPlugin::create(buffer);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
{
|
|
auto plugin = QOALoaderPlugin::create(buffer);
|
|
if (!plugin.is_error())
|
|
return NonnullOwnPtr<LoaderPlugin>(plugin.release_value());
|
|
}
|
|
|
|
return LoaderError { "No loader plugin available" };
|
|
}
|
|
|
|
}
|