On Thu, 2012-04-26 at 11:24 +0300, Tanu Kaskinen wrote: > On Thu, 2012-04-26 at 08:20 +0200, David Henningsson wrote: > > > size_t pa_resampler_result(pa_resampler *r, size_t in_length) { > > > pa_assert(r); > > > > > > - /* Let's round up here */ > > > - > > > - return (((((in_length + r->i_fz-1) / r->i_fz) * r->o_ss.rate) + r->i_ss.rate-1) / r->i_ss.rate) * r->o_fz; > > > + /* Let's round up here to ensure that the caller will always allocate big > > > + * enough output buffer. */ > > > + return (((((in_length + r->i_fz-1) / r->i_fz + r->leftover_buf.length / r->o_fz) * r->o_ss.rate) + r->i_ss.rate-1) / r->i_ss.rate) * r->o_fz; > > > > A temporary variable or two here would increase readability and ease > > debugging. > > > > > } > > > > > > size_t pa_resampler_max_block_size(pa_resampler *r) { > > > @@ -413,7 +428,7 @@ size_t pa_resampler_max_block_size(pa_resampler *r) { > > > > > > fs = pa_frame_size(&ss); > > > > > > - return (((block_size_max/fs - EXTRA_FRAMES)*r->i_ss.rate)/ss.rate)*r->i_fz; > > > + return (((block_size_max / fs - EXTRA_FRAMES - r->leftover_buf.length / r->o_fz) * r->i_ss.rate) / ss.rate) * r->i_fz; > > > > A temporary variable or two here would increase readability and ease > > debugging. > > Good suggestions. There was also wrong frame size used in these > calculations: the leftover length needs to be divided by working frame > size instead of output frame size. Would be neat to have a test case for this -- something like a dummy resampler that wraps some other resampler and intentionally consumes less than the total. -- Arun