Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/kent-audio1]: src/sys adopt the filter pipeline framework



details:   https://anonhg.NetBSD.org/src/rev/680e9fa2a52e
branches:  kent-audio1
changeset: 571728:680e9fa2a52e
user:      kent <kent%NetBSD.org@localhost>
date:      Mon Jan 03 16:42:52 2005 +0000

description:
adopt the filter pipeline framework

diffstat:

 sys/arch/arm/iomd/files.iomd     |    4 +-
 sys/arch/arm/iomd/vidcaudio.c    |  148 ++++++++----
 sys/arch/dreamcast/dev/g2/aica.c |  137 +++---------
 sys/arch/hp700/gsc/harmony.c     |   44 ++-
 sys/arch/hpcmips/vr/vraiu.c      |   13 +-
 sys/arch/macppc/dev/awacs.c      |  177 ++++-----------
 sys/arch/macppc/dev/snapper.c    |  141 ++----------
 sys/arch/sgimips/hpc/haltwo.c    |   84 +++---
 sys/arch/x68k/dev/vs.c           |   85 +++----
 sys/arch/x68k/dev/vsvar.h        |    4 +-
 sys/dev/ic/am7930.c              |   26 +-
 sys/dev/ic/am7930var.h           |   11 +-
 sys/dev/ic/msm6258.c             |  426 ++++++++++++++++++++++++--------------
 sys/dev/ic/msm6258var.h          |   23 +-
 sys/dev/ic/tms320av110.c         |   19 +-
 sys/dev/pcmcia/esl.c             |   40 ++-
 sys/dev/sbus/cs4231_sbus.c       |   12 +-
 sys/dev/tc/bba.c                 |  123 +++++++----
 sys/dev/tc/files.tc              |    4 +-
 19 files changed, 750 insertions(+), 771 deletions(-)

diffs (truncated from 2634 to 300 lines):

diff -r 40799f90070c -r 680e9fa2a52e sys/arch/arm/iomd/files.iomd
--- a/sys/arch/arm/iomd/files.iomd      Mon Jan 03 16:42:02 2005 +0000
+++ b/sys/arch/arm/iomd/files.iomd      Mon Jan 03 16:42:52 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.iomd,v 1.13 2004/03/13 19:20:50 bjh21 Exp $
+#      $NetBSD: files.iomd,v 1.13.4.1 2005/01/03 16:42:52 kent Exp $
 #
 # IOMD-specific configuration data
 #
@@ -58,7 +58,7 @@
 file   arch/arm/iomd/vidcvideo.c               vidcvideo       needs-flag
 
 # Audio device
-device vidcaudio: audiobus, mulaw, aurateconv, audiobell
+device vidcaudio: audiobus, auconv, mulaw, aurateconv, audiobell
 attach vidcaudio at vidc
 file   arch/arm/iomd/vidcaudio.c               vidcaudio       needs-flag
 
diff -r 40799f90070c -r 680e9fa2a52e sys/arch/arm/iomd/vidcaudio.c
--- a/sys/arch/arm/iomd/vidcaudio.c     Mon Jan 03 16:42:02 2005 +0000
+++ b/sys/arch/arm/iomd/vidcaudio.c     Mon Jan 03 16:42:52 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vidcaudio.c,v 1.40 2004/10/29 12:57:16 yamt Exp $      */
+/*     $NetBSD: vidcaudio.c,v 1.40.2.1 2005/01/03 16:42:52 kent Exp $  */
 
 /*
  * Copyright (c) 1995 Melvin Tang-Richardson
@@ -65,7 +65,7 @@
 
 #include <sys/param.h> /* proc.h */
 
-__KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.40 2004/10/29 12:57:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vidcaudio.c,v 1.40.2.1 2005/01/03 16:42:52 kent Exp $");
 
 #include <sys/audioio.h>
 #include <sys/conf.h>   /* autoconfig functions */
@@ -79,6 +79,7 @@
 
 #include <dev/audio_if.h>
 #include <dev/audiobellvar.h>
+#include <dev/auconv.h>
 #include <dev/mulaw.h>
 
 #include <machine/intr.h>
@@ -140,20 +141,23 @@
 static void vidcaudio_rate(int);
 static void vidcaudio_ctrl(int);
 static void vidcaudio_stereo(int, int);
-static void mulaw_to_vidc(void *, u_char *, int);
-static void mulaw_to_vidc_stereo(void *, u_char *, int);
+static stream_filter_factory_t mulaw_to_vidc;
+static stream_filter_factory_t mulaw_to_vidc_stereo;
+static int mulaw_to_vidc_fetch_to(stream_fetcher_t *, audio_stream_t *, int);
+static int mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *,
+    audio_stream_t *, int);
 
 CFATTACH_DECL(vidcaudio, sizeof(struct vidcaudio_softc),
     vidcaudio_probe, vidcaudio_attach, NULL, NULL);
 
 static int    vidcaudio_query_encoding(void *, struct audio_encoding *);
