pcm/Export: add GetSilence()
This commit is contained in:
@@ -21,10 +21,13 @@
|
||||
#include "AudioFormat.hxx"
|
||||
#include "Order.hxx"
|
||||
#include "Pack.hxx"
|
||||
#include "Silence.hxx"
|
||||
#include "util/ByteReverse.hxx"
|
||||
#include "util/ConstBuffer.hxx"
|
||||
#include "util/WritableBuffer.hxx"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
void
|
||||
PcmExport::Open(SampleFormat sample_format, unsigned _channels,
|
||||
@@ -89,6 +92,16 @@ PcmExport::Open(SampleFormat sample_format, unsigned _channels,
|
||||
if (sample_size > 1)
|
||||
reverse_endian = sample_size;
|
||||
}
|
||||
|
||||
/* prepare a moment of silence for GetSilence() */
|
||||
char buffer[sizeof(silence_buffer)];
|
||||
const size_t buffer_size = GetInputBlockSize();
|
||||
assert(buffer_size < sizeof(buffer));
|
||||
PcmSilence({buffer, buffer_size}, src_sample_format);
|
||||
auto s = Export({buffer, buffer_size});
|
||||
assert(s.size < sizeof(silence_buffer));
|
||||
silence_size = s.size;
|
||||
memcpy(silence_buffer, s.data, s.size);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -190,6 +203,12 @@ PcmExport::GetOutputBlockSize() const noexcept
|
||||
return GetOutputFrameSize();
|
||||
}
|
||||
|
||||
ConstBuffer<void>
|
||||
PcmExport::GetSilence() const noexcept
|
||||
{
|
||||
return {silence_buffer, silence_size};
|
||||
}
|
||||
|
||||
unsigned
|
||||
PcmExport::Params::CalcOutputSampleRate(unsigned sample_rate) const noexcept
|
||||
{
|
||||
|
||||
@@ -79,6 +79,10 @@ class PcmExport {
|
||||
*/
|
||||
PcmBuffer reverse_buffer;
|
||||
|
||||
size_t silence_size;
|
||||
|
||||
uint8_t silence_buffer[64]; /* worst-case size */
|
||||
|
||||
/**
|
||||
* The sample format of input data.
|
||||
*/
|
||||
@@ -210,6 +214,14 @@ public:
|
||||
gcc_pure
|
||||
size_t GetOutputBlockSize() const noexcept;
|
||||
|
||||
/**
|
||||
* @return one block of silence output; its size is the same
|
||||
* as GetOutputBlockSize(); the pointer is valid as long as
|
||||
* this #PcmExport object exists and until the next Open()
|
||||
* call
|
||||
*/
|
||||
ConstBuffer<void> GetSilence() const noexcept;
|
||||
|
||||
/**
|
||||
* Export a PCM buffer.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user