Skip to content

Commit 272a4a6

Browse files
Increase expected size of output sample buffer.
1 parent d737def commit 272a4a6

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/samplerate.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,14 @@ class Resampler {
158158
if (channels != _channels || channels == 0)
159159
throw std::domain_error("Invalid number of channels in input data.");
160160

161+
// Add a "fudge factor" of 10,000. This is because the actual number of
162+
// output samples generated on the last call when input is terminated can
163+
// be more than the expected number of output samples during mid-stream
164+
// steady-state processing. (Also, when the stream is started, the number
165+
// of output samples generated will generally be zero or otherwise less
166+
// than the number of samples in mid-stream processing.)
161167
const auto new_size =
162-
static_cast<size_t>(std::ceil(inbuf.shape[0] * sr_ratio));
168+
static_cast<size_t>(std::ceil(inbuf.shape[0] * sr_ratio)) + 10000;
163169

164170
// allocate output array
165171
std::vector<size_t> out_shape{new_size};

0 commit comments

Comments
 (0)