[pulseaudio-discuss] [PATCH v2 3/3] resampler: Add support for resamplers that consume less data than asked.
Tanu Kaskinen
tanuk at iki.fi
Thu Apr 26 01:24:24 PDT 2012
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.
--
Tanu
More information about the pulseaudio-discuss
mailing list