pcm/*: add "noexcept"

This commit is contained in:
Max Kellermann 2018-01-01 19:07:33 +01:00
parent 10537c5095
commit 3bb9c704de
35 changed files with 123 additions and 120 deletions

View File

@ -49,7 +49,7 @@ PcmChannelsConverter::Open(SampleFormat _format,
} }
void void
PcmChannelsConverter::Close() PcmChannelsConverter::Close() noexcept
{ {
#ifndef NDEBUG #ifndef NDEBUG
format = SampleFormat::UNDEFINED; format = SampleFormat::UNDEFINED;

View File

@ -41,10 +41,10 @@ class PcmChannelsConverter {
public: public:
#ifndef NDEBUG #ifndef NDEBUG
PcmChannelsConverter() PcmChannelsConverter() noexcept
:format(SampleFormat::UNDEFINED) {} :format(SampleFormat::UNDEFINED) {}
~PcmChannelsConverter() { ~PcmChannelsConverter() noexcept {
assert(format == SampleFormat::UNDEFINED); assert(format == SampleFormat::UNDEFINED);
} }
#endif #endif
@ -64,7 +64,7 @@ public:
/** /**
* Closes the object. After that, you may call Open() again. * Closes the object. After that, you may call Open() again.
*/ */
void Close(); void Close() noexcept;
/** /**
* Convert a block of PCM data. * Convert a block of PCM data.

View File

@ -52,7 +52,7 @@ enum class SelectedResampler {
static SelectedResampler selected_resampler = SelectedResampler::FALLBACK; static SelectedResampler selected_resampler = SelectedResampler::FALLBACK;
static const ConfigBlock * static const ConfigBlock *
MakeResamplerDefaultConfig(ConfigBlock &block) MakeResamplerDefaultConfig(ConfigBlock &block) noexcept
{ {
assert(block.IsEmpty()); assert(block.IsEmpty());
@ -71,7 +71,7 @@ MakeResamplerDefaultConfig(ConfigBlock &block)
* "resampler" block. * "resampler" block.
*/ */
static const ConfigBlock * static const ConfigBlock *
MigrateResamplerConfig(const ConfigParam &param, ConfigBlock &block) MigrateResamplerConfig(const ConfigParam &param, ConfigBlock &block) noexcept
{ {
assert(block.IsEmpty()); assert(block.IsEmpty());
@ -102,7 +102,7 @@ MigrateResamplerConfig(const ConfigParam &param, ConfigBlock &block)
} }
static const ConfigBlock * static const ConfigBlock *
MigrateResamplerConfig(const ConfigParam *param, ConfigBlock &buffer) MigrateResamplerConfig(const ConfigParam *param, ConfigBlock &buffer) noexcept
{ {
assert(buffer.IsEmpty()); assert(buffer.IsEmpty());

View File

@ -57,7 +57,7 @@ FallbackPcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
} }
void void
FallbackPcmResampler::Close() FallbackPcmResampler::Close() noexcept
{ {
} }
@ -67,7 +67,7 @@ pcm_resample_fallback(PcmBuffer &buffer,
unsigned channels, unsigned channels,
unsigned src_rate, unsigned src_rate,
ConstBuffer<T> src, ConstBuffer<T> src,
unsigned dest_rate) unsigned dest_rate) noexcept
{ {
unsigned dest_pos = 0; unsigned dest_pos = 0;
unsigned src_frames = src.size / channels; unsigned src_frames = src.size / channels;
@ -107,7 +107,7 @@ pcm_resample_fallback_void(PcmBuffer &buffer,
unsigned channels, unsigned channels,
unsigned src_rate, unsigned src_rate,
ConstBuffer<void> src, ConstBuffer<void> src,
unsigned dest_rate) unsigned dest_rate) noexcept
{ {
const auto typed_src = ConstBuffer<T>::FromVoid(src); const auto typed_src = ConstBuffer<T>::FromVoid(src);
return pcm_resample_fallback(buffer, channels, src_rate, typed_src, return pcm_resample_fallback(buffer, channels, src_rate, typed_src,

View File

@ -37,7 +37,7 @@ class FallbackPcmResampler final : public PcmResampler {
public: public:
AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override; AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override;
void Close() override; void Close() noexcept override;
ConstBuffer<void> Resample(ConstBuffer<void> src) override; ConstBuffer<void> Resample(ConstBuffer<void> src) override;
}; };

View File

@ -42,11 +42,11 @@ class PcmFormatConverter {
public: public:
#ifndef NDEBUG #ifndef NDEBUG
PcmFormatConverter() PcmFormatConverter() noexcept
:src_format(SampleFormat::UNDEFINED), :src_format(SampleFormat::UNDEFINED),
dest_format(SampleFormat::UNDEFINED) {} dest_format(SampleFormat::UNDEFINED) {}
~PcmFormatConverter() { ~PcmFormatConverter() noexcept {
assert(src_format == SampleFormat::UNDEFINED); assert(src_format == SampleFormat::UNDEFINED);
assert(dest_format == SampleFormat::UNDEFINED); assert(dest_format == SampleFormat::UNDEFINED);
} }

View File

@ -27,7 +27,7 @@
GluePcmResampler::GluePcmResampler() GluePcmResampler::GluePcmResampler()
:resampler(pcm_resampler_create()) {} :resampler(pcm_resampler_create()) {}
GluePcmResampler::~GluePcmResampler() GluePcmResampler::~GluePcmResampler() noexcept
{ {
delete resampler; delete resampler;
} }
@ -57,7 +57,7 @@ GluePcmResampler::Open(AudioFormat src_format, unsigned new_sample_rate)
} }
void void
GluePcmResampler::Close() GluePcmResampler::Close() noexcept
{ {
if (requested_sample_format != src_sample_format) if (requested_sample_format != src_sample_format)
format_converter.Close(); format_converter.Close();
@ -66,7 +66,7 @@ GluePcmResampler::Close()
} }
void void
GluePcmResampler::Reset() GluePcmResampler::Reset() noexcept
{ {
resampler->Reset(); resampler->Reset();
} }

View File

@ -46,19 +46,19 @@ class GluePcmResampler {
public: public:
GluePcmResampler(); GluePcmResampler();
~GluePcmResampler(); ~GluePcmResampler() noexcept;
void Open(AudioFormat src_format, unsigned new_sample_rate); void Open(AudioFormat src_format, unsigned new_sample_rate);
void Close(); void Close() noexcept;
SampleFormat GetOutputSampleFormat() const { SampleFormat GetOutputSampleFormat() const noexcept {
return output_sample_format; return output_sample_format;
} }
/** /**
* @see PcmResampler::Reset() * @see PcmResampler::Reset()
*/ */
void Reset(); void Reset() noexcept;
ConstBuffer<void> Resample(ConstBuffer<void> src); ConstBuffer<void> Resample(ConstBuffer<void> src);
}; };

View File

@ -25,7 +25,7 @@
static void static void
GenericPcmInterleave(uint8_t *gcc_restrict dest, GenericPcmInterleave(uint8_t *gcc_restrict dest,
ConstBuffer<const uint8_t *> src, ConstBuffer<const uint8_t *> src,
size_t n_frames, size_t sample_size) size_t n_frames, size_t sample_size) noexcept
{ {
for (size_t frame = 0; frame < n_frames; ++frame) { for (size_t frame = 0; frame < n_frames; ++frame) {
for (size_t channel = 0; channel < src.size; ++channel) { for (size_t channel = 0; channel < src.size; ++channel) {
@ -41,7 +41,7 @@ static void
PcmInterleaveStereo(T *gcc_restrict dest, PcmInterleaveStereo(T *gcc_restrict dest,
const T *gcc_restrict src1, const T *gcc_restrict src1,
const T *gcc_restrict src2, const T *gcc_restrict src2,
size_t n_frames) size_t n_frames) noexcept
{ {
for (size_t i = 0; i != n_frames; ++i) { for (size_t i = 0; i != n_frames; ++i) {
*dest++ = *src1++; *dest++ = *src1++;
@ -53,7 +53,7 @@ template<typename T>
static void static void
PcmInterleaveT(T *gcc_restrict dest, PcmInterleaveT(T *gcc_restrict dest,
const ConstBuffer<const T *> src, const ConstBuffer<const T *> src,
size_t n_frames) size_t n_frames) noexcept
{ {
switch (src.size) { switch (src.size) {
case 2: case 2:
@ -73,7 +73,7 @@ PcmInterleaveT(T *gcc_restrict dest,
static void static void
PcmInterleave16(int16_t *gcc_restrict dest, PcmInterleave16(int16_t *gcc_restrict dest,
const ConstBuffer<const int16_t *> src, const ConstBuffer<const int16_t *> src,
size_t n_frames) size_t n_frames) noexcept
{ {
PcmInterleaveT(dest, src, n_frames); PcmInterleaveT(dest, src, n_frames);
} }
@ -81,7 +81,7 @@ PcmInterleave16(int16_t *gcc_restrict dest,
void void
PcmInterleave32(int32_t *gcc_restrict dest, PcmInterleave32(int32_t *gcc_restrict dest,
const ConstBuffer<const int32_t *> src, const ConstBuffer<const int32_t *> src,
size_t n_frames) size_t n_frames) noexcept
{ {
PcmInterleaveT(dest, src, n_frames); PcmInterleaveT(dest, src, n_frames);
} }
@ -89,7 +89,7 @@ PcmInterleave32(int32_t *gcc_restrict dest,
void void
PcmInterleave(void *gcc_restrict dest, PcmInterleave(void *gcc_restrict dest,
ConstBuffer<const void *> src, ConstBuffer<const void *> src,
size_t n_frames, size_t sample_size) size_t n_frames, size_t sample_size) noexcept
{ {
switch (sample_size) { switch (sample_size) {
case 2: case 2:

View File

@ -31,7 +31,7 @@
*/ */
void void
PcmInterleave(void *gcc_restrict dest, ConstBuffer<const void *> src, PcmInterleave(void *gcc_restrict dest, ConstBuffer<const void *> src,
size_t n_frames, size_t sample_size); size_t n_frames, size_t sample_size) noexcept;
/** /**
* A variant of PcmInterleave() that assumes 32 bit samples (4 bytes * A variant of PcmInterleave() that assumes 32 bit samples (4 bytes
@ -39,11 +39,11 @@ PcmInterleave(void *gcc_restrict dest, ConstBuffer<const void *> src,
*/ */
void void
PcmInterleave32(int32_t *gcc_restrict dest, ConstBuffer<const int32_t *> src, PcmInterleave32(int32_t *gcc_restrict dest, ConstBuffer<const int32_t *> src,
size_t n_frames); size_t n_frames) noexcept;
static inline void static inline void
PcmInterleaveFloat(float *gcc_restrict dest, ConstBuffer<const float *> src, PcmInterleaveFloat(float *gcc_restrict dest, ConstBuffer<const float *> src,
size_t n_frames) size_t n_frames) noexcept
{ {
PcmInterleave32((int32_t *)dest, PcmInterleave32((int32_t *)dest,
ConstBuffer<const int32_t *>((const int32_t *const*)src.data, ConstBuffer<const int32_t *>((const int32_t *const*)src.data,

View File

@ -109,13 +109,13 @@ LibsampleratePcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
} }
void void
LibsampleratePcmResampler::Close() LibsampleratePcmResampler::Close() noexcept
{ {
state = src_delete(state); state = src_delete(state);
} }
void void
LibsampleratePcmResampler::Reset() LibsampleratePcmResampler::Reset() noexcept
{ {
src_reset(state); src_reset(state);
} }

View File

@ -43,8 +43,8 @@ class LibsampleratePcmResampler final : public PcmResampler {
public: public:
AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override; AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override;
void Close() override; void Close() noexcept override;
void Reset() override; void Reset() noexcept override;
ConstBuffer<void> Resample(ConstBuffer<void> src) override; ConstBuffer<void> Resample(ConstBuffer<void> src) override;
private: private:

View File

@ -66,7 +66,8 @@ struct NeonFloatTo16 {
static constexpr size_t BLOCK_SIZE = 16; static constexpr size_t BLOCK_SIZE = 16;
void Convert(int16_t *dst, const float *src, const size_t n) const { void Convert(int16_t *dst, const float *src,
const size_t n) const noexcept {
for (unsigned i = 0; i < n / BLOCK_SIZE; for (unsigned i = 0; i < n / BLOCK_SIZE;
++i, src += BLOCK_SIZE, dst += BLOCK_SIZE) { ++i, src += BLOCK_SIZE, dst += BLOCK_SIZE) {
/* load 16 float samples into 4 quad /* load 16 float samples into 4 quad

View File

@ -21,7 +21,7 @@
#include "PcmBuffer.hxx" #include "PcmBuffer.hxx"
void * void *
PcmBuffer::Get(size_t new_size) PcmBuffer::Get(size_t new_size) noexcept
{ {
if (new_size == 0) if (new_size == 0)
/* never return nullptr, because nullptr would be /* never return nullptr, because nullptr would be

View File

@ -34,7 +34,7 @@ class PcmBuffer {
ReusableArray<uint8_t, 8192> buffer; ReusableArray<uint8_t, 8192> buffer;
public: public:
void Clear() { void Clear() noexcept {
buffer.Clear(); buffer.Clear();
} }
@ -48,11 +48,11 @@ public:
* always an error. * always an error.
*/ */
gcc_malloc gcc_returns_nonnull gcc_malloc gcc_returns_nonnull
void *Get(size_t size); void *Get(size_t size) noexcept;
template<typename T> template<typename T>
gcc_malloc gcc_returns_nonnull gcc_malloc gcc_returns_nonnull
T *GetT(size_t n) { T *GetT(size_t n) noexcept {
return (T *)Get(n * sizeof(T)); return (T *)Get(n * sizeof(T));
} }
}; };

View File

@ -33,7 +33,7 @@
template<typename D, typename S> template<typename D, typename S>
static void static void
MonoToStereo(D dest, S src, S end) MonoToStereo(D dest, S src, S end) noexcept
{ {
while (src != end) { while (src != end) {
const auto value = *src++; const auto value = *src++;
@ -47,7 +47,7 @@ MonoToStereo(D dest, S src, S end)
template<SampleFormat F, class Traits=SampleTraits<F>> template<SampleFormat F, class Traits=SampleTraits<F>>
static typename Traits::value_type static typename Traits::value_type
StereoToMono(typename Traits::value_type _a, StereoToMono(typename Traits::value_type _a,
typename Traits::value_type _b) typename Traits::value_type _b) noexcept
{ {
typename Traits::sum_type a(_a); typename Traits::sum_type a(_a);
typename Traits::sum_type b(_b); typename Traits::sum_type b(_b);
@ -59,7 +59,7 @@ template<SampleFormat F, class Traits=SampleTraits<F>>
static typename Traits::pointer_type static typename Traits::pointer_type
StereoToMono(typename Traits::pointer_type dest, StereoToMono(typename Traits::pointer_type dest,
typename Traits::const_pointer_type src, typename Traits::const_pointer_type src,
typename Traits::const_pointer_type end) typename Traits::const_pointer_type end) noexcept
{ {
while (src != end) { while (src != end) {
const auto a = *src++; const auto a = *src++;
@ -76,7 +76,7 @@ static typename Traits::pointer_type
NToStereo(typename Traits::pointer_type dest, NToStereo(typename Traits::pointer_type dest,
unsigned src_channels, unsigned src_channels,
typename Traits::const_pointer_type src, typename Traits::const_pointer_type src,
typename Traits::const_pointer_type end) typename Traits::const_pointer_type end) noexcept
{ {
assert((end - src) % src_channels == 0); assert((end - src) % src_channels == 0);
@ -105,7 +105,7 @@ static typename Traits::pointer_type
StereoToN(typename Traits::pointer_type dest, StereoToN(typename Traits::pointer_type dest,
unsigned dest_channels, unsigned dest_channels,
typename Traits::const_pointer_type src, typename Traits::const_pointer_type src,
typename Traits::const_pointer_type end) typename Traits::const_pointer_type end) noexcept
{ {
assert(dest_channels > 2); assert(dest_channels > 2);
assert((end - src) % 2 == 0); assert((end - src) % 2 == 0);
@ -133,7 +133,7 @@ NToM(typename Traits::pointer_type dest,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
typename Traits::const_pointer_type src, typename Traits::const_pointer_type src,
typename Traits::const_pointer_type end) typename Traits::const_pointer_type end) noexcept
{ {
assert((end - src) % src_channels == 0); assert((end - src) % src_channels == 0);
@ -157,7 +157,7 @@ static ConstBuffer<typename Traits::value_type>
ConvertChannels(PcmBuffer &buffer, ConvertChannels(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<typename Traits::value_type> src) ConstBuffer<typename Traits::value_type> src) noexcept
{ {
assert(src.size % src_channels == 0); assert(src.size % src_channels == 0);
@ -184,7 +184,7 @@ ConstBuffer<int16_t>
pcm_convert_channels_16(PcmBuffer &buffer, pcm_convert_channels_16(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int16_t> src) ConstBuffer<int16_t> src) noexcept
{ {
return ConvertChannels<SampleFormat::S16>(buffer, dest_channels, return ConvertChannels<SampleFormat::S16>(buffer, dest_channels,
src_channels, src); src_channels, src);
@ -194,7 +194,7 @@ ConstBuffer<int32_t>
pcm_convert_channels_24(PcmBuffer &buffer, pcm_convert_channels_24(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int32_t> src) ConstBuffer<int32_t> src) noexcept
{ {
return ConvertChannels<SampleFormat::S24_P32>(buffer, dest_channels, return ConvertChannels<SampleFormat::S24_P32>(buffer, dest_channels,
src_channels, src); src_channels, src);
@ -204,7 +204,7 @@ ConstBuffer<int32_t>
pcm_convert_channels_32(PcmBuffer &buffer, pcm_convert_channels_32(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int32_t> src) ConstBuffer<int32_t> src) noexcept
{ {
return ConvertChannels<SampleFormat::S32>(buffer, dest_channels, return ConvertChannels<SampleFormat::S32>(buffer, dest_channels,
src_channels, src); src_channels, src);
@ -214,7 +214,7 @@ ConstBuffer<float>
pcm_convert_channels_float(PcmBuffer &buffer, pcm_convert_channels_float(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<float> src) ConstBuffer<float> src) noexcept
{ {
return ConvertChannels<SampleFormat::FLOAT>(buffer, dest_channels, return ConvertChannels<SampleFormat::FLOAT>(buffer, dest_channels,
src_channels, src); src_channels, src);

View File

@ -38,7 +38,7 @@ ConstBuffer<int16_t>
pcm_convert_channels_16(PcmBuffer &buffer, pcm_convert_channels_16(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int16_t> src); ConstBuffer<int16_t> src) noexcept;
/** /**
* Changes the number of channels in 24 bit PCM data (aligned at 32 * Changes the number of channels in 24 bit PCM data (aligned at 32
@ -54,7 +54,7 @@ ConstBuffer<int32_t>
pcm_convert_channels_24(PcmBuffer &buffer, pcm_convert_channels_24(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int32_t> src); ConstBuffer<int32_t> src) noexcept;
/** /**
* Changes the number of channels in 32 bit PCM data. * Changes the number of channels in 32 bit PCM data.
@ -69,7 +69,7 @@ ConstBuffer<int32_t>
pcm_convert_channels_32(PcmBuffer &buffer, pcm_convert_channels_32(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<int32_t> src); ConstBuffer<int32_t> src) noexcept;
/** /**
* Changes the number of channels in 32 bit float PCM data. * Changes the number of channels in 32 bit float PCM data.
@ -84,6 +84,6 @@ ConstBuffer<float>
pcm_convert_channels_float(PcmBuffer &buffer, pcm_convert_channels_float(PcmBuffer &buffer,
unsigned dest_channels, unsigned dest_channels,
unsigned src_channels, unsigned src_channels,
ConstBuffer<float> src); ConstBuffer<float> src) noexcept;
#endif #endif

View File

@ -30,7 +30,7 @@ pcm_convert_global_init()
pcm_resampler_global_init(); pcm_resampler_global_init();
} }
PcmConvert::PcmConvert() PcmConvert::PcmConvert() noexcept
{ {
#ifndef NDEBUG #ifndef NDEBUG
src_format.Clear(); src_format.Clear();
@ -38,7 +38,7 @@ PcmConvert::PcmConvert()
#endif #endif
} }
PcmConvert::~PcmConvert() PcmConvert::~PcmConvert() noexcept
{ {
assert(!src_format.IsValid()); assert(!src_format.IsValid());
assert(!dest_format.IsValid()); assert(!dest_format.IsValid());
@ -97,7 +97,7 @@ PcmConvert::Open(const AudioFormat _src_format, const AudioFormat _dest_format)
} }
void void
PcmConvert::Close() PcmConvert::Close() noexcept
{ {
if (enable_channels) if (enable_channels)
channels_converter.Close(); channels_converter.Close();
@ -117,7 +117,7 @@ PcmConvert::Close()
} }
void void
PcmConvert::Reset() PcmConvert::Reset() noexcept
{ {
if (enable_resampler) if (enable_resampler)
resampler.Reset(); resampler.Reset();

View File

@ -51,8 +51,8 @@ class PcmConvert {
bool enable_resampler, enable_format, enable_channels; bool enable_resampler, enable_format, enable_channels;
public: public:
PcmConvert(); PcmConvert() noexcept;
~PcmConvert(); ~PcmConvert() noexcept;
/** /**
* Prepare the object. Call Close() when done. * Prepare the object. Call Close() when done.
@ -65,12 +65,12 @@ public:
* Close the object after it was prepared with Open(). After * Close the object after it was prepared with Open(). After
* that, it may be reused by calling Open() again. * that, it may be reused by calling Open() again.
*/ */
void Close(); void Close() noexcept;
/** /**
* Reset the filter's state, e.g. drop/flush buffers. * Reset the filter's state, e.g. drop/flush buffers.
*/ */
void Reset(); void Reset() noexcept;
/** /**
* Converts PCM data between two audio formats. * Converts PCM data between two audio formats.

View File

@ -24,7 +24,7 @@
template<typename T, T MIN, T MAX, unsigned scale_bits> template<typename T, T MIN, T MAX, unsigned scale_bits>
inline T inline T
PcmDither::Dither(T sample) PcmDither::Dither(T sample) noexcept
{ {
constexpr T round = 1 << (scale_bits - 1); constexpr T round = 1 << (scale_bits - 1);
constexpr T mask = (1 << scale_bits) - 1; constexpr T mask = (1 << scale_bits) - 1;
@ -64,7 +64,7 @@ PcmDither::Dither(T sample)
template<typename ST, unsigned SBITS, unsigned DBITS> template<typename ST, unsigned SBITS, unsigned DBITS>
inline ST inline ST
PcmDither::DitherShift(ST sample) PcmDither::DitherShift(ST sample) noexcept
{ {
static_assert(sizeof(ST) * 8 > SBITS, "Source type too small"); static_assert(sizeof(ST) * 8 > SBITS, "Source type too small");
static_assert(SBITS > DBITS, "Non-positive scale_bits"); static_assert(SBITS > DBITS, "Non-positive scale_bits");
@ -77,7 +77,7 @@ PcmDither::DitherShift(ST sample)
template<typename ST, typename DT> template<typename ST, typename DT>
inline typename DT::value_type inline typename DT::value_type
PcmDither::DitherConvert(typename ST::value_type sample) PcmDither::DitherConvert(typename ST::value_type sample) noexcept
{ {
static_assert(ST::BITS > DT::BITS, static_assert(ST::BITS > DT::BITS,
"Sample formats cannot be dithered"); "Sample formats cannot be dithered");
@ -92,7 +92,7 @@ template<typename ST, typename DT>
inline void inline void
PcmDither::DitherConvert(typename DT::pointer_type dest, PcmDither::DitherConvert(typename DT::pointer_type dest,
typename ST::const_pointer_type src, typename ST::const_pointer_type src,
typename ST::const_pointer_type src_end) typename ST::const_pointer_type src_end) noexcept
{ {
while (src < src_end) while (src < src_end)
*dest++ = DitherConvert<ST, DT>(*src++); *dest++ = DitherConvert<ST, DT>(*src++);
@ -100,7 +100,7 @@ PcmDither::DitherConvert(typename DT::pointer_type dest,
inline void inline void
PcmDither::Dither24To16(int16_t *dest, const int32_t *src, PcmDither::Dither24To16(int16_t *dest, const int32_t *src,
const int32_t *src_end) const int32_t *src_end) noexcept
{ {
typedef SampleTraits<SampleFormat::S24_P32> ST; typedef SampleTraits<SampleFormat::S24_P32> ST;
typedef SampleTraits<SampleFormat::S16> DT; typedef SampleTraits<SampleFormat::S16> DT;
@ -109,7 +109,7 @@ PcmDither::Dither24To16(int16_t *dest, const int32_t *src,
inline void inline void
PcmDither::Dither32To16(int16_t *dest, const int32_t *src, PcmDither::Dither32To16(int16_t *dest, const int32_t *src,
const int32_t *src_end) const int32_t *src_end) noexcept
{ {
typedef SampleTraits<SampleFormat::S32> ST; typedef SampleTraits<SampleFormat::S32> ST;
typedef SampleTraits<SampleFormat::S16> DT; typedef SampleTraits<SampleFormat::S16> DT;

View File

@ -29,7 +29,7 @@ class PcmDither {
int32_t random; int32_t random;
public: public:
constexpr PcmDither() constexpr PcmDither() noexcept
:error{0, 0, 0}, random(0) {} :error{0, 0, 0}, random(0) {}
/** /**
@ -42,13 +42,13 @@ public:
* @param sample the input sample value * @param sample the input sample value
*/ */
template<typename ST, unsigned SBITS, unsigned DBITS> template<typename ST, unsigned SBITS, unsigned DBITS>
ST DitherShift(ST sample); ST DitherShift(ST sample) noexcept;
void Dither24To16(int16_t *dest, const int32_t *src, void Dither24To16(int16_t *dest, const int32_t *src,
const int32_t *src_end); const int32_t *src_end) noexcept;
void Dither32To16(int16_t *dest, const int32_t *src, void Dither32To16(int16_t *dest, const int32_t *src,
const int32_t *src_end); const int32_t *src_end) noexcept;
private: private:
/** /**
@ -62,7 +62,7 @@ private:
* @param sample the input sample value * @param sample the input sample value
*/ */
template<typename T, T MIN, T MAX, unsigned scale_bits> template<typename T, T MIN, T MAX, unsigned scale_bits>
T Dither(T sample); T Dither(T sample) noexcept;
/** /**
* Convert the given sample from one sample format to another, * Convert the given sample from one sample format to another,
@ -73,12 +73,12 @@ private:
* @param sample the input sample value * @param sample the input sample value
*/ */
template<typename ST, typename DT> template<typename ST, typename DT>
typename DT::value_type DitherConvert(typename ST::value_type sample); typename DT::value_type DitherConvert(typename ST::value_type sample) noexcept;
template<typename ST, typename DT> template<typename ST, typename DT>
void DitherConvert(typename DT::pointer_type dest, void DitherConvert(typename DT::pointer_type dest,
typename ST::const_pointer_type src, typename ST::const_pointer_type src,
typename ST::const_pointer_type src_end); typename ST::const_pointer_type src_end) noexcept;
}; };
#endif #endif

View File

@ -24,12 +24,12 @@
#include <assert.h> #include <assert.h>
PcmDsd::PcmDsd() PcmDsd::PcmDsd() noexcept
{ {
dsd2pcm.fill(nullptr); dsd2pcm.fill(nullptr);
} }
PcmDsd::~PcmDsd() PcmDsd::~PcmDsd() noexcept
{ {
for (auto i : dsd2pcm) for (auto i : dsd2pcm)
if (i != nullptr) if (i != nullptr)
@ -37,7 +37,7 @@ PcmDsd::~PcmDsd()
} }
void void
PcmDsd::Reset() PcmDsd::Reset() noexcept
{ {
for (auto i : dsd2pcm) for (auto i : dsd2pcm)
if (i != nullptr) if (i != nullptr)
@ -45,7 +45,7 @@ PcmDsd::Reset()
} }
ConstBuffer<float> ConstBuffer<float>
PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src) PcmDsd::ToFloat(unsigned channels, ConstBuffer<uint8_t> src) noexcept
{ {
assert(!src.IsNull()); assert(!src.IsNull());
assert(!src.empty()); assert(!src.empty());

View File

@ -39,13 +39,13 @@ class PcmDsd {
std::array<struct dsd2pcm_ctx_s *, MAX_CHANNELS> dsd2pcm; std::array<struct dsd2pcm_ctx_s *, MAX_CHANNELS> dsd2pcm;
public: public:
PcmDsd(); PcmDsd() noexcept;
~PcmDsd(); ~PcmDsd() noexcept;
void Reset(); void Reset() noexcept;
ConstBuffer<float> ToFloat(unsigned channels, ConstBuffer<float> ToFloat(unsigned channels,
ConstBuffer<uint8_t> src); ConstBuffer<uint8_t> src) noexcept;
}; };
#endif #endif

View File

@ -33,7 +33,7 @@ template<SampleFormat F, class Traits=SampleTraits<F>>
static typename Traits::value_type static typename Traits::value_type
PcmAddVolume(PcmDither &dither, PcmAddVolume(PcmDither &dither,
typename Traits::value_type _a, typename Traits::value_type _b, typename Traits::value_type _a, typename Traits::value_type _b,
int volume1, int volume2) int volume1, int volume2) noexcept
{ {
typename Traits::long_type a(_a), b(_b); typename Traits::long_type a(_a), b(_b);
typename Traits::long_type c(a * volume1 + b * volume2); typename Traits::long_type c(a * volume1 + b * volume2);
@ -48,7 +48,7 @@ static void
PcmAddVolume(PcmDither &dither, PcmAddVolume(PcmDither &dither,
typename Traits::pointer_type a, typename Traits::pointer_type a,
typename Traits::const_pointer_type b, typename Traits::const_pointer_type b,
size_t n, int volume1, int volume2) size_t n, int volume1, int volume2) noexcept
{ {
for (size_t i = 0; i != n; ++i) for (size_t i = 0; i != n; ++i)
a[i] = PcmAddVolume<F, Traits>(dither, a[i], b[i], a[i] = PcmAddVolume<F, Traits>(dither, a[i], b[i],
@ -58,7 +58,8 @@ PcmAddVolume(PcmDither &dither,
template<SampleFormat F, class Traits=SampleTraits<F>> template<SampleFormat F, class Traits=SampleTraits<F>>
static void static void
PcmAddVolumeVoid(PcmDither &dither, PcmAddVolumeVoid(PcmDither &dither,
void *a, const void *b, size_t size, int volume1, int volume2) void *a, const void *b, size_t size,
int volume1, int volume2) noexcept
{ {
constexpr size_t sample_size = Traits::SAMPLE_SIZE; constexpr size_t sample_size = Traits::SAMPLE_SIZE;
assert(size % sample_size == 0); assert(size % sample_size == 0);
@ -72,7 +73,7 @@ PcmAddVolumeVoid(PcmDither &dither,
static void static void
pcm_add_vol_float(float *buffer1, const float *buffer2, pcm_add_vol_float(float *buffer1, const float *buffer2,
unsigned num_samples, float volume1, float volume2) unsigned num_samples, float volume1, float volume2) noexcept
{ {
while (num_samples > 0) { while (num_samples > 0) {
float sample1 = *buffer1; float sample1 = *buffer1;
@ -87,7 +88,7 @@ pcm_add_vol_float(float *buffer1, const float *buffer2,
static bool static bool
pcm_add_vol(PcmDither &dither, void *buffer1, const void *buffer2, size_t size, pcm_add_vol(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
int vol1, int vol2, int vol1, int vol2,
SampleFormat format) SampleFormat format) noexcept
{ {
switch (format) { switch (format) {
case SampleFormat::UNDEFINED: case SampleFormat::UNDEFINED:
@ -133,7 +134,7 @@ pcm_add_vol(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
template<SampleFormat F, class Traits=SampleTraits<F>> template<SampleFormat F, class Traits=SampleTraits<F>>
static typename Traits::value_type static typename Traits::value_type
PcmAdd(typename Traits::value_type _a, typename Traits::value_type _b) PcmAdd(typename Traits::value_type _a, typename Traits::value_type _b) noexcept
{ {
typename Traits::sum_type a(_a), b(_b); typename Traits::sum_type a(_a), b(_b);
@ -144,7 +145,7 @@ template<SampleFormat F, class Traits=SampleTraits<F>>
static void static void
PcmAdd(typename Traits::pointer_type a, PcmAdd(typename Traits::pointer_type a,
typename Traits::const_pointer_type b, typename Traits::const_pointer_type b,
size_t n) size_t n) noexcept
{ {
for (size_t i = 0; i != n; ++i) for (size_t i = 0; i != n; ++i)
a[i] = PcmAdd<F, Traits>(a[i], b[i]); a[i] = PcmAdd<F, Traits>(a[i], b[i]);
@ -152,7 +153,7 @@ PcmAdd(typename Traits::pointer_type a,
template<SampleFormat F, class Traits=SampleTraits<F>> template<SampleFormat F, class Traits=SampleTraits<F>>
static void static void
PcmAddVoid(void *a, const void *b, size_t size) PcmAddVoid(void *a, const void *b, size_t size) noexcept
{ {
constexpr size_t sample_size = Traits::SAMPLE_SIZE; constexpr size_t sample_size = Traits::SAMPLE_SIZE;
assert(size % sample_size == 0); assert(size % sample_size == 0);
@ -163,7 +164,8 @@ PcmAddVoid(void *a, const void *b, size_t size)
} }
static void static void
pcm_add_float(float *buffer1, const float *buffer2, unsigned num_samples) pcm_add_float(float *buffer1, const float *buffer2,
unsigned num_samples) noexcept
{ {
while (num_samples > 0) { while (num_samples > 0) {
float sample1 = *buffer1; float sample1 = *buffer1;
@ -175,7 +177,7 @@ pcm_add_float(float *buffer1, const float *buffer2, unsigned num_samples)
static bool static bool
pcm_add(void *buffer1, const void *buffer2, size_t size, pcm_add(void *buffer1, const void *buffer2, size_t size,
SampleFormat format) SampleFormat format) noexcept
{ {
switch (format) { switch (format) {
case SampleFormat::UNDEFINED: case SampleFormat::UNDEFINED:
@ -211,7 +213,7 @@ pcm_add(void *buffer1, const void *buffer2, size_t size,
bool bool
pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size, pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
SampleFormat format, float portion1) SampleFormat format, float portion1) noexcept
{ {
float s; float s;

View File

@ -47,6 +47,6 @@ class PcmDither;
gcc_warn_unused_result gcc_warn_unused_result
bool bool
pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size, pcm_mix(PcmDither &dither, void *buffer1, const void *buffer2, size_t size,
SampleFormat format, float portion1); SampleFormat format, float portion1) noexcept;
#endif #endif

View File

@ -25,7 +25,7 @@
* dithering. * dithering.
*/ */
constexpr static inline unsigned long constexpr static inline unsigned long
pcm_prng(unsigned long state) pcm_prng(unsigned long state) noexcept
{ {
return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL; return (state * 0x0019660dL + 0x3c6ef35fL) & 0xffffffffL;
} }

View File

@ -52,12 +52,12 @@ public:
* Closes the resampler. After that, you may call Open() * Closes the resampler. After that, you may call Open()
* again. * again.
*/ */
virtual void Close() = 0; virtual void Close() noexcept = 0;
/** /**
* Reset the filter's state, e.g. drop/flush buffers. * Reset the filter's state, e.g. drop/flush buffers.
*/ */
virtual void Reset() { virtual void Reset() noexcept {
} }
/** /**

View File

@ -68,7 +68,7 @@ enum class SampleFormat : uint8_t {
constexpr constexpr
#endif #endif
static inline bool static inline bool
audio_valid_sample_format(SampleFormat format) audio_valid_sample_format(SampleFormat format) noexcept
{ {
switch (format) { switch (format) {
case SampleFormat::S8: case SampleFormat::S8:
@ -90,7 +90,7 @@ audio_valid_sample_format(SampleFormat format)
constexpr constexpr
#endif #endif
static inline unsigned static inline unsigned
sample_format_size(SampleFormat format) sample_format_size(SampleFormat format) noexcept
{ {
switch (format) { switch (format) {
case SampleFormat::S8: case SampleFormat::S8:

View File

@ -39,7 +39,7 @@ struct LeftShiftSampleConvert {
static_assert(SrcTraits::BITS < DstTraits::BITS, static_assert(SrcTraits::BITS < DstTraits::BITS,
"Source format must be smaller than destination format"); "Source format must be smaller than destination format");
constexpr static DV Convert(SV src) { constexpr static DV Convert(SV src) noexcept {
return DV(src) << (DstTraits::BITS - SrcTraits::BITS); return DV(src) << (DstTraits::BITS - SrcTraits::BITS);
} }
}; };
@ -61,7 +61,7 @@ struct RightShiftSampleConvert {
static_assert(SrcTraits::BITS > DstTraits::BITS, static_assert(SrcTraits::BITS > DstTraits::BITS,
"Source format must be smaller than destination format"); "Source format must be smaller than destination format");
constexpr static DV Convert(SV src) { constexpr static DV Convert(SV src) noexcept {
return src >> (SrcTraits::BITS - DstTraits::BITS); return src >> (SrcTraits::BITS - DstTraits::BITS);
} }
}; };

View File

@ -26,7 +26,7 @@
#include <string.h> #include <string.h>
void void
PcmSilence(WritableBuffer<void> dest, SampleFormat format) PcmSilence(WritableBuffer<void> dest, SampleFormat format) noexcept
{ {
uint8_t pattern = 0; uint8_t pattern = 0;
if (format == SampleFormat::DSD) if (format == SampleFormat::DSD)

View File

@ -31,6 +31,6 @@ enum class SampleFormat : uint8_t;
* Fill the given buffer with the format-specific silence pattern. * Fill the given buffer with the format-specific silence pattern.
*/ */
void void
PcmSilence(WritableBuffer<void> dest, SampleFormat format); PcmSilence(WritableBuffer<void> dest, SampleFormat format) noexcept;
#endif #endif

View File

@ -134,7 +134,7 @@ SoxrPcmResampler::Open(AudioFormat &af, unsigned new_sample_rate)
} }
void void
SoxrPcmResampler::Close() SoxrPcmResampler::Close() noexcept
{ {
soxr_delete(soxr); soxr_delete(soxr);
} }

View File

@ -40,7 +40,7 @@ class SoxrPcmResampler final : public PcmResampler {
public: public:
AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override; AudioFormat Open(AudioFormat &af, unsigned new_sample_rate) override;
void Close() override; void Close() noexcept override;
ConstBuffer<void> Resample(ConstBuffer<void> src) override; ConstBuffer<void> Resample(ConstBuffer<void> src) override;
}; };

View File

@ -35,7 +35,7 @@ template<SampleFormat F, class Traits=SampleTraits<F>>
static inline typename Traits::value_type static inline typename Traits::value_type
pcm_volume_sample(PcmDither &dither, pcm_volume_sample(PcmDither &dither,
typename Traits::value_type _sample, typename Traits::value_type _sample,
int volume) int volume) noexcept
{ {
typename Traits::long_type sample(_sample); typename Traits::long_type sample(_sample);
@ -50,7 +50,7 @@ pcm_volume_change(PcmDither &dither,
typename Traits::pointer_type dest, typename Traits::pointer_type dest,
typename Traits::const_pointer_type src, typename Traits::const_pointer_type src,
size_t n, size_t n,
int volume) int volume) noexcept
{ {
for (size_t i = 0; i != n; ++i) for (size_t i = 0; i != n; ++i)
dest[i] = pcm_volume_sample<F, Traits>(dither, src[i], volume); dest[i] = pcm_volume_sample<F, Traits>(dither, src[i], volume);
@ -59,7 +59,7 @@ pcm_volume_change(PcmDither &dither,
static void static void
pcm_volume_change_8(PcmDither &dither, pcm_volume_change_8(PcmDither &dither,
int8_t *dest, const int8_t *src, size_t n, int8_t *dest, const int8_t *src, size_t n,
int volume) int volume) noexcept
{ {
pcm_volume_change<SampleFormat::S8>(dither, dest, src, n, volume); pcm_volume_change<SampleFormat::S8>(dither, dest, src, n, volume);
} }
@ -67,7 +67,7 @@ pcm_volume_change_8(PcmDither &dither,
static void static void
pcm_volume_change_16(PcmDither &dither, pcm_volume_change_16(PcmDither &dither,
int16_t *dest, const int16_t *src, size_t n, int16_t *dest, const int16_t *src, size_t n,
int volume) int volume) noexcept
{ {
pcm_volume_change<SampleFormat::S16>(dither, dest, src, n, volume); pcm_volume_change<SampleFormat::S16>(dither, dest, src, n, volume);
} }
@ -75,7 +75,7 @@ pcm_volume_change_16(PcmDither &dither,
static void static void
pcm_volume_change_24(PcmDither &dither, pcm_volume_change_24(PcmDither &dither,
int32_t *dest, const int32_t *src, size_t n, int32_t *dest, const int32_t *src, size_t n,
int volume) int volume) noexcept
{ {
pcm_volume_change<SampleFormat::S24_P32>(dither, dest, src, n, pcm_volume_change<SampleFormat::S24_P32>(dither, dest, src, n,
volume); volume);
@ -84,14 +84,14 @@ pcm_volume_change_24(PcmDither &dither,
static void static void
pcm_volume_change_32(PcmDither &dither, pcm_volume_change_32(PcmDither &dither,
int32_t *dest, const int32_t *src, size_t n, int32_t *dest, const int32_t *src, size_t n,
int volume) int volume) noexcept
{ {
pcm_volume_change<SampleFormat::S32>(dither, dest, src, n, volume); pcm_volume_change<SampleFormat::S32>(dither, dest, src, n, volume);
} }
static void static void
pcm_volume_change_float(float *dest, const float *src, size_t n, pcm_volume_change_float(float *dest, const float *src, size_t n,
float volume) float volume) noexcept
{ {
for (size_t i = 0; i != n; ++i) for (size_t i = 0; i != n; ++i)
dest[i] = src[i] * volume; dest[i] = src[i] * volume;

View File

@ -45,14 +45,14 @@ static constexpr int PCM_VOLUME_1S = PCM_VOLUME_1;
* Converts a float value (0.0 = silence, 1.0 = 100% volume) to an * Converts a float value (0.0 = silence, 1.0 = 100% volume) to an
* integer volume value (1000 = 100%). * integer volume value (1000 = 100%).
*/ */
static inline int static constexpr inline int
pcm_float_to_volume(float volume) pcm_float_to_volume(float volume) noexcept
{ {
return volume * PCM_VOLUME_1 + 0.5; return volume * PCM_VOLUME_1 + 0.5;
} }
static inline float static constexpr inline float
pcm_volume_to_float(int volume) pcm_volume_to_float(int volume) noexcept
{ {
return (float)volume / (float)PCM_VOLUME_1; return (float)volume / (float)PCM_VOLUME_1;
} }
@ -69,14 +69,14 @@ class PcmVolume {
PcmDither dither; PcmDither dither;
public: public:
PcmVolume() PcmVolume() noexcept
:volume(PCM_VOLUME_1) { :volume(PCM_VOLUME_1) {
#ifndef NDEBUG #ifndef NDEBUG
format = SampleFormat::UNDEFINED; format = SampleFormat::UNDEFINED;
#endif #endif
} }
unsigned GetVolume() const { unsigned GetVolume() const noexcept {
return volume; return volume;
} }
@ -85,7 +85,7 @@ public:
* [0..#PCM_VOLUME_1]; may be bigger than #PCM_VOLUME_1, but * [0..#PCM_VOLUME_1]; may be bigger than #PCM_VOLUME_1, but
* then it will most likely clip a lot * then it will most likely clip a lot
*/ */
void SetVolume(unsigned _volume) { void SetVolume(unsigned _volume) noexcept {
volume = _volume; volume = _volume;
} }
@ -101,7 +101,7 @@ public:
/** /**
* Closes the object. After that, you may call Open() again. * Closes the object. After that, you may call Open() again.
*/ */
void Close() { void Close() noexcept {
#ifndef NDEBUG #ifndef NDEBUG
assert(format != SampleFormat::UNDEFINED); assert(format != SampleFormat::UNDEFINED);
format = SampleFormat::UNDEFINED; format = SampleFormat::UNDEFINED;