Alsa-Devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Clemens Ladisch <clemens@ladisch.de>
To: alsa-devel@alsa-project.org
Subject: Re: pcm_rate API  question
Date: Mon, 30 Sep 2013 10:59:35 +0200	[thread overview]
Message-ID: <52493D77.40601@ladisch.de> (raw)
In-Reply-To: <1380362320.63959.YahooMailNeo@web171406.mail.ir2.yahoo.com>

Rob Sykes wrote:
>> Typically there is some buffering/delay within a resampler -- how
>> does the pcm_rate API allow for this?

The API itself does not allow for this.  Your code must generate
dst_frames samples.

At startup, prefix the output with zero samples.  For example,
rate_samplerate.c in the alsa-plugins package does this:

    src_short_to_float_array(src, rate->src_buf, src_frames * rate->channels);
    src_process(rate->state, &rate->data);
    if (rate->data.output_frames_gen < dst_frames)
            ofs = dst_frames - rate->data.output_frames_gen;
    else
            ofs = 0;
    src_float_to_short_array(rate->dst_buf, dst + ofs * rate->channels,
                             rate->data.output_frames_gen * rate->channels);

> If, as you say above, the buffer sizes

the period sizes

> define the conversion ratio, then this seems to imply that alsa is
> unable to perform accurate rate conversion for one of the most common
> uses!

The conversion indeed is not accurate, unless you are using a period
size of an integer multiple of 441 frames.  In your example, the
application probably used a buffer of 0.5 s and four periods per buffer;
it should either double the buffer size or halve the number of periods.


Regards,
Clemens

  reply	other threads:[~2013-09-30  8:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 11:59 pcm_rate API question Rob Sykes
2013-09-27 12:38 ` Clemens Ladisch
     [not found]   ` <1380295697.44147.YahooMailNeo@web171405.mail.ir2.yahoo.com>
2013-09-28  9:58     ` Rob Sykes
2013-09-30  8:59       ` Clemens Ladisch [this message]
2013-09-30 11:15         ` Rob Sykes
2013-09-30 14:16           ` Clemens Ladisch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=52493D77.40601@ladisch.de \
    --to=clemens@ladisch.de \
    --cc=alsa-devel@alsa-project.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox