diff --git a/sys/dev/sound/pcm/channel.c b/sys/dev/sound/pcm/channel.c index 9fd4e4a7ca65..e68421853e64 100644 --- a/sys/dev/sound/pcm/channel.c +++ b/sys/dev/sound/pcm/channel.c @@ -44,6 +44,7 @@ static void chn_dmaupdate(pcm_channel *c); static void chn_wrintr(pcm_channel *c); static void chn_rdintr(pcm_channel *c); static u_int32_t chn_start(pcm_channel *c); +static int chn_buildfeeder(pcm_channel *c); /* * SOUND OUTPUT @@ -307,14 +308,16 @@ static int chn_wrfeed2nd(pcm_channel *c, struct uio *buf) { snd_dbuf *bs = &c->buffer2nd; - int l, w, wacc; + int l, w, wacc, hl; + u_int8_t hackbuf[64]; /* The DMA buffer may have some space. */ while (chn_wrfeed(c) > 0); /* ensure we always have a whole number of samples */ wacc = 0; - while (buf->uio_resid > 0 && bs->fl > 0) { + hl = 0; + while (buf->uio_resid > 0 && bs->fl > 64) { /* * The size of the data to move here does not have to be * aligned. We take care of it upon moving the data to a @@ -322,7 +325,14 @@ chn_wrfeed2nd(pcm_channel *c, struct uio *buf) */ l = min(bs->fl, bs->bufsize - bs->fp); /* Move the samples, update the markers and pointers. */ - w = c->feeder->feed(c->feeder, c, bs->buf + bs->fp, l, buf); + if (l < 64) { + w = c->feeder->feed(c->feeder, c, hackbuf, 64, buf); + l = min(w, bs->bufsize - bs->fp); + bcopy(hackbuf, bs->buf + bs->fp, l); + if (w > l) + bcopy(hackbuf + l, bs->buf, w - l); + } else + w = c->feeder->feed(c->feeder, c, bs->buf + bs->fp, l, buf); if (w == 0) panic("no feed"); bs->rl += w; @@ -1093,6 +1103,18 @@ chn_flush(pcm_channel *c) return 0; } +int +fmtvalid(u_int32_t fmt, u_int32_t *fmtlist) +{ + int i; + + for (i = 0; fmtlist[i]; i++) + if (fmt == fmtlist[i]) + return 1; + + return 0; +} + int chn_reset(pcm_channel *c, u_int32_t fmt) { @@ -1104,6 +1126,7 @@ chn_reset(pcm_channel *c, u_int32_t fmt) if (r) return r; if (fmt) { + c->speed = DSP_DEFAULT_SPEED; r = chn_setformat(c, fmt); if (r == 0) r = chn_setspeed(c, DSP_DEFAULT_SPEED); @@ -1146,6 +1169,7 @@ chn_init(pcm_channel *c, void *devinfo, int dir) c->feeder->source = NULL; c->flags = 0; + c->feederflags = 0; c->buffer.chan = -1; c->devinfo = c->init(devinfo, &c->buffer, c, dir); if (c->devinfo == NULL || c->buffer.bufsize == 0) @@ -1202,11 +1226,45 @@ chn_setvolume(pcm_channel *c, int left, int right) int chn_setspeed(pcm_channel *c, int speed) { + pcm_feeder *f; + int r, hwspd, delta; + + DEB(printf("want speed %d, ", speed)); if (speed <= 0) return EINVAL; - /* could add a feeder for rate conversion */ if (CANCHANGE(c)) { - c->speed = c->setspeed(c->devinfo, speed); + c->speed = speed; + hwspd = speed; + RANGE(hwspd, chn_getcaps(c)->minspeed, chn_getcaps(c)->maxspeed); + DEB(printf("try speed %d, ", hwspd)); + hwspd = c->setspeed(c->devinfo, hwspd); + DEB(printf("got speed %d, ", hwspd)); + delta = hwspd - speed; + if (delta < 0) + delta = -delta; + c->feederflags &= ~(1 << FEEDER_RATE); + if (delta > 500) + c->feederflags |= 1 << FEEDER_RATE; + else + speed = hwspd; + r = chn_buildfeeder(c); + DEB(printf("r = %d\n", r)); + if (r) + return r; + if (!(c->feederflags & (1 << FEEDER_RATE))) + return 0; + f = chn_findfeeder(c, FEEDER_RATE); + DEB(printf("feedrate = %p\n", f)); + if (f == NULL) + return EINVAL; + r = feeder_set(f, FEEDRATE_SRC, speed); + DEB(printf("feeder_set(FEEDRATE_SRC, %d) = %d\n", speed, r)); + if (r) + return r; + r = feeder_set(f, FEEDRATE_DST, hwspd); + DEB(printf("feeder_set(FEEDRATE_DST, %d) = %d\n", hwspd, r)); + if (r) + return r; return 0; } c->speed = speed; @@ -1214,42 +1272,31 @@ chn_setspeed(pcm_channel *c, int speed) return 0; } -int -fmtvalid(u_int32_t fmt, u_int32_t *fmtlist) -{ - int i; - - for (i = 0; fmtlist[i]; i++) - if (fmt == fmtlist[i]) - return 1; - - return 0; -} - int chn_setformat(pcm_channel *c, u_int32_t fmt) { snd_dbuf *b = &c->buffer; snd_dbuf *bs = &c->buffer2nd; + int r; u_int32_t hwfmt; if (CANCHANGE(c)) { - while (chn_removefeeder(c) == 0); + DEB(printf("want format %d\n", fmt)); c->format = fmt; c->feederdesc->out = c->format; hwfmt = c->format; - if (!fmtvalid(hwfmt, chn_getcaps(c)->fmtlist)) { - if (c->flags & CHN_F_MAPPED) - return EINVAL; - hwfmt = chn_feedchain(c, chn_getcaps(c)->fmtlist); - if (hwfmt == 0) - return EINVAL; - } + c->feederflags &= ~(1 << FEEDER_FMT); + if (!fmtvalid(hwfmt, chn_getcaps(c)->fmtlist)) + c->feederflags |= 1 << FEEDER_FMT; + r = chn_buildfeeder(c); + if (r) + return r; + hwfmt = c->feeder->desc->out; b->fmt = hwfmt; bs->fmt = hwfmt; chn_resetbuf(c); c->setformat(c->devinfo, hwfmt); - return 0; + return chn_setspeed(c, c->speed); } c->format = fmt; c->flags |= CHN_F_INIT; @@ -1354,4 +1401,53 @@ chn_getformats(pcm_channel *c) return fmts; } +static int +chn_buildfeeder(pcm_channel *c) +{ + pcm_feeder *f; + struct pcm_feederdesc desc; + u_int32_t tmp[2], src, dst, type, flags; + while (chn_removefeeder(c) == 0); + c->align = 0; + flags = c->feederflags; + src = c->feeder->desc->out; + if ((c->flags & CHN_F_MAPPED) && (flags != 0)) + return EINVAL; + DEB(printf("not mapped, flags %x, ", flags)); + for (type = FEEDER_RATE; type <= FEEDER_LAST; type++) { + if (flags & (1 << type)) { + desc.type = type; + desc.in = 0; + desc.out = 0; + desc.flags = 0; + DEB(printf("find feeder type %d, ", type)); + f = feeder_get(&desc); + DEB(printf("got %p\n", f)); + if (f == NULL) + return EINVAL; + dst = f->desc->in; + if (src != dst) { + DEB(printf("build fmtchain from %x to %x: ", src, dst)); + tmp[0] = dst; + tmp[1] = 0; + if (chn_fmtchain(c, tmp) == 0) + return EINVAL; + DEB(printf("ok\n")); + } + if (chn_addfeeder(c, f)) + return EINVAL; + src = f->desc->out; + DEB(printf("added feeder %p, output %x\n", f, src)); + dst = 0; + flags &= ~(1 << type); + } + } + if (!fmtvalid(src, chn_getcaps(c)->fmtlist)) { + if (chn_fmtchain(c, chn_getcaps(c)->fmtlist) == 0) + return EINVAL; + DEB(printf("built fmtchain from %x to %x\n", src, c->feeder->desc->out)); + flags &= ~(1 << FEEDER_FMT); + } + return 0; +} diff --git a/sys/dev/sound/pcm/datatypes.h b/sys/dev/sound/pcm/datatypes.h index c6343a573579..3dcf6703f55b 100644 --- a/sys/dev/sound/pcm/datatypes.h +++ b/sys/dev/sound/pcm/datatypes.h @@ -81,11 +81,7 @@ typedef int (pcmfeed_init_t)(pcm_feeder *feeder); typedef int (pcmfeed_free_t)(pcm_feeder *feeder); typedef int (pcmfeed_feed_t)(pcm_feeder *feeder, pcm_channel *c, u_int8_t *buffer, u_int32_t count, struct uio *stream); - -#define FEEDER_ROOT 1 -#define FEEDER_FMT 2 -#define FEEDER_RATE 3 -#define FEEDER_FILTER 4 +typedef int (pcmfeed_set_t)(pcm_feeder *feeder, int what, int value); struct pcm_feederdesc { u_int32_t type; @@ -94,14 +90,13 @@ struct pcm_feederdesc { int idx; }; -#define MAXFEEDERS 256 - struct _pcm_feeder { char name[16]; int align; struct pcm_feederdesc *desc; pcmfeed_init_t *init; pcmfeed_free_t *free; + pcmfeed_set_t *set; pcmfeed_feed_t *feed; void *data; pcm_feeder *source; @@ -147,8 +142,9 @@ struct _pcm_channel { int volume; u_int32_t speed; - u_int32_t flags; u_int32_t format; + u_int32_t flags; + u_int32_t feederflags; u_int32_t blocks; int direction; diff --git a/sys/dev/sound/pcm/feeder.c b/sys/dev/sound/pcm/feeder.c index 66e9fb1f28eb..c10d62e0d543 100644 --- a/sys/dev/sound/pcm/feeder.c +++ b/sys/dev/sound/pcm/feeder.c @@ -28,79 +28,9 @@ #include -#define FEEDBUFSZ 8192 +#define MAXFEEDERS 256 #undef FEEDER_DEBUG -static unsigned char ulaw_to_u8[] = { - 3, 7, 11, 15, 19, 23, 27, 31, - 35, 39, 43, 47, 51, 55, 59, 63, - 66, 68, 70, 72, 74, 76, 78, 80, - 82, 84, 86, 88, 90, 92, 94, 96, - 98, 99, 100, 101, 102, 103, 104, 105, - 106, 107, 108, 109, 110, 111, 112, 113, - 113, 114, 114, 115, 115, 116, 116, 117, - 117, 118, 118, 119, 119, 120, 120, 121, - 121, 121, 122, 122, 122, 122, 123, 123, - 123, 123, 124, 124, 124, 124, 125, 125, - 125, 125, 125, 125, 126, 126, 126, 126, - 126, 126, 126, 126, 127, 127, 127, 127, - 127, 127, 127, 127, 127, 127, 127, 127, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 253, 249, 245, 241, 237, 233, 229, 225, - 221, 217, 213, 209, 205, 201, 197, 193, - 190, 188, 186, 184, 182, 180, 178, 176, - 174, 172, 170, 168, 166, 164, 162, 160, - 158, 157, 156, 155, 154, 153, 152, 151, - 150, 149, 148, 147, 146, 145, 144, 143, - 143, 142, 142, 141, 141, 140, 140, 139, - 139, 138, 138, 137, 137, 136, 136, 135, - 135, 135, 134, 134, 134, 134, 133, 133, - 133, 133, 132, 132, 132, 132, 131, 131, - 131, 131, 131, 131, 130, 130, 130, 130, - 130, 130, 130, 130, 129, 129, 129, 129, - 129, 129, 129, 129, 129, 129, 129, 129, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, -}; - -static unsigned char u8_to_ulaw[] = { - 0, 0, 0, 0, 0, 1, 1, 1, - 1, 2, 2, 2, 2, 3, 3, 3, - 3, 4, 4, 4, 4, 5, 5, 5, - 5, 6, 6, 6, 6, 7, 7, 7, - 7, 8, 8, 8, 8, 9, 9, 9, - 9, 10, 10, 10, 10, 11, 11, 11, - 11, 12, 12, 12, 12, 13, 13, 13, - 13, 14, 14, 14, 14, 15, 15, 15, - 15, 16, 16, 17, 17, 18, 18, 19, - 19, 20, 20, 21, 21, 22, 22, 23, - 23, 24, 24, 25, 25, 26, 26, 27, - 27, 28, 28, 29, 29, 30, 30, 31, - 31, 32, 33, 34, 35, 36, 37, 38, - 39, 40, 41, 42, 43, 44, 45, 46, - 47, 49, 51, 53, 55, 57, 59, 61, - 63, 66, 70, 74, 78, 84, 92, 104, - 254, 231, 219, 211, 205, 201, 197, 193, - 190, 188, 186, 184, 182, 180, 178, 176, - 175, 174, 173, 172, 171, 170, 169, 168, - 167, 166, 165, 164, 163, 162, 161, 160, - 159, 159, 158, 158, 157, 157, 156, 156, - 155, 155, 154, 154, 153, 153, 152, 152, - 151, 151, 150, 150, 149, 149, 148, 148, - 147, 147, 146, 146, 145, 145, 144, 144, - 143, 143, 143, 143, 142, 142, 142, 142, - 141, 141, 141, 141, 140, 140, 140, 140, - 139, 139, 139, 139, 138, 138, 138, 138, - 137, 137, 137, 137, 136, 136, 136, 136, - 135, 135, 135, 135, 134, 134, 134, 134, - 133, 133, 133, 133, 132, 132, 132, 132, - 131, 131, 131, 131, 130, 130, 130, 130, - 129, 129, 129, 129, 128, 128, 128, 128, -}; - struct feedertab_entry { SLIST_ENTRY(feedertab_entry) link; pcm_feeder *feeder; @@ -149,347 +79,13 @@ feeder_register(void *p) printf("MAXFEEDERS exceeded\n"); } -/*****************************************************************************/ - -static int -feed_root(pcm_feeder *feeder, pcm_channel *ch, u_int8_t *buffer, u_int32_t count, struct uio *stream) -{ - int ret, s; - - KASSERT(count, ("feed_root: count == 0")); - count &= ~((1 << ch->align) - 1); - KASSERT(count, ("feed_root: aligned count == 0")); - - s = spltty(); - count = min(count, stream->uio_resid); - if (count) { - ret = uiomove(buffer, count, stream); - KASSERT(ret == 0, ("feed_root: uiomove failed")); - } - splx(s); - - return count; -} -static pcm_feeder feeder_root = { "root", 0, NULL, NULL, NULL, feed_root }; -SYSINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_register, &feeder_root); - -/*****************************************************************************/ - -static int -feed_8to16le(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - int i, j, k; - - k = f->source->feed(f->source, c, b, count / 2, stream); - j = k - 1; - i = j * 2 + 1; - while (i > 0 && j >= 0) { - b[i--] = b[j--]; - b[i--] = 0; - } - return k * 2; -} - -static struct pcm_feederdesc desc_8to16le[] = { - {FEEDER_FMT, AFMT_U8, AFMT_U16_LE, 0}, - {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S8, AFMT_S16_LE, 0}, - {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_8to16le = - { "8to16le", 0, desc_8to16le, NULL, NULL, feed_8to16le }; -SYSINIT(feeder_8to16le, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_8to16le); - -/*****************************************************************************/ - -static int -feed_16to8_init(pcm_feeder *f) -{ - f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); - return (f->data == NULL); -} - -static int -feed_16to8_free(pcm_feeder *f) -{ - if (f->data) free(f->data, M_DEVBUF); - f->data = NULL; - return 0; -} - -static int -feed_16leto8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - u_int32_t i = 0, toget = count * 2; - int j = 1, k; - - k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); - while (j < k) { - b[i++] = ((u_int8_t *)f->data)[j]; - j += 2; - } - return i; -} - -static struct pcm_feederdesc desc_16leto8[] = { - {FEEDER_FMT, AFMT_U16_LE, AFMT_U8, 0}, - {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_LE, AFMT_S8, 0}, - {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S8 | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_16leto8 = - { "16leto8", 1, desc_16leto8, feed_16to8_init, feed_16to8_free, feed_16leto8 }; -SYSINIT(feeder_16leto8, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_16leto8); - -/*****************************************************************************/ - -static int -feed_monotostereo8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - int i, j, k = f->source->feed(f->source, c, b, count / 2, stream); - - j = k - 1; - i = j * 2 + 1; - while (i > 0 && j >= 0) { - b[i--] = b[j]; - b[i--] = b[j]; - j--; - } - return k * 2; -} - -static struct pcm_feederdesc desc_monotostereo8[] = { - {FEEDER_FMT, AFMT_U8, AFMT_U8 | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S8, AFMT_S8 | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_monotostereo8 = - { "monotostereo8", 0, desc_monotostereo8, NULL, NULL, feed_monotostereo8 }; -SYSINIT(feeder_monotostereo8, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_monotostereo8); - -/*****************************************************************************/ - -static int -feed_monotostereo16(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - int i, j, k = f->source->feed(f->source, c, b, count / 2, stream); - u_int8_t x, y; - - j = k - 1; - i = j * 2 + 1; - while (i > 3 && j >= 1) { - x = b[j--]; - y = b[j--]; - b[i--] = x; - b[i--] = y; - b[i--] = x; - b[i--] = y; - } - return k * 2; -} - -static struct pcm_feederdesc desc_monotostereo16[] = { - {FEEDER_FMT, AFMT_U16_LE, AFMT_U16_LE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_LE, AFMT_S16_LE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_U16_BE, AFMT_U16_BE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_BE, AFMT_S16_BE | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_monotostereo16 = - { "monotostereo16", 0, desc_monotostereo16, NULL, NULL, feed_monotostereo16 }; -SYSINIT(feeder_monotostereo16, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_monotostereo16); - -/*****************************************************************************/ - -static int -feed_stereotomono8_init(pcm_feeder *f) -{ - f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); - return (f->data == NULL); -} - -static int -feed_stereotomono8_free(pcm_feeder *f) -{ - if (f->data) free(f->data, M_DEVBUF); - f->data = NULL; - return 0; -} - -static int -feed_stereotomono8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - u_int32_t i = 0, toget = count * 2; - int j = 0, k; - - k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); - while (j < k) { - b[i++] = ((u_int8_t *)f->data)[j]; - j += 2; - } - return i; -} - -static struct pcm_feederdesc desc_stereotomono8[] = { - {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_U8, 0}, - {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_S8, 0}, - {0}, -}; -static pcm_feeder feeder_stereotomono8 = - { "stereotomono8", 1, desc_stereotomono8, feed_stereotomono8_init, feed_stereotomono8_free, feed_stereotomono8 }; -SYSINIT(feeder_stereotomono8, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_stereotomono8); - -/*****************************************************************************/ - -static int -feed_stereotomono16_init(pcm_feeder *f) -{ - f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); - return (f->data == NULL); -} - -static int -feed_stereotomono16_free(pcm_feeder *f) -{ - if (f->data) free(f->data, M_DEVBUF); - f->data = NULL; - return 0; -} - -static int -feed_stereotomono16(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - u_int32_t i = 0, toget = count * 2; - int j = 0, k; - - k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); - while (j < k) { - b[i++] = ((u_int8_t *)f->data)[j]; - b[i++] = ((u_int8_t *)f->data)[j + 1]; - j += 4; - } - return i; -} - -static struct pcm_feederdesc desc_stereotomono16[] = { - {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U16_LE, 0}, - {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_LE, 0}, - {FEEDER_FMT, AFMT_U16_BE | AFMT_STEREO, AFMT_U16_BE, 0}, - {FEEDER_FMT, AFMT_S16_BE | AFMT_STEREO, AFMT_S16_BE, 0}, - {0}, -}; -static pcm_feeder feeder_stereotomono16 = - { "stereotomono16", 1, desc_stereotomono16, feed_stereotomono16_init, feed_stereotomono16_free, feed_stereotomono16 }; -SYSINIT(feeder_stereotomono16, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_stereotomono16); - -/*****************************************************************************/ - -static int -feed_endian(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - u_int8_t t; - int i = 0, j = f->source->feed(f->source, c, b, count, stream); - - while (i < j) { - t = b[i]; - b[i] = b[i + 1]; - b[i + 1] = t; - i += 2; - } - return i; -} - -static struct pcm_feederdesc desc_endian[] = { - {FEEDER_FMT, AFMT_U16_LE, AFMT_U16_BE, 0}, - {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U16_BE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_LE, AFMT_S16_BE, 0}, - {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_BE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_U16_BE, AFMT_U16_LE, 0}, - {FEEDER_FMT, AFMT_U16_BE | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_BE, AFMT_S16_LE, 0}, - {FEEDER_FMT, AFMT_S16_BE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_endian = { "endian", -1, desc_endian, NULL, NULL, feed_endian }; -SYSINIT(feeder_endian, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_endian); - -/*****************************************************************************/ - -static int -feed_sign(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - int i = 0, j = f->source->feed(f->source, c, b, count, stream); - int ssz = (int)f->data, ofs = ssz - 1; - - while (i < j) { - b[i + ofs] ^= 0x80; - i += ssz; - } - return i; -} - -static struct pcm_feederdesc desc_sign8[] = { - {FEEDER_FMT, AFMT_U8, AFMT_S8, 0}, - {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_S8 | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S8, AFMT_U8, 0}, - {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_sign8 = - { "sign8", 0, desc_sign8, NULL, NULL, feed_sign, (void *)1 }; -SYSINIT(feeder_sign8, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_sign8); - -static struct pcm_feederdesc desc_sign16le[] = { - {FEEDER_FMT, AFMT_U16_LE, AFMT_S16_LE, 0}, - {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, - {FEEDER_FMT, AFMT_S16_LE, AFMT_U16_LE, 0}, - {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_sign16le = - { "sign16le", -1, desc_sign16le, NULL, NULL, feed_sign, (void *)2 }; -SYSINIT(feeder_sign16le, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_sign16le); - -/*****************************************************************************/ - -static int -feed_table(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) -{ - int i = 0, j = f->source->feed(f->source, c, b, count, stream); - - while (i < j) { - b[i] = ((u_int8_t *)f->data)[b[i]]; - i++; - } - return i; -} - -static struct pcm_feederdesc desc_ulawtou8[] = { - {FEEDER_FMT, AFMT_MU_LAW, AFMT_U8, 0}, - {FEEDER_FMT, AFMT_MU_LAW | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_ulawtou8 = - { "ulawtou8", 0, desc_ulawtou8, NULL, NULL, feed_table, ulaw_to_u8 }; -SYSINIT(feeder_ulawtou8, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_ulawtou8); - -static struct pcm_feederdesc desc_u8toulaw[] = { - {FEEDER_FMT, AFMT_U8, AFMT_MU_LAW, 0}, - {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_MU_LAW | AFMT_STEREO, 0}, - {0}, -}; -static pcm_feeder feeder_u8toulaw = - { "u8toulaw", 0, desc_u8toulaw, NULL, NULL, feed_table, u8_to_ulaw }; -SYSINIT(feeder_u8toulaw, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder_u8toulaw); - -/*****************************************************************************/ - static int cmpdesc(struct pcm_feederdesc *n, struct pcm_feederdesc *m) { - return ((n->type == m->type) && (n->in == m->in) && (n->out == m->out) && (n->flags == m->flags)); + return ((n->type == m->type) && + ((n->in == 0) || (n->in == m->in)) && + ((n->out == 0) || (n->out == m->out)) && + (n->flags == m->flags)); } pcm_feeder * @@ -516,6 +112,39 @@ feeder_getroot() return NULL; } +int +feeder_set(pcm_feeder *feeder, int what, int value) +{ + if (feeder->set) + return feeder->set(feeder, what, value); + else + return -1; +} + +int +chn_addfeeder(pcm_channel *c, pcm_feeder *f) +{ + pcm_feeder *nf; + struct pcm_feederdesc *nfdesc; + + nf = malloc(sizeof(*nf), M_DEVBUF, M_NOWAIT); + nfdesc = malloc(sizeof(*nfdesc), M_DEVBUF, M_NOWAIT); + *nfdesc = *(f->desc); + *nf = *f; + nf->desc = nfdesc; + nf->source = c->feeder; + if (nf->init) + nf->init(nf); + if (nf->align > 0) + c->align += nf->align; + else if (nf->align < 0 && c->align < -nf->align) + c->align = -nf->align; + + c->feeder = nf; + + return 0; +} + int chn_removefeeder(pcm_channel *c) { @@ -526,11 +155,26 @@ chn_removefeeder(pcm_channel *c) f = c->feeder->source; if (c->feeder->free) c->feeder->free(c->feeder); + free(c->feeder->desc, M_DEVBUF); free(c->feeder, M_DEVBUF); c->feeder = f; return 0; } +pcm_feeder * +chn_findfeeder(pcm_channel *c, u_int32_t type) +{ + pcm_feeder *f; + + f = c->feeder; + while (f != NULL) { + if (f->desc->type == type) + return f; + f = f->source; + } + return NULL; +} + static int chainok(pcm_feeder *test, pcm_feeder *stop) { @@ -597,7 +241,7 @@ feeder_fmtchain(u_int32_t *to, pcm_feeder *source, pcm_feeder *stop, int maxdept } u_int32_t -chn_feedchain(pcm_channel *c, u_int32_t *to) +chn_fmtchain(pcm_channel *c, u_int32_t *to) { pcm_feeder *try, *stop; int max; @@ -635,3 +279,39 @@ chn_feedchain(pcm_channel *c, u_int32_t *to) #endif return c->feeder->desc->out; } + +/*****************************************************************************/ + +static int +feed_root(pcm_feeder *feeder, pcm_channel *ch, u_int8_t *buffer, u_int32_t count, struct uio *stream) +{ + int ret, s; + + KASSERT(count, ("feed_root: count == 0")); + count &= ~((1 << ch->align) - 1); + KASSERT(count, ("feed_root: aligned count == 0 (align = %d)", ch->align)); + + s = spltty(); + count = min(count, stream->uio_resid); + if (count) { + ret = uiomove(buffer, count, stream); + KASSERT(ret == 0, ("feed_root: uiomove failed")); + } + splx(s); + + return count; +} +static pcm_feeder feeder_root = { + "root", + 0, + NULL, + NULL, + NULL, + NULL, + feed_root, +}; +SYSINIT(feeder_root, SI_SUB_DRIVERS, SI_ORDER_FIRST, feeder_register, &feeder_root); + + + + diff --git a/sys/dev/sound/pcm/feeder.h b/sys/dev/sound/pcm/feeder.h index b6890e6b2bc7..40f866c5ee06 100644 --- a/sys/dev/sound/pcm/feeder.h +++ b/sys/dev/sound/pcm/feeder.h @@ -29,8 +29,23 @@ void feeder_register(void *p); pcm_feeder *feeder_get(struct pcm_feederdesc *desc); pcm_feeder *feeder_getroot(void); +int feeder_set(pcm_feeder *feeder, int what, int value); -u_int32_t chn_feedchain(pcm_channel *c, u_int32_t *to); +u_int32_t chn_fmtchain(pcm_channel *c, u_int32_t *to); +int chn_addfeeder(pcm_channel *c, pcm_feeder *f); int chn_removefeeder(pcm_channel *c); +pcm_feeder *chn_findfeeder(pcm_channel *c, u_int32_t type); + +#define FEEDER_DECLARE(feeder) SYSINIT(feeder, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, feeder_register, &feeder) + +#define FEEDER_ROOT 1 +#define FEEDER_FMT 2 +#define FEEDER_RATE 3 +#define FEEDER_FILTER 4 +#define FEEDER_VOLUME 5 +#define FEEDER_LAST FEEDER_VOLUME + +#define FEEDRATE_SRC 1 +#define FEEDRATE_DST 2 diff --git a/sys/dev/sound/pcm/feeder_fmt.c b/sys/dev/sound/pcm/feeder_fmt.c new file mode 100644 index 000000000000..e056da625b76 --- /dev/null +++ b/sys/dev/sound/pcm/feeder_fmt.c @@ -0,0 +1,496 @@ +/* + * Copyright (c) 1999 Cameron Grant + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#include + +#define FEEDBUFSZ 8192 + +static unsigned char ulaw_to_u8[] = { + 3, 7, 11, 15, 19, 23, 27, 31, + 35, 39, 43, 47, 51, 55, 59, 63, + 66, 68, 70, 72, 74, 76, 78, 80, + 82, 84, 86, 88, 90, 92, 94, 96, + 98, 99, 100, 101, 102, 103, 104, 105, + 106, 107, 108, 109, 110, 111, 112, 113, + 113, 114, 114, 115, 115, 116, 116, 117, + 117, 118, 118, 119, 119, 120, 120, 121, + 121, 121, 122, 122, 122, 122, 123, 123, + 123, 123, 124, 124, 124, 124, 125, 125, + 125, 125, 125, 125, 126, 126, 126, 126, + 126, 126, 126, 126, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 127, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 253, 249, 245, 241, 237, 233, 229, 225, + 221, 217, 213, 209, 205, 201, 197, 193, + 190, 188, 186, 184, 182, 180, 178, 176, + 174, 172, 170, 168, 166, 164, 162, 160, + 158, 157, 156, 155, 154, 153, 152, 151, + 150, 149, 148, 147, 146, 145, 144, 143, + 143, 142, 142, 141, 141, 140, 140, 139, + 139, 138, 138, 137, 137, 136, 136, 135, + 135, 135, 134, 134, 134, 134, 133, 133, + 133, 133, 132, 132, 132, 132, 131, 131, + 131, 131, 131, 131, 130, 130, 130, 130, + 130, 130, 130, 130, 129, 129, 129, 129, + 129, 129, 129, 129, 129, 129, 129, 129, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 128, 128, 128, 128, 128, 128, +}; + +static unsigned char u8_to_ulaw[] = { + 0, 0, 0, 0, 0, 1, 1, 1, + 1, 2, 2, 2, 2, 3, 3, 3, + 3, 4, 4, 4, 4, 5, 5, 5, + 5, 6, 6, 6, 6, 7, 7, 7, + 7, 8, 8, 8, 8, 9, 9, 9, + 9, 10, 10, 10, 10, 11, 11, 11, + 11, 12, 12, 12, 12, 13, 13, 13, + 13, 14, 14, 14, 14, 15, 15, 15, + 15, 16, 16, 17, 17, 18, 18, 19, + 19, 20, 20, 21, 21, 22, 22, 23, + 23, 24, 24, 25, 25, 26, 26, 27, + 27, 28, 28, 29, 29, 30, 30, 31, + 31, 32, 33, 34, 35, 36, 37, 38, + 39, 40, 41, 42, 43, 44, 45, 46, + 47, 49, 51, 53, 55, 57, 59, 61, + 63, 66, 70, 74, 78, 84, 92, 104, + 254, 231, 219, 211, 205, 201, 197, 193, + 190, 188, 186, 184, 182, 180, 178, 176, + 175, 174, 173, 172, 171, 170, 169, 168, + 167, 166, 165, 164, 163, 162, 161, 160, + 159, 159, 158, 158, 157, 157, 156, 156, + 155, 155, 154, 154, 153, 153, 152, 152, + 151, 151, 150, 150, 149, 149, 148, 148, + 147, 147, 146, 146, 145, 145, 144, 144, + 143, 143, 143, 143, 142, 142, 142, 142, + 141, 141, 141, 141, 140, 140, 140, 140, + 139, 139, 139, 139, 138, 138, 138, 138, + 137, 137, 137, 137, 136, 136, 136, 136, + 135, 135, 135, 135, 134, 134, 134, 134, + 133, 133, 133, 133, 132, 132, 132, 132, + 131, 131, 131, 131, 130, 130, 130, 130, + 129, 129, 129, 129, 128, 128, 128, 128, +}; + +/*****************************************************************************/ + +static int +feed_8to16le(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + int i, j, k; + + k = f->source->feed(f->source, c, b, count / 2, stream); + j = k - 1; + i = j * 2 + 1; + while (i > 0 && j >= 0) { + b[i--] = b[j--]; + b[i--] = 0; + } + return k * 2; +} + +static struct pcm_feederdesc desc_8to16le[] = { + {FEEDER_FMT, AFMT_U8, AFMT_U16_LE, 0}, + {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S8, AFMT_S16_LE, 0}, + {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_8to16le = { + "8to16le", + 0, + desc_8to16le, + NULL, + NULL, + NULL, + feed_8to16le, +}; +FEEDER_DECLARE(feeder_8to16le); + +/*****************************************************************************/ + +static int +feed_16to8_init(pcm_feeder *f) +{ + f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); + return (f->data == NULL); +} + +static int +feed_16to8_free(pcm_feeder *f) +{ + if (f->data) free(f->data, M_DEVBUF); + f->data = NULL; + return 0; +} + +static int +feed_16leto8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + u_int32_t i = 0, toget = count * 2; + int j = 1, k; + + k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); + while (j < k) { + b[i++] = ((u_int8_t *)f->data)[j]; + j += 2; + } + return i; +} + +static struct pcm_feederdesc desc_16leto8[] = { + {FEEDER_FMT, AFMT_U16_LE, AFMT_U8, 0}, + {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_LE, AFMT_S8, 0}, + {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S8 | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_16leto8 = { + "16leto8", + 1, + desc_16leto8, + feed_16to8_init, + feed_16to8_free, + NULL, + feed_16leto8, +}; +FEEDER_DECLARE(feeder_16leto8); + +/*****************************************************************************/ + +static int +feed_monotostereo8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + int i, j, k = f->source->feed(f->source, c, b, count / 2, stream); + + j = k - 1; + i = j * 2 + 1; + while (i > 0 && j >= 0) { + b[i--] = b[j]; + b[i--] = b[j]; + j--; + } + return k * 2; +} + +static struct pcm_feederdesc desc_monotostereo8[] = { + {FEEDER_FMT, AFMT_U8, AFMT_U8 | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S8, AFMT_S8 | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_monotostereo8 = { + "monotostereo8", + 0, + desc_monotostereo8, + NULL, + NULL, + NULL, + feed_monotostereo8, +}; +FEEDER_DECLARE(feeder_monotostereo8); + +/*****************************************************************************/ + +static int +feed_monotostereo16(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + int i, j, k = f->source->feed(f->source, c, b, count / 2, stream); + u_int8_t x, y; + + j = k - 1; + i = j * 2 + 1; + while (i > 3 && j >= 1) { + x = b[j--]; + y = b[j--]; + b[i--] = x; + b[i--] = y; + b[i--] = x; + b[i--] = y; + } + return k * 2; +} + +static struct pcm_feederdesc desc_monotostereo16[] = { + {FEEDER_FMT, AFMT_U16_LE, AFMT_U16_LE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_LE, AFMT_S16_LE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_U16_BE, AFMT_U16_BE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_BE, AFMT_S16_BE | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_monotostereo16 = { + "monotostereo16", + 0, + desc_monotostereo16, + NULL, + NULL, + NULL, + feed_monotostereo16, +}; +FEEDER_DECLARE(feeder_monotostereo16); + +/*****************************************************************************/ + +static int +feed_stereotomono8_init(pcm_feeder *f) +{ + f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); + return (f->data == NULL); +} + +static int +feed_stereotomono8_free(pcm_feeder *f) +{ + if (f->data) free(f->data, M_DEVBUF); + f->data = NULL; + return 0; +} + +static int +feed_stereotomono8(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + u_int32_t i = 0, toget = count * 2; + int j = 0, k; + + k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); + while (j < k) { + b[i++] = ((u_int8_t *)f->data)[j]; + j += 2; + } + return i; +} + +static struct pcm_feederdesc desc_stereotomono8[] = { + {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_U8, 0}, + {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_S8, 0}, + {0}, +}; +static pcm_feeder feeder_stereotomono8 = { + "stereotomono8", + 1, + desc_stereotomono8, + feed_stereotomono8_init, + feed_stereotomono8_free, + NULL, + feed_stereotomono8, +}; +FEEDER_DECLARE(feeder_stereotomono8); + +/*****************************************************************************/ + +static int +feed_stereotomono16_init(pcm_feeder *f) +{ + f->data = malloc(FEEDBUFSZ, M_DEVBUF, M_NOWAIT); + return (f->data == NULL); +} + +static int +feed_stereotomono16_free(pcm_feeder *f) +{ + if (f->data) free(f->data, M_DEVBUF); + f->data = NULL; + return 0; +} + +static int +feed_stereotomono16(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + u_int32_t i = 0, toget = count * 2; + int j = 0, k; + + k = f->source->feed(f->source, c, f->data, min(toget, FEEDBUFSZ), stream); + while (j < k) { + b[i++] = ((u_int8_t *)f->data)[j]; + b[i++] = ((u_int8_t *)f->data)[j + 1]; + j += 4; + } + return i; +} + +static struct pcm_feederdesc desc_stereotomono16[] = { + {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U16_LE, 0}, + {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_LE, 0}, + {FEEDER_FMT, AFMT_U16_BE | AFMT_STEREO, AFMT_U16_BE, 0}, + {FEEDER_FMT, AFMT_S16_BE | AFMT_STEREO, AFMT_S16_BE, 0}, + {0}, +}; +static pcm_feeder feeder_stereotomono16 = { + "stereotomono16", + 1, + desc_stereotomono16, + feed_stereotomono16_init, + feed_stereotomono16_free, + NULL, + feed_stereotomono16, +}; +FEEDER_DECLARE(feeder_stereotomono16); + +/*****************************************************************************/ + +static int +feed_endian(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + u_int8_t t; + int i = 0, j = f->source->feed(f->source, c, b, count, stream); + + while (i < j) { + t = b[i]; + b[i] = b[i + 1]; + b[i + 1] = t; + i += 2; + } + return i; +} + +static struct pcm_feederdesc desc_endian[] = { + {FEEDER_FMT, AFMT_U16_LE, AFMT_U16_BE, 0}, + {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_U16_BE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_LE, AFMT_S16_BE, 0}, + {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_S16_BE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_U16_BE, AFMT_U16_LE, 0}, + {FEEDER_FMT, AFMT_U16_BE | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_BE, AFMT_S16_LE, 0}, + {FEEDER_FMT, AFMT_S16_BE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_endian = { + "endian", + -1, + desc_endian, + NULL, + NULL, + NULL, + feed_endian, +}; +FEEDER_DECLARE(feeder_endian); + +/*****************************************************************************/ + +static int +feed_sign(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + int i = 0, j = f->source->feed(f->source, c, b, count, stream); + int ssz = (int)f->data, ofs = ssz - 1; + + while (i < j) { + b[i + ofs] ^= 0x80; + i += ssz; + } + return i; +} + +static struct pcm_feederdesc desc_sign8[] = { + {FEEDER_FMT, AFMT_U8, AFMT_S8, 0}, + {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_S8 | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S8, AFMT_U8, 0}, + {FEEDER_FMT, AFMT_S8 | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_sign8 = { + "sign8", + 0, + desc_sign8, + NULL, + NULL, + NULL, + feed_sign, + (void *)1, +}; +FEEDER_DECLARE(feeder_sign8); + +static struct pcm_feederdesc desc_sign16le[] = { + {FEEDER_FMT, AFMT_U16_LE, AFMT_S16_LE, 0}, + {FEEDER_FMT, AFMT_U16_LE | AFMT_STEREO, AFMT_S16_LE | AFMT_STEREO, 0}, + {FEEDER_FMT, AFMT_S16_LE, AFMT_U16_LE, 0}, + {FEEDER_FMT, AFMT_S16_LE | AFMT_STEREO, AFMT_U16_LE | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_sign16le = { + "sign16le", + -1, + desc_sign16le, + NULL, + NULL, + NULL, + feed_sign, + (void *)2, +}; +FEEDER_DECLARE(feeder_sign16le); + +/*****************************************************************************/ + +static int +feed_table(pcm_feeder *f, pcm_channel *c, u_int8_t *b, u_int32_t count, struct uio *stream) +{ + int i = 0, j = f->source->feed(f->source, c, b, count, stream); + + while (i < j) { + b[i] = ((u_int8_t *)f->data)[b[i]]; + i++; + } + return i; +} + +static struct pcm_feederdesc desc_ulawtou8[] = { + {FEEDER_FMT, AFMT_MU_LAW, AFMT_U8, 0}, + {FEEDER_FMT, AFMT_MU_LAW | AFMT_STEREO, AFMT_U8 | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_ulawtou8 = { + "ulawtou8", + 0, + desc_ulawtou8, + NULL, + NULL, + NULL, + feed_table, + ulaw_to_u8, +}; +FEEDER_DECLARE(feeder_ulawtou8); + +static struct pcm_feederdesc desc_u8toulaw[] = { + {FEEDER_FMT, AFMT_U8, AFMT_MU_LAW, 0}, + {FEEDER_FMT, AFMT_U8 | AFMT_STEREO, AFMT_MU_LAW | AFMT_STEREO, 0}, + {0}, +}; +static pcm_feeder feeder_u8toulaw = { + "u8toulaw", + 0, + desc_u8toulaw, + NULL, + NULL, + NULL, + feed_table, + u8_to_ulaw, +}; +FEEDER_DECLARE(feeder_u8toulaw); + +