2023-03-06 14:42:04 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
// Copyright The Music Player Daemon Project
|
2013-01-30 23:40:56 +01:00
|
|
|
|
|
|
|
#ifndef PCM_CONVERT_HXX
|
|
|
|
#define PCM_CONVERT_HXX
|
|
|
|
|
2013-11-29 21:39:53 +01:00
|
|
|
#include "FormatConverter.hxx"
|
2013-11-30 13:19:07 +01:00
|
|
|
#include "ChannelsConverter.hxx"
|
2013-11-30 14:10:31 +01:00
|
|
|
#include "GlueResampler.hxx"
|
2013-11-11 16:15:38 +01:00
|
|
|
#include "AudioFormat.hxx"
|
2018-11-19 12:49:45 +01:00
|
|
|
#include "config.h"
|
2013-01-30 23:40:56 +01:00
|
|
|
|
2014-09-26 10:52:46 +02:00
|
|
|
#ifdef ENABLE_DSD
|
|
|
|
#include "PcmDsd.hxx"
|
|
|
|
#endif
|
|
|
|
|
2022-07-04 15:27:03 +02:00
|
|
|
#include <cstddef>
|
|
|
|
#include <span>
|
|
|
|
|
2018-07-17 23:04:26 +02:00
|
|
|
struct ConfigData;
|
2013-01-30 23:40:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This object is statically allocated (within another struct), and
|
|
|
|
* holds buffer allocations and the state for all kinds of PCM
|
|
|
|
* conversions.
|
|
|
|
*/
|
|
|
|
class PcmConvert {
|
2014-09-26 10:52:46 +02:00
|
|
|
#ifdef ENABLE_DSD
|
2013-07-29 07:56:40 +02:00
|
|
|
PcmDsd dsd;
|
2014-09-26 10:52:46 +02:00
|
|
|
#endif
|
2013-01-30 23:40:56 +01:00
|
|
|
|
2013-11-11 22:31:46 +01:00
|
|
|
GluePcmResampler resampler;
|
2013-11-29 21:39:53 +01:00
|
|
|
PcmFormatConverter format_converter;
|
2013-11-30 13:19:07 +01:00
|
|
|
PcmChannelsConverter channels_converter;
|
2013-01-30 23:40:56 +01:00
|
|
|
|
2019-04-04 21:06:28 +02:00
|
|
|
const AudioFormat src_format;
|
2013-11-11 16:15:38 +01:00
|
|
|
|
2013-11-11 22:31:46 +01:00
|
|
|
bool enable_resampler, enable_format, enable_channels;
|
|
|
|
|
2020-01-17 19:12:16 +01:00
|
|
|
#ifdef ENABLE_DSD
|
|
|
|
bool dsd2pcm_float;
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 23:40:56 +01:00
|
|
|
public:
|
|
|
|
|
2013-11-11 16:15:38 +01:00
|
|
|
/**
|
2019-04-04 20:55:39 +02:00
|
|
|
* Throws on error.
|
2013-11-11 16:15:38 +01:00
|
|
|
*/
|
2019-04-04 20:55:39 +02:00
|
|
|
PcmConvert(AudioFormat _src_format, AudioFormat _dest_format);
|
2013-01-30 23:40:56 +01:00
|
|
|
|
2019-04-04 20:55:39 +02:00
|
|
|
~PcmConvert() noexcept;
|
2013-01-30 23:40:56 +01:00
|
|
|
|
2017-01-11 15:30:30 +01:00
|
|
|
/**
|
|
|
|
* Reset the filter's state, e.g. drop/flush buffers.
|
|
|
|
*/
|
2018-01-01 19:07:33 +01:00
|
|
|
void Reset() noexcept;
|
2017-01-11 15:30:30 +01:00
|
|
|
|
2013-01-30 23:40:56 +01:00
|
|
|
/**
|
|
|
|
* Converts PCM data between two audio formats.
|
|
|
|
*
|
2016-09-05 12:19:20 +02:00
|
|
|
* Throws std::runtime_error on error.
|
|
|
|
*
|
2013-01-30 23:40:56 +01:00
|
|
|
* @param src the source PCM buffer
|
2016-09-05 12:19:20 +02:00
|
|
|
* @return the destination buffer
|
2013-01-30 23:40:56 +01:00
|
|
|
*/
|
2022-07-04 15:27:03 +02:00
|
|
|
std::span<const std::byte> Convert(std::span<const std::byte> src);
|
2018-01-02 18:22:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush pending data and return it. This should be called
|
|
|
|
* repepatedly until it returns nullptr.
|
|
|
|
*/
|
2022-07-04 15:27:03 +02:00
|
|
|
std::span<const std::byte> Flush();
|
2013-01-30 23:40:56 +01:00
|
|
|
};
|
|
|
|
|
2016-09-05 12:19:20 +02:00
|
|
|
void
|
2018-07-17 23:04:26 +02:00
|
|
|
pcm_convert_global_init(const ConfigData &config);
|
2013-11-29 10:06:20 +01:00
|
|
|
|
2013-01-30 23:40:56 +01:00
|
|
|
#endif
|