summaryrefslogtreecommitdiffstats
path: root/sys/dev/sound/pcm/feeder_rate.c
diff options
context:
space:
mode:
authorariff <ariff@FreeBSD.org>2006-01-22 15:06:49 +0000
committerariff <ariff@FreeBSD.org>2006-01-22 15:06:49 +0000
commit3a3753e6561928c0918f5f5c65642d7661d68468 (patch)
tree324fadb042b8f178336f219e5a0d1749d51d031f /sys/dev/sound/pcm/feeder_rate.c
parent7c1b5ba95ea0c00aed508231bd1a7a1c41210cd5 (diff)
downloadFreeBSD-src-3a3753e6561928c0918f5f5c65642d7661d68468.zip
FreeBSD-src-3a3753e6561928c0918f5f5c65642d7661d68468.tar.gz
Various fixups:
feeder.h: feeder.c: - Implement scoring mechanisme to select best format for conversion. This is actually part of newer format chaining procedures which will be commited someday. Confusion during chaining process solved by this scoring since it will try to reduce list of from/to formats to a single, best format. Related PR: kern/91683 channel.c: - Simplify feeder building process since we have smarter format chaining. feeder_fmt.c: - Add few more sign conversion feeders for 24 and 32 bit format. feeder_rate.c: - Force buffer / bytes allignment. Unaligned buffer may cause panics during recording on pure 32bit sample format if it involves feeder_rate as part of feeders chain. Tested on: ATI IXP, force 32bit recording. MFC after: 5 days
Diffstat (limited to 'sys/dev/sound/pcm/feeder_rate.c')
-rw-r--r--sys/dev/sound/pcm/feeder_rate.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/sys/dev/sound/pcm/feeder_rate.c b/sys/dev/sound/pcm/feeder_rate.c
index 977d77d..a8f55e8 100644
--- a/sys/dev/sound/pcm/feeder_rate.c
+++ b/sys/dev/sound/pcm/feeder_rate.c
@@ -69,6 +69,7 @@
SND_DECLARE_FILE("$FreeBSD$");
#define RATE_ASSERT(x, y) /* KASSERT(x,y) */
+#define RATE_TEST(x, y) /* if (!(x)) printf y */
#define RATE_TRACE(x...) /* printf(x) */
MALLOC_DEFINE(M_RATEFEEDER, "ratefeed", "pcm rate feeder");
@@ -700,10 +701,16 @@ feed_rate(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
* sampling without causing missing samples or excessive buffer
* feeding.
*/
- RATE_ASSERT(count >= 4 && count % 4 == 0,
- ("%s: Count size not byte integral\n", __func__));
+ RATE_TEST(count >= 4 && (count & 3) == 0,
+ ("%s: Count size not byte integral (%d)\n", __func__, count));
+ if (count < 4)
+ return 0;
count >>= 1;
+ count &= ~1;
slot = (((info->gx * (count >> 1)) + info->gy - info->alpha - 1) / info->gy) << 1;
+ RATE_TEST((slot & 1) == 0, ("%s: Slot count not sample integral (%d)\n",
+ __func__, slot));
+ slot &= ~1;
/*
* Optimize buffer feeding aggresively to ensure calculated slot
* can be fitted nicely into available buffer free space, hence
@@ -729,23 +736,25 @@ feed_rate(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
for (;;) {
fetch = info->bufsz - info->bpos;
RATE_ASSERT(fetch >= 0,
- ("%s: Buffer overrun: %d > %d\n",
+ ("%s: [1] Buffer overrun: %d > %d\n",
__func__, info->bpos, info->bufsz));
if (slot < fetch)
fetch = slot;
+ fetch &= ~1;
if (fetch > 0) {
- RATE_ASSERT(fetch % 2 == 0,
- ("%s: Fetch size not sample integral\n",
- __func__));
+ RATE_TEST((fetch & 1) == 0,
+ ("%s: Fetch size not sample integral (%d)\n",
+ __func__, fetch));
fetch = FEEDER_FEED(f->source, c,
(uint8_t *)(info->buffer + info->bpos),
fetch << 1, source);
if (fetch == 0)
break;
- RATE_ASSERT(fetch % 4 == 0,
- ("%s: Fetch size not byte integral\n",
- __func__));
+ RATE_TEST((fetch & 3) == 0,
+ ("%s: Fetch size not byte integral (%d)\n",
+ __func__, fetch));
fetch >>= 1;
+ fetch &= ~1;
info->bpos += fetch;
slot -= fetch;
RATE_ASSERT(slot >= 0,
@@ -759,20 +768,21 @@ feed_rate(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
break;
}
if (info->pos == info->bpos) {
- RATE_ASSERT(info->pos == 2,
+ RATE_TEST(info->pos == 2,
("%s: EOF while in progress\n", __func__));
break;
}
RATE_ASSERT(info->pos <= info->bpos,
- ("%s: Buffer overrun: %d > %d\n", __func__,
+ ("%s: [2] Buffer overrun: %d > %d\n", __func__,
info->pos, info->bpos));
RATE_ASSERT(info->pos < info->bpos,
("%s: Zero buffer!\n", __func__));
- RATE_ASSERT((info->bpos - info->pos) % 2 == 0,
- ("%s: Buffer not sample integral\n", __func__));
+ RATE_ASSERT(((info->bpos - info->pos) & 1) == 0,
+ ("%s: Buffer not sample integral (%d)\n",
+ __func__, info->bpos - info->pos));
i += info->convert(info, dst + i, count - i);
RATE_ASSERT(info->pos <= info->bpos,
- ("%s: Buffer overrun: %d > %d\n",
+ ("%s: [3] Buffer overrun: %d > %d\n",
__func__, info->pos, info->bpos));
if (info->pos == info->bpos) {
/*
@@ -788,6 +798,7 @@ feed_rate(struct pcm_feeder *f, struct pcm_channel *c, uint8_t *b,
if (i == count)
break;
}
+ RATE_TEST(count == i, ("Expect: %u , Got: %u\n", count << 1, i << 1));
return i << 1;
}
OpenPOWER on IntegriCloud