Commit 31ed83f5 authored by Stefan Westerfeld's avatar Stefan Westerfeld

Implement skip() function for Limiter.

Signed-off-by: Stefan Westerfeld's avatarStefan Westerfeld <stefan@space.twc.de>
parent c78e8094
......@@ -66,6 +66,28 @@ Limiter::process (const vector<float>& samples)
return out;
}
size_t
Limiter::skip (size_t zeros)
{
vector<float> samples (zeros * n_channels);
assert (block_size >= 1);
assert (samples.size() % n_channels == 0); // process should be called with whole frames
buffer.insert (buffer.end(), samples.begin(), samples.end());
/* need at least two complete blocks in buffer to produce output */
const uint buffered_blocks = buffer.size() / n_channels / block_size;
if (buffered_blocks < 2)
return 0;
const uint blocks_todo = buffered_blocks - 1;
buffer.erase (buffer.begin(), buffer.begin() + blocks_todo * block_size * n_channels);
return blocks_todo * block_size;
}
float
Limiter::block_max (const float *in)
{
......
......@@ -42,6 +42,7 @@ public:
void set_ceiling (float ceiling);
std::vector<float> process (const std::vector<float>& samples);
size_t skip (size_t zeros);
std::vector<float> flush();
};
......
......@@ -670,13 +670,12 @@ add_stream_watermark (AudioInputStream *in_stream, AudioOutputStream *out_stream
{
total_input_frames += Params::frame_size;
audio_buffer_frames += Params::frame_size;
samples.assign (wm_resampler.skip (Params::frame_size) * n_channels, 0);
size_t to_read = samples.size() / n_channels;
audio_buffer_frames -= to_read;
size_t frames = wm_resampler.skip (Params::frame_size);
audio_buffer_frames -= frames;
samples = limiter.process (samples);
frames = limiter.skip (frames);
err = out_stream->write_frames (samples);
err = out_stream->write_frames (vector<float> (frames * n_channels));
total_output_frames += samples.size() / n_channels;
zero_frames -= Params::frame_size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment