From: James Courtier-Dutton <James@superbug.demon.co.uk>
To: alsa-devel@lists.sourceforge.net
Subject: [PATCH] fix resamplers.
Date: Wed, 21 Jul 2004 16:14:43 +0100 [thread overview]
Message-ID: <40FE8863.50009@superbug.demon.co.uk> (raw)
[-- Attachment #1: Type: text/plain, Size: 295 bytes --]
The current pcm_rate.c tends to insert zero samples in the stream.
E.g. Downsampling from 48000 -> 16000
Starts with a block of 2048, and has to create 682 samples.
The current code sometimes only produces 681 samples, leaving the last
one zero.
The attached patch fixes this problem.
James
[-- Attachment #2: sample-rate-fix.diff.txt --]
[-- Type: text/plain, Size: 3805 bytes --]
? alsa-lib/ltconfig
? alsa-lib/src/pcm/pcm_rate.c.org
Index: alsa-lib/src/pcm/pcm_rate.c
===================================================================
RCS file: /cvsroot/alsa/alsa-lib/src/pcm/pcm_rate.c,v
retrieving revision 1.84
diff -u -r1.84 pcm_rate.c
--- alsa-lib/src/pcm/pcm_rate.c 26 Apr 2004 07:40:13 -0000 1.84
+++ alsa-lib/src/pcm/pcm_rate.c 21 Jul 2004 15:02:59 -0000
@@ -585,47 +585,47 @@
do {
snd_pcm_uframes_t cframes;
- cframes = snd_pcm_rate_client_frames(pcm, slave->period_size - 1);
- if (cframes == pcm->period_size - 1)
+ cframes = snd_pcm_rate_client_frames(pcm, slave->period_size);
+ if (cframes == pcm->period_size)
break;
- if (cframes > pcm->period_size - 1) {
+ if (cframes > pcm->period_size) {
rate->pitch++;
- if ((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size - 1) < pcm->period_size - 1) {
- SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size - 1, pcm->period_size - 1);
+ if ((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size) < pcm->period_size) {
+ SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size, pcm->period_size);
return -EIO;
}
} else {
rate->pitch--;
- if ((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size - 1) > pcm->period_size - 1) {
+ if ((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size) > pcm->period_size) {
SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size - 1, pcm->period_size - 1);
return -EIO;
}
}
} while (1);
- assert((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size - 1) == pcm->period_size - 1);
+ assert((snd_pcm_uframes_t)snd_pcm_rate_client_frames(pcm, slave->period_size) == pcm->period_size);
} else {
rate->pitch = (((u_int64_t)pcm->period_size * LINEAR_DIV) + slave->period_size - 1) / slave->period_size;
do {
snd_pcm_uframes_t cframes;
- cframes = snd_pcm_rate_slave_frames(pcm, pcm->period_size - 1);
- if (cframes == slave->period_size - 1)
+ cframes = snd_pcm_rate_slave_frames(pcm, pcm->period_size);
+ if (cframes == slave->period_size)
break;
- if (cframes > slave->period_size - 1) {
+ if (cframes > slave->period_size) {
rate->pitch++;
- if ((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size - 1) < slave->period_size - 1) {
- SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size - 1, pcm->period_size - 1);
+ if ((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size) < slave->period_size) {
+ SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size, pcm->period_size);
return -EIO;
}
} else {
rate->pitch--;
- if ((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size - 1) > slave->period_size - 1) {
- SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size - 1, pcm->period_size - 1);
+ if ((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size) > slave->period_size) {
+ SNDERR("Unable to satisfy pitch condition (%i/%i - %li/%li)\n", slave->rate, pcm->rate, slave->period_size, pcm->period_size);
return -EIO;
}
}
} while (1);
- assert((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size - 1) == slave->period_size - 1);
+ assert((snd_pcm_uframes_t)snd_pcm_rate_slave_frames(pcm, pcm->period_size) == slave->period_size);
}
recalc(pcm, &sparams->avail_min);
rate->orig_avail_min = sparams->avail_min;
next reply other threads:[~2004-07-21 15:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-21 15:14 James Courtier-Dutton [this message]
2004-07-21 18:06 ` [PATCH] fix resamplers James Courtier-Dutton
2004-07-21 21:50 ` James Courtier-Dutton
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=40FE8863.50009@superbug.demon.co.uk \
--to=james@superbug.demon.co.uk \
--cc=alsa-devel@lists.sourceforge.net \
/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