pcm/Silence: use std::span
This commit is contained in:
parent
3bb7693200
commit
84e5da4bf0
|
@ -50,7 +50,6 @@
|
|||
#include "util/StringStrip.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
@ -237,7 +236,7 @@ RouteFilter::FilterPCM(ConstBuffer<void> src)
|
|||
void *const result = output_buffer.Get(result_size);
|
||||
|
||||
// A moving pointer that always refers to the currently filled channel of the currently handled frame, in the output
|
||||
auto *chan_destination = (uint8_t *)result;
|
||||
auto *chan_destination = (std::byte *)result;
|
||||
|
||||
// Perform our copy operations, with N input channels and M output channels
|
||||
for (unsigned int s=0; s<number_of_frames; ++s) {
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "SampleFormat.hxx"
|
||||
#include "pcm/Silence.hxx"
|
||||
#include "pcm/CheckAudioFormat.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
extern "C" {
|
||||
#include <libavfilter/buffersrc.h>
|
||||
|
@ -42,7 +41,7 @@ DetectFilterOutputFormat(const AudioFormat &in_audio_format,
|
|||
const size_t silence_size = in_audio_format.GetFrameSize();
|
||||
assert(sizeof(silence) >= silence_size);
|
||||
|
||||
PcmSilence(WritableBuffer<void>{&silence, silence_size},
|
||||
PcmSilence(std::as_writable_bytes(std::span{silence}),
|
||||
in_audio_format.format);
|
||||
|
||||
Frame frame;
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "Silence.hxx"
|
||||
#include "util/ByteReverse.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
@ -94,7 +93,7 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels,
|
|||
}
|
||||
|
||||
/* prepare a moment of silence for GetSilence() */
|
||||
char buffer[sizeof(silence_buffer)];
|
||||
std::byte buffer[sizeof(silence_buffer)];
|
||||
const size_t buffer_size = GetInputBlockSize();
|
||||
assert(buffer_size < sizeof(buffer));
|
||||
PcmSilence({buffer, buffer_size}, src_sample_format);
|
||||
|
|
|
@ -23,7 +23,6 @@
|
|||
#include "Silence.hxx"
|
||||
#include "Traits.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
#include <array>
|
||||
#include <algorithm>
|
||||
|
@ -109,7 +108,7 @@ StereoToN(typename Traits::pointer dest,
|
|||
assert((end - src) % 2 == 0);
|
||||
|
||||
std::array<typename Traits::value_type, MAX_CHANNELS - 2> silence;
|
||||
PcmSilence({&silence.front(), sizeof(silence)}, F);
|
||||
PcmSilence(std::as_writable_bytes(std::span{silence}), F);
|
||||
|
||||
while (src != end) {
|
||||
/* copy left/right to front-left/front-right, which is
|
||||
|
|
|
@ -20,16 +20,15 @@
|
|||
#include "Silence.hxx"
|
||||
#include "Traits.hxx"
|
||||
#include "SampleFormat.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
|
||||
void
|
||||
PcmSilence(WritableBuffer<void> dest, SampleFormat format) noexcept
|
||||
PcmSilence(std::span<std::byte> dest, SampleFormat format) noexcept
|
||||
{
|
||||
uint8_t pattern = 0;
|
||||
std::byte pattern{0};
|
||||
if (format == SampleFormat::DSD)
|
||||
pattern = SampleTraits<SampleFormat::DSD>::SILENCE;
|
||||
pattern = std::byte{SampleTraits<SampleFormat::DSD>::SILENCE};
|
||||
|
||||
memset(dest.data, pattern, dest.size);
|
||||
std::fill(dest.begin(), dest.end(), pattern);
|
||||
}
|
||||
|
|
|
@ -20,15 +20,16 @@
|
|||
#ifndef MPD_PCM_SILENCE_HXX
|
||||
#define MPD_PCM_SILENCE_HXX
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
|
||||
template<typename T> struct WritableBuffer;
|
||||
enum class SampleFormat : uint8_t;
|
||||
|
||||
/**
|
||||
* Fill the given buffer with the format-specific silence pattern.
|
||||
*/
|
||||
void
|
||||
PcmSilence(WritableBuffer<void> dest, SampleFormat format) noexcept;
|
||||
PcmSilence(std::span<std::byte> dest, SampleFormat format) noexcept;
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "Silence.hxx"
|
||||
#include "Traits.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "util/TransformN.hxx"
|
||||
|
||||
|
@ -204,7 +203,8 @@ PcmVolume::Apply(ConstBuffer<void> src) noexcept
|
|||
|
||||
if (volume == 0) {
|
||||
/* optimized special case: 0% volume = memset(0) */
|
||||
PcmSilence({data, dest_size}, format);
|
||||
PcmSilence(std::span{(std::byte *)data, dest_size},
|
||||
format);
|
||||
return { data, dest_size };
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue