Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
frame_fill.hpp
Go to the documentation of this file.
1#pragma once
2
3// Small, platform-independent helpers for handling partial-read input
4// buffers in the audio callback. Keeping the fill math independent of
5// platform audio backends makes it unit-testable without pulling in Oboe
6// or other device APIs.
7
8#include <cstddef>
9#include <cstring>
10
11namespace pulp::audio {
12
26inline void zero_fill_short_read(float* buf,
27 int frames_read,
28 int total_frames,
29 int channels) noexcept {
30 if (buf == nullptr) return;
31 if (channels <= 0) return;
32 if (total_frames <= 0) return;
33 if (frames_read < 0) frames_read = 0;
34 if (frames_read > total_frames) frames_read = total_frames;
35 const std::size_t samples_read =
36 static_cast<std::size_t>(frames_read) * static_cast<std::size_t>(channels);
37 const std::size_t samples_total =
38 static_cast<std::size_t>(total_frames) * static_cast<std::size_t>(channels);
39 if (samples_read >= samples_total) return;
40 std::memset(buf + samples_read, 0,
41 sizeof(float) * (samples_total - samples_read));
42}
43
44} // namespace pulp::audio
Definition analyzer_provider.hpp:12
void zero_fill_short_read(float *buf, int frames_read, int total_frames, int channels) noexcept
Zero-fill the trailing samples of an interleaved input buffer after a short read.
Definition frame_fill.hpp:26