-static int    vidcaudio_set_params(void *, int, int, struct audio_params *,
-    struct audio_params *);
+static int    vidcaudio_set_params(void *, int, int, audio_params_t *,
+    audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
 static int    vidcaudio_round_blocksize(void *, int);
 static int    vidcaudio_trigger_output(void *, void *, void *, int,
-    void (*)(void *), void *, struct audio_params *);
+    void (*)(void *), void *, const audio_params_t *);
 static int    vidcaudio_trigger_input(void *, void *, void *, int,
-    void (*)(void *), void *, struct audio_params *);
+    void (*)(void *), void *, const audio_params_t *);
 static int    vidcaudio_halt_output(void *);
 static int    vidcaudio_halt_input(void *);
 static int    vidcaudio_getdev(void *, struct audio_device *);
@@ -331,34 +335,88 @@
 
 #define MULAW_TO_VIDC(m) (~((m) << 1 | (m) >> 7))
 
-static void
-mulaw_to_vidc(void *v, u_char *p, int cc)
+static stream_filter_t *
+mulaw_to_vidc(struct audio_softc *sc, const audio_params_t *from,
+             const audio_params_t *to)
 {
+       return auconv_nocontext_filter_factory(mulaw_to_vidc_fetch_to);
+}
+
+static int
+mulaw_to_vidc_fetch_to(stream_fetcher_t *self, audio_stream_t *dst, int max_used)
+{
+       stream_filter_t *this;
+       uint8_t *d;
+       const uint8_t *s;
+       int m, err;
+       int used_dst, used_src;
 
-       while (--cc >= 0) {
-               *p = MULAW_TO_VIDC(*p);
-               ++p;
+       this = (stream_filter_t *)self;
+       if ((err = this->prev->fetch_to(this->prev, this->src, max_used)))
+               return err;
+       m = dst->end - dst->start;
+       m = min(m, max_used);
+       d = dst->inp;
+       s = this->src->outp;
+       used_dst = audio_stream_get_used(dst);
+       used_src = audio_stream_get_used(this->src);
+       while (used_dst < m && used_src > 0) {
+               *d = MULAW_TO_VIDC(*s);
+               d = audio_stream_add_inp(dst, d, 1);
+               s = audio_stream_add_outp(this->src, s, 1);
+               used_dst++;
+               used_src--;
        }
+       dst->inp = d;
+       this->src->outp = s;
+       return 0;
 }
 
-static void
-mulaw_to_vidc_stereo(void *v, u_char *p, int cc)
+static stream_filter_t *
+mulaw_to_vidc_stereo(struct audio_softc *sc, const audio_params_t *from,
+                    const audio_params_t *to)
 {
-       u_char *q = p;
+       return auconv_nocontext_filter_factory(mulaw_to_vidc_stereo_fetch_to);
+}
+
+static int
+mulaw_to_vidc_stereo_fetch_to(stream_fetcher_t *self, audio_stream_t *dst,
+                             int max_used)
+{
+       stream_filter_t *this;
+       uint8_t *d;
+       const uint8_t *s;
+       int m, err;
+       int used_dst, used_src;
 
-       p += cc;
-       q += cc * 2;
-       while (--cc >= 0) {
-               q -= 2;
-               --p;
-               q[0] = q[1] = MULAW_TO_VIDC(*p);
+       this = (stream_filter_t *)self;
+       max_used = (max_used + 1) & ~1;
+       if ((err = this->prev->fetch_to(this->prev, this->src, max_used / 2)))
+               return err;
+       m = (dst->end - dst->start) & ~1;
+       m = min(m, max_used);
+       d = dst->inp;
+       s = this->src->outp;
+       used_dst = audio_stream_get_used(dst);
+       used_src = audio_stream_get_used(this->src);
+       while (used_dst < m && used_src > 0) {
+               d[0] = d[1] = MULAW_TO_VIDC(*s);
+               d = audio_stream_add_inp(dst, d, 2);
+               s = audio_stream_add_outp(this->src, s, 1);
+               used_dst += 2;
+               used_src--;
        }
+       dst->inp = d;
+       this->src->outp = s;
+       return 0;
 }
 
 static int
 vidcaudio_set_params(void *addr, int setmode, int usemode,
-    struct audio_params *p, struct audio_params *r)
+    audio_params_t *p, audio_params_t *r,
+    stream_filter_list_t *pfil, stream_filter_list_t *rfil)
 {
+       audio_params_t hw;
        struct vidcaudio_softc *sc = addr;
        int sample_period, ch;
 
@@ -367,20 +425,21 @@
 
        if (sc->sc_is16bit) {
                /* ARM7500ish, 16-bit, two-channel */
+               hw = *p;
                if (p->encoding == AUDIO_ENCODING_ULAW && p->precision == 8) {
-                       p->sw_code = mulaw_to_slinear16_le;
-                       p->factor = 2; p->factor_denom = 1;
+                       hw.encoding = AUDIO_ENCODING_SLINEAR_LE;
+                       hw.precision = hw.validbits = 16;
+                       pfil->append(pfil, mulaw_to_linear16, &hw);
                } else if (p->encoding != AUDIO_ENCODING_SLINEAR_LE ||
                    p->precision != 16)
                        return EINVAL;
-               p->hw_channels = 2;
                sample_period = 705600 / 4 / p->sample_rate;
                if (sample_period < 3) sample_period = 3;
-               p->hw_sample_rate = 705600 / 4 / sample_period;
                vidcaudio_rate(sample_period - 2);
                vidcaudio_ctrl(SCR_SERIAL);
-               p->hw_encoding = AUDIO_ENCODING_SLINEAR_LE;
-               p->hw_precision = 16;
+               hw.sample_rate = 705600 / 4 / sample_period;
+               hw.channels = 2;
+               pfil->append(pfil, aurateconv, &hw);
        } else {
                /* VIDC20ish, u-law, 8-channel */
                if (p->encoding != AUDIO_ENCODING_ULAW || p->precision != 8)
@@ -392,31 +451,20 @@
                 * ulaw, so we do the channel duplication ourselves,
                 * and don't try to do rate conversion.
                 */
-               switch (p->channels) {
-               case 1:
-                       p->sw_code = mulaw_to_vidc_stereo;
-                       p->factor = 2; p->factor_denom = 1;
-                       break;
-               case 2:
-                       p->sw_code = mulaw_to_vidc;
-                       p->factor = 1; p->factor_denom = 1;
-                       break;
-               default:
-                       return EINVAL;
-               }
-               p->hw_channels = p->channels;
                sample_period = 1000000 / 2 / p->sample_rate;
                if (sample_period < 3) sample_period = 3;
-               p->hw_sample_rate = p->sample_rate =
-                   1000000 / 2 / sample_period;
-               p->hw_encoding = AUDIO_ENCODING_NONE;
-               p->hw_precision = 8;
+               p->sample_rate = 1000000 / 2 / sample_period;
+               hw = *p;
+               hw.encoding = AUDIO_ENCODING_NONE;
+               hw.precision = 8;
                vidcaudio_rate(sample_period - 2);
                vidcaudio_ctrl(SCR_SDAC | SCR_CLKSEL);
-               if (p->hw_channels == 1)
+               if (p->channels == 1) {
+                       pfil->append(pfil, mulaw_to_vidc_stereo, &hw);
                        for (ch = 0; ch < 8; ch++)
                                vidcaudio_stereo(ch, SIR_CENTRE);
-               else {
+               } else {
+                       pfil->append(pfil, mulaw_to_vidc, &hw);
                        for (ch = 0; ch < 8; ch += 2)
                                vidcaudio_stereo(ch, SIR_LEFT_100);
                        for (ch = 1; ch < 8; ch += 2)
@@ -445,7 +493,7 @@
 
 static int
 vidcaudio_trigger_output(void *addr, void *start, void *end, int blksize,
-    void (*intr)(void *), void *arg, struct audio_params *params)
+    void (*intr)(void *), void *arg, const audio_params_t *params)
 {
        struct vidcaudio_softc *sc = addr;
        size_t npages, i;
@@ -487,7 +535,7 @@
 
 static int
 vidcaudio_trigger_input(void *addr, void *start, void *end, int blksize,
-    void (*intr)(void *), void *arg, struct audio_params *params)
+    void (*intr)(void *), void *arg, const audio_params_t *params)
 {
 
        return ENODEV;
diff -r 40799f90070c -r 680e9fa2a52e sys/arch/dreamcast/dev/g2/aica.c
--- a/sys/arch/dreamcast/dev/g2/aica.c  Mon Jan 03 16:42:02 2005 +0000
+++ b/sys/arch/dreamcast/dev/g2/aica.c  Mon Jan 03 16:42:52 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: aica.c,v 1.5 2004/10/29 12:57:16 yamt Exp $    */
+/*     $NetBSD: aica.c,v 1.5.2.1 2005/01/03 16:43:32 kent Exp $        */
 
 /*
  * Copyright (c) 2003 SHIMIZU Ryo <ryo%misakimix.org@localhost>
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.5 2004/10/29 12:57:16 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.5.2.1 2005/01/03 16:43:32 kent Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -82,10 +82,10 @@
        int                     sc_nextfill;
 };
 
-struct {
+const struct {
        char    *name;
-       int     encoding;
-       int     precision;
+       int     encoding;
+       int     precision;
 } aica_encodings[] = {
        {AudioEadpcm,           AUDIO_ENCODING_ADPCM,           4},
        {AudioEslinear,         AUDIO_ENCODING_SLINEAR,         8},
@@ -98,6 +98,20 @@
        {AudioEulinear_le,      AUDIO_ENCODING_ULINEAR_LE,      16},
 };
 



Home | Main Index | Thread Index | Old Index