Module Name:    src
Committed By:   isaki
Date:           Sun Apr 21 14:00:19 UTC 2019

Modified Files:
        src/sys/arch/x68k/dev [isaki-audio2]: vs.c vsvar.h
        src/sys/dev/ic [isaki-audio2]: msm6258.c msm6258var.h

Log Message:
Adapt to audio2.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.50.2.1 src/sys/arch/x68k/dev/vs.c
cvs rdiff -u -r1.16 -r1.16.6.1 src/sys/arch/x68k/dev/vsvar.h
cvs rdiff -u -r1.25 -r1.25.2.1 src/sys/dev/ic/msm6258.c
cvs rdiff -u -r1.10 -r1.10.8.1 src/sys/dev/ic/msm6258var.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x68k/dev/vs.c
diff -u src/sys/arch/x68k/dev/vs.c:1.50 src/sys/arch/x68k/dev/vs.c:1.50.2.1
--- src/sys/arch/x68k/dev/vs.c:1.50	Sat Mar 16 12:09:57 2019
+++ src/sys/arch/x68k/dev/vs.c	Sun Apr 21 14:00:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vs.c,v 1.50 2019/03/16 12:09:57 isaki Exp $	*/
+/*	$NetBSD: vs.c,v 1.50.2.1 2019/04/21 14:00:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.50 2019/03/16 12:09:57 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.50.2.1 2019/04/21 14:00:19 isaki Exp $");
 
 #include "audio.h"
 #include "vs.h"
@@ -43,7 +43,6 @@ __KERNEL_RCSID(0, "$NetBSD: vs.c,v 1.50 
 
 #include <sys/audioio.h>
 #include <dev/audio_if.h>
-#include <dev/mulaw.h>
 
 #include <machine/bus.h>
 #include <machine/cpu.h>
@@ -75,11 +74,11 @@ static int  vs_dmaerrintr(void *);
 /* MI audio layer interface */
 static int  vs_open(void *, int);
 static void vs_close(void *);
-static int  vs_query_encoding(void *, struct audio_encoding *);
-static int  vs_set_params(void *, int, int, audio_params_t *,
-	audio_params_t *, stream_filter_list_t *, stream_filter_list_t *);
-static int  vs_init_output(void *, void *, int);
-static int  vs_init_input(void *, void *, int);
+static int  vs_query_format(void *, audio_format_query_t *);
+static int  vs_set_format(void *, int,
+	const audio_params_t *, const audio_params_t *,
+	audio_filter_reg_t *, audio_filter_reg_t *);
+static int  vs_commit_settings(void *);
 static int  vs_start_input(void *, void *, int, void (*)(void *), void *);
 static int  vs_start_output(void *, void *, int, void (*)(void *), void *);
 static int  vs_halt_output(void *);
@@ -99,8 +98,7 @@ static void vs_get_locks(void *, kmutex_
 
 /* lower functions */
 static int vs_round_sr(u_long);
-static void vs_set_sr(struct vs_softc *, int);
-static inline void vs_set_po(struct vs_softc *, u_long);
+static inline void vs_set_panout(struct vs_softc *, u_long);
 
 extern struct cfdriver vs_cd;
 
@@ -112,10 +110,9 @@ static int vs_attached;
 static const struct audio_hw_if vs_hw_if = {
 	.open			= vs_open,
 	.close			= vs_close,
-	.query_encoding		= vs_query_encoding,
-	.set_params		= vs_set_params,
-	.init_output		= vs_init_output,
-	.init_input		= vs_init_input,
+	.query_format		= vs_query_format,
+	.set_format		= vs_set_format,
+	.commit_settings	= vs_commit_settings,
 	.start_output		= vs_start_output,
 	.start_input		= vs_start_input,
 	.halt_output		= vs_halt_output,
@@ -137,6 +134,18 @@ static struct audio_device vs_device = {
 	"vs"
 };
 
+static const struct audio_format vs_formats = {
+	.mode		= AUMODE_PLAY | AUMODE_RECORD,
+	.encoding	= AUDIO_ENCODING_ADPCM,
+	.validbits	= 4,
+	.precision	= 4,
+	.channels	= 1,
+	.channel_mask	= AUFMT_MONAURAL,
+	.frequency_type	= 5,
+	.frequency	= { VS_RATE_3K, VS_RATE_5K, VS_RATE_7K,
+	                    VS_RATE_10K, VS_RATE_15K },
+};
+
 struct {
 	u_long rate;
 	u_char clk;
@@ -213,7 +222,7 @@ vs_attach(device_t parent, device_t self
 	sc->sc_prev_vd = NULL;
 	sc->sc_active = 0;
 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
-	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
+	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
 
 	/* XXX */
 	bus_space_map(iot, PPI_ADDR, PPI_MAPSIZE, BUS_SPACE_MAP_SHIFTED,
@@ -298,172 +307,87 @@ vs_close(void *hdl)
 }
 
 static int
-vs_query_encoding(void *hdl, struct audio_encoding *fp)
+vs_query_format(void *hdl, audio_format_query_t *afp)
 {
 
-	DPRINTF(1, ("vs_query_encoding\n"));
-
-	if (fp->index == 0) {
-		strcpy(fp->name, AudioEslinear);
-		fp->encoding = AUDIO_ENCODING_SLINEAR;
-		fp->precision = 8;
-		fp->flags = 0;
-		return 0;
-	}
-	if (fp->index == 1) {
-		strcpy(fp->name, AudioEslinear_be);
-		fp->encoding = AUDIO_ENCODING_SLINEAR_BE;
-		fp->precision = 16;
-		fp->flags = 0;
-		return 0;
-	}
-	return EINVAL;
+	return audio_query_format(&vs_formats, 1, afp);
 }
 
 static int
 vs_round_sr(u_long rate)
 {
 	int i;
-	int diff;
-	int nearest;
 
-	diff = rate;
-	nearest = 0;
 	for (i = 0; i < NUM_RATE; i++) {
-		if (rate >= vs_l2r[i].rate) {
-			if (rate - vs_l2r[i].rate < diff) {
-				diff = rate - vs_l2r[i].rate;
-				nearest = i;
-			}
-		} else {
-			if (vs_l2r[i].rate - rate < diff) {
-				diff = vs_l2r[i].rate - rate;
-				nearest = i;
-			}
-		}
+		if (rate == vs_l2r[i].rate)
+			return i;
 	}
-	if (diff * 100 / rate > 15)
-		return -1;
-	else
-		return nearest;
+	return -1;
 }
 
 static int
-vs_set_params(void *hdl, int setmode, int usemode,
-	audio_params_t *play, audio_params_t *rec,
-	stream_filter_list_t *pfil, stream_filter_list_t *rfil)
+vs_set_format(void *hdl, int setmode,
+	const audio_params_t *play, const audio_params_t *rec,
+	audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
 {
 	struct vs_softc *sc;
-	audio_params_t hw;
-	stream_filter_factory_t *pconv;
-	stream_filter_factory_t *rconv;
 	int rate;
 
 	sc = hdl;
 
-	DPRINTF(1, ("vs_set_params: mode=%d enc=%d rate=%d prec=%d ch=%d: ",
-		setmode, play->encoding, play->sample_rate,
-		play->precision, play->channels));
+	DPRINTF(1, ("%s: mode=%d %s/%dbit/%dch/%dHz: ", __func__,
+	    setmode, audio_encoding_name(play->encoding),
+	    play->precision, play->channels, play->sample_rate));
 
 	/* *play and *rec are identical because !AUDIO_PROP_INDEPENDENT */
 
-	if (play->channels != 1) {
-		DPRINTF(1, ("channels not matched\n"));
-		return EINVAL;
-	}
-
 	rate = vs_round_sr(play->sample_rate);
-	if (rate < 0) {
-		DPRINTF(1, ("rate not matched\n"));
-		return EINVAL;
-	}
-
-	if (play->precision == 8 && play->encoding == AUDIO_ENCODING_SLINEAR) {
-		pconv = msm6258_linear8_to_adpcm;
-		rconv = msm6258_adpcm_to_linear8;
-	} else if (play->precision == 16 &&
-	           play->encoding == AUDIO_ENCODING_SLINEAR_BE) {
-		pconv = msm6258_slinear16_to_adpcm;
-		rconv = msm6258_adpcm_to_slinear16;
-	} else {
-		DPRINTF(1, ("prec/enc not matched\n"));
-		return EINVAL;
-	}
-
+	KASSERT(rate >= 0);
 	sc->sc_current.rate = rate;
 
-	/* pfil and rfil are independent even if !AUDIO_PROP_INDEPENDENT */
-
 	if ((setmode & AUMODE_PLAY) != 0) {
-		hw = *play;
-		hw.encoding = AUDIO_ENCODING_ADPCM;
-		hw.precision = 4;
-		hw.validbits = 4;
-		pfil->prepend(pfil, pconv, &hw);
+		pfil->codec = msm6258_internal_to_adpcm;
+		pfil->context = &sc->sc_codecvar;
 	}
 	if ((setmode & AUMODE_RECORD) != 0) {
-		hw = *rec;
-		hw.encoding = AUDIO_ENCODING_ADPCM;
-		hw.precision = 4;
-		hw.validbits = 4;
-		rfil->prepend(rfil, rconv, &hw);
+		rfil->codec = msm6258_adpcm_to_internal;
+		rfil->context = &sc->sc_codecvar;
 	}
 
 	DPRINTF(1, ("accepted\n"));
 	return 0;
 }
 
-static void
-vs_set_sr(struct vs_softc *sc, int rate)
+static int
+vs_commit_settings(void *hdl)
 {
+	struct vs_softc *sc;
+	int rate;
+
+	sc = hdl;
+	rate = sc->sc_current.rate;
 
-	DPRINTF(1, ("setting sample rate to %d, %d\n",
+	DPRINTF(1, ("commit_settings: sample rate to %d, %d\n",
 		 rate, (int)vs_l2r[rate].rate));
 	bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
 			  (bus_space_read_1 (sc->sc_iot, sc->sc_ppi,
 					     PPI_PORTC) & 0xf0)
 			  | vs_l2r[rate].den);
 	adpcm_chgclk(vs_l2r[rate].clk);
+
+	return 0;
 }
 
 static inline void
-vs_set_po(struct vs_softc *sc, u_long po)
+vs_set_panout(struct vs_softc *sc, u_long po)
 {
+
 	bus_space_write_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC,
 			  (bus_space_read_1(sc->sc_iot, sc->sc_ppi, PPI_PORTC)
 			   & 0xfc) | po);
 }
 
 static int
-vs_init_output(void *hdl, void *buffer, int size)
-{
-	struct vs_softc *sc;
-
-	DPRINTF(1, ("%s\n", __func__));
-	sc = hdl;
-
-	/* Set rate and pan */
-	vs_set_sr(sc, sc->sc_current.rate);
-	vs_set_po(sc, VS_PANOUT_LR);
-
-	return 0;
-}
-
-static int
-vs_init_input(void *hdl, void *buffer, int size)
-{
-	struct vs_softc *sc;
-
-	DPRINTF(1, ("%s\n", __func__));
-	sc = hdl;
-
-	/* Set rate */
-	vs_set_sr(sc, sc->sc_current.rate);
-
-	return 0;
-}
-
-static int
 vs_start_output(void *hdl, void *block, int blksize, void (*intr)(void *),
 	void *arg)
 {
@@ -501,6 +425,7 @@ vs_start_output(void *hdl, void *block, 
 	    (int)block - (int)KVADDR(vd), blksize);
 
 	if (sc->sc_active == 0) {
+		vs_set_panout(sc, VS_PANOUT_LR);
 		bus_space_write_1(sc->sc_iot, sc->sc_ioh,
 			MSM6258_CMD, MSM6258_CMD_PLAY_START);
 		sc->sc_active = 1;
@@ -734,30 +659,6 @@ vs_round_buffersize(void *hdl, int direc
 	return bufsize;
 }
 
-#if 0
-paddr_t
-vs_mappage(void *addr, void *mem, off_t off, int prot)
-{
-	struct vs_softc *sc;
-	struct vs_dma *p;
-
-	if (off < 0)
-		return -1;
-	sc = addr;
-	for (p = sc->sc_dmas; p != NULL && KVADDR(p) != mem;
-	     p = p->vd_next)
-		continue;
-	if (p == NULL) {
-		printf("%s: mappage: bad addr %p\n",
-		    device_xname(sc->sc_dev), start);
-		return -1;
-	}
-
-	return bus_dmamem_mmap(sc->sc_dmat, p->vd_segs, p->vd_nsegs,
-			       off, prot, BUS_DMA_WAITOK);
-}
-#endif
-
 static int
 vs_get_props(void *hdl)
 {

Index: src/sys/arch/x68k/dev/vsvar.h
diff -u src/sys/arch/x68k/dev/vsvar.h:1.16 src/sys/arch/x68k/dev/vsvar.h:1.16.6.1
--- src/sys/arch/x68k/dev/vsvar.h:1.16	Sat Sep 30 04:07:04 2017
+++ src/sys/arch/x68k/dev/vsvar.h	Sun Apr 21 14:00:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: vsvar.h,v 1.16 2017/09/30 04:07:04 isaki Exp $	*/
+/*	$NetBSD: vsvar.h,v 1.16.6.1 2019/04/21 14:00:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -106,4 +106,6 @@ struct vs_softc {
 	void (*sc_rintr)(void *);
 	void *sc_parg;
 	void *sc_rarg;
+
+	struct msm6258_codecvar sc_codecvar;
 };

Index: src/sys/dev/ic/msm6258.c
diff -u src/sys/dev/ic/msm6258.c:1.25 src/sys/dev/ic/msm6258.c:1.25.2.1
--- src/sys/dev/ic/msm6258.c:1.25	Mon Sep  3 16:29:31 2018
+++ src/sys/dev/ic/msm6258.c	Sun Apr 21 14:00:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msm6258.c,v 1.25 2018/09/03 16:29:31 riastradh Exp $	*/
+/*	$NetBSD: msm6258.c,v 1.25.2.1 2019/04/21 14:00:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: msm6258.c,v 1.25 2018/09/03 16:29:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: msm6258.c,v 1.25.2.1 2019/04/21 14:00:19 isaki Exp $");
 
 #include <sys/systm.h>
 #include <sys/device.h>
@@ -39,21 +39,9 @@ __KERNEL_RCSID(0, "$NetBSD: msm6258.c,v 
 #include <sys/audioio.h>
 
 #include <dev/audio_if.h>
-#include <dev/auconv.h>
 #include <dev/audiovar.h>
-#include <dev/mulaw.h>
 #include <dev/ic/msm6258var.h>
 
-struct msm6258_codecvar {
-	stream_filter_t	base;
-	short		mc_amp;
-	char		mc_estim;
-};
-
-static stream_filter_t *msm6258_factory
-	(struct audio_softc *,
-	 int (*)(struct audio_softc *, stream_fetcher_t *, audio_stream_t *, int));
-static void msm6258_dtor(struct stream_filter *);
 static inline uint8_t	pcm2adpcm_step(struct msm6258_codecvar *, int16_t);
 static inline int16_t	adpcm2pcm_step(struct msm6258_codecvar *, uint8_t);
 
@@ -75,29 +63,6 @@ static const int adpcm_estimstep[16] = {
 	-1, -1, -1, -1, 2, 4, 6, 8
 };
 
-static int16_t buzzer;	/* sound for debug */
-
-static stream_filter_t *
-msm6258_factory(struct audio_softc *asc,
-    int (*fetch_to)(struct audio_softc *, stream_fetcher_t *, audio_stream_t *, int))
-{
-	struct msm6258_codecvar *this;
-
-	this = kmem_alloc(sizeof(struct msm6258_codecvar), KM_SLEEP);
-	this->base.base.fetch_to = fetch_to;
-	this->base.dtor = msm6258_dtor;
-	this->base.set_fetcher = stream_filter_set_fetcher;
-	this->base.set_inputbuffer = stream_filter_set_inputbuffer;
-	return &this->base;
-}
-
-static void
-msm6258_dtor(struct stream_filter *this)
-{
-	if (this != NULL)
-		kmem_free(this, sizeof(struct msm6258_codecvar));
-}
-
 /*
  * signed 16bit linear PCM -> OkiADPCM
  */
@@ -134,140 +99,38 @@ pcm2adpcm_step(struct msm6258_codecvar *
 	return s;
 }
 
-#define DEFINE_FILTER(name)	\
-static int \
-name##_fetch_to(struct audio_softc *, stream_fetcher_t *, audio_stream_t *, int); \
-stream_filter_t * \
-name(struct audio_softc *sc, const audio_params_t *from, \
-     const audio_params_t *to) \
-{ \
-	return msm6258_factory(sc, name##_fetch_to); \
-} \
-static int \
-name##_fetch_to(struct audio_softc *asc, stream_fetcher_t *self, audio_stream_t *dst, int max_used)
-
-DEFINE_FILTER(msm6258_slinear16_to_adpcm)
+void
+msm6258_internal_to_adpcm(audio_filter_arg_t *arg)
 {
-	stream_filter_t *this;
 	struct msm6258_codecvar *mc;
-	uint8_t *d;
-	const uint8_t *s;
-	int m, err, enc_src;
-
-	this = (stream_filter_t *)self;
-	mc = (struct msm6258_codecvar *)self;
-	if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used * 4)))
-		return err;
-	m = dst->end - dst->start;
-	m = uimin(m, max_used);
-	d = dst->inp;
-	s = this->src->outp;
-	enc_src = this->src->param.encoding;
-	if (enc_src == AUDIO_ENCODING_SLINEAR_LE) {
-		while (dst->used < m && this->src->used >= 4) {
-			uint8_t f;
-			int16_t ss;
-			ss = le16toh(*(const int16_t*)s);
-			f  = pcm2adpcm_step(mc, ss);
-			s = audio_stream_add_outp(this->src, s, 2);
-			ss = le16toh(*(const int16_t*)s);
-			f |= pcm2adpcm_step(mc, ss) << 4;
-			s = audio_stream_add_outp(this->src, s, 2);
-			*d = f;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else if (enc_src == AUDIO_ENCODING_SLINEAR_BE) {
-		while (dst->used < m && this->src->used >= 4) {
-			uint8_t f;
-			int16_t ss;
-			ss = be16toh(*(const int16_t*)s);
-			s = audio_stream_add_outp(this->src, s, 2);
-			f  = pcm2adpcm_step(mc, ss);
-			ss = be16toh(*(const int16_t*)s);
-			s = audio_stream_add_outp(this->src, s, 2);
-			f |= pcm2adpcm_step(mc, ss) << 4;
-			*d = f;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else {
-#if defined(DIAGNOSTIC)
-		panic("msm6258_slinear16_to_adpcm: unsupported enc_src(%d)", enc_src);
-#endif
-		/* dummy run */
-		while (dst->used < m && this->src->used >= 4) {
-			s = audio_stream_add_outp(this->src, s, 2);
-			s = audio_stream_add_outp(this->src, s, 2);
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	}
-	dst->inp = d;
-	this->src->outp = s;
-	return 0;
-}
+	const aint_t *src;
+	uint8_t *dst;
+	u_int sample_count;
+	u_int i;
+
+	KASSERT((arg->count & 1) == 0);
+
+	mc = arg->context;
+	src = arg->src;
+	dst = arg->dst;
+	sample_count = arg->count * arg->srcfmt->channels;
+	for (i = 0; i < sample_count / 2; i++) {
+		aint_t s;
+		uint8_t f;
+
+		s = *src++;
+		s >>= AUDIO_INTERNAL_BITS - 16;
+		f = pcm2adpcm_step(mc, s);
+
+		s = *src++;
+		s >>= AUDIO_INTERNAL_BITS - 16;
+		f |= pcm2adpcm_step(mc, s) << 4;
 
-DEFINE_FILTER(msm6258_linear8_to_adpcm)
-{
-	stream_filter_t *this;
-	struct msm6258_codecvar *mc;
-	uint8_t *d;
-	const uint8_t *s;
-	int m, err, enc_src;
-
-	this = (stream_filter_t *)self;
-	mc = (struct msm6258_codecvar *)self;
-	if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used * 2)))
-		return err;
-	m = dst->end - dst->start;
-	m = uimin(m, max_used);
-	d = dst->inp;
-	s = this->src->outp;
-	enc_src = this->src->param.encoding;
-	if (enc_src == AUDIO_ENCODING_SLINEAR_LE
-	 || enc_src == AUDIO_ENCODING_SLINEAR_BE) {
-		while (dst->used < m && this->src->used >= 4) {
-			uint8_t f;
-			int16_t ss;
-			ss = ((int16_t)s[0]) * 256;
-			s = audio_stream_add_outp(this->src, s, 1);
-			f  = pcm2adpcm_step(mc, ss);
-			ss = ((int16_t)s[0]) * 256;
-			s = audio_stream_add_outp(this->src, s, 1);
-			f |= pcm2adpcm_step(mc, ss) << 4;
-			*d = f;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else if (enc_src == AUDIO_ENCODING_ULINEAR_LE
-	        || enc_src == AUDIO_ENCODING_ULINEAR_BE) {
-		while (dst->used < m && this->src->used >= 4) {
-			uint8_t f;
-			int16_t ss;
-			ss = ((int16_t)(s[0] ^ 0x80)) * 256;
-			s = audio_stream_add_outp(this->src, s, 1);
-			f  = pcm2adpcm_step(mc, ss);
-			ss = ((int16_t)(s[0] ^ 0x80)) * 256;
-			s = audio_stream_add_outp(this->src, s, 1);
-			f |= pcm2adpcm_step(mc, ss) << 4;
-			*d = f;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else {
-#if defined(DIAGNOSTIC)
-		panic("msm6258_linear8_to_adpcm: unsupported enc_src(%d)", enc_src);
-#endif
-		/* dummy run */
-		while (dst->used < m && this->src->used >= 4) {
-			s = audio_stream_add_outp(this->src, s, 1);
-			s = audio_stream_add_outp(this->src, s, 1);
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
+		*dst++ = (uint8_t)f;
 	}
-	dst->inp = d;
-	this->src->outp = s;
-	return 0;
 }
 
+
 /*
  * OkiADPCM -> signed 16bit linear PCM
  */
@@ -289,126 +152,31 @@ adpcm2pcm_step(struct msm6258_codecvar *
 	return mc->mc_amp;
 }
 
-DEFINE_FILTER(msm6258_adpcm_to_slinear16)
-{
-	stream_filter_t *this;
-	struct msm6258_codecvar *mc;
-	uint8_t *d;
-	const uint8_t *s;
-	int m, err, enc_dst;
-
-	this = (stream_filter_t *)self;
-	mc = (struct msm6258_codecvar *)self;
-	max_used = (max_used + 3) & ~3; /* round up multiple of 4 */
-	if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used / 4)))
-		return err;
-	m = (dst->end - dst->start) & ~3;
-	m = uimin(m, max_used);
-	d = dst->inp;
-	s = this->src->outp;
-	enc_dst = dst->param.encoding;
-	if (enc_dst == AUDIO_ENCODING_SLINEAR_LE) {
-		while (dst->used < m && this->src->used >= 1) {
-			uint8_t a;
-			int16_t s1, s2;
-			a = s[0];
-			s1 = adpcm2pcm_step(mc, a & 0x0f);
-			s2 = adpcm2pcm_step(mc, a >> 4);
-			*(int16_t*)d = htole16(s1);
-			d = audio_stream_add_inp(dst, d, 2);
-			*(int16_t*)d = htole16(s2);
-			d = audio_stream_add_inp(dst, d, 2);
-			s = audio_stream_add_outp(this->src, s, 1);
-		}
-	} else if (enc_dst == AUDIO_ENCODING_SLINEAR_BE) {
-		while (dst->used < m && this->src->used >= 1) {
-			uint8_t a;
-			int16_t s1, s2;
-			a = s[0];
-			s1 = adpcm2pcm_step(mc, a & 0x0f);
-			s2 = adpcm2pcm_step(mc, a >> 4);
-			*(int16_t*)d = htobe16(s1);
-			d = audio_stream_add_inp(dst, d, 2);
-			*(int16_t*)d = htobe16(s2);
-			d = audio_stream_add_inp(dst, d, 2);
-			s = audio_stream_add_outp(this->src, s, 1);
-		}
-	} else {
-#if defined(DIAGNOSTIC)
-		panic("msm6258_adpcm_to_slinear16: unsupported enc_dst(%d)", enc_dst);
-#endif
-		/* dummy run */
-		while (dst->used < m && this->src->used >= 1) {
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 2);
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 2);
-			s = audio_stream_add_outp(this->src, s, 1);
-		}
-	}
-	dst->inp = d;
-	this->src->outp = s;
-	return 0;
-}
-
-DEFINE_FILTER(msm6258_adpcm_to_linear8)
+void
+msm6258_adpcm_to_internal(audio_filter_arg_t *arg)
 {
-	stream_filter_t *this;
 	struct msm6258_codecvar *mc;
-	uint8_t *d;
-	const uint8_t *s;
-	int m, err, enc_dst;
-
-	this = (stream_filter_t *)self;
-	mc = (struct msm6258_codecvar *)self;
-	max_used = (max_used + 1) & ~1; /* round up multiple of 4 */
-	if ((err = this->prev->fetch_to(asc, this->prev, this->src, max_used / 2)))
-		return err;
-	m = (dst->end - dst->start) & ~1;
-	m = uimin(m, max_used);
-	d = dst->inp;
-	s = this->src->outp;
-	enc_dst = dst->param.encoding;
-	if (enc_dst == AUDIO_ENCODING_SLINEAR_LE) {
-		while (dst->used < m && this->src->used >= 1) {
-			uint8_t a;
-			int16_t s1, s2;
-			a = s[0];
-			s = audio_stream_add_outp(this->src, s, 1);
-			s1 = adpcm2pcm_step(mc, a & 0x0f);
-			s2 = adpcm2pcm_step(mc, a >> 4);
-			d[0] = s1 / 256;
-			d = audio_stream_add_inp(dst, d, 1);
-			d[0] = s2 / 256;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else if (enc_dst == AUDIO_ENCODING_ULINEAR_LE) {
-		while (dst->used < m && this->src->used >= 1) {
-			uint8_t a;
-			int16_t s1, s2;
-			a = s[0];
-			s = audio_stream_add_outp(this->src, s, 1);
-			s1 = adpcm2pcm_step(mc, a & 0x0f);
-			s2 = adpcm2pcm_step(mc, a >> 4);
-			d[0] = (s1 / 256) ^ 0x80;
-			d = audio_stream_add_inp(dst, d, 1);
-			d[0] = (s2 / 256) ^ 0x80;
-			d = audio_stream_add_inp(dst, d, 1);
-		}
-	} else {
-#if defined(DIAGNOSTIC)
-		panic("msm6258_adpcm_to_linear8: unsupported enc_dst(%d)", enc_dst);
-#endif
-		/* dummy run */
-		while (dst->used < m && this->src->used >= 1) {
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 1);
-			*d = buzzer++;
-			d = audio_stream_add_inp(dst, d, 1);
-			s = audio_stream_add_outp(this->src, s, 1);
-		}
+	const uint8_t *src;
+	aint_t *dst;
+	u_int sample_count;
+	u_int i;
+
+	KASSERT((arg->count & 1) == 0);
+
+	mc = arg->context;
+	src = arg->src;
+	dst = arg->dst;
+	sample_count = arg->count * arg->srcfmt->channels;
+	for (i = 0; i < sample_count / 2; i++) {
+		uint8_t a = *src++;
+		aint_t s;
+
+		s = adpcm2pcm_step(mc, a & 0x0f);
+		s <<= AUDIO_INTERNAL_BITS - 16;
+		*dst++ = s;
+
+		s = adpcm2pcm_step(mc, a >> 4);
+		s <<= AUDIO_INTERNAL_BITS - 16;
+		*dst++ = s;
 	}
-	dst->inp = d;
-	this->src->outp = s;
-	return 0;
 }

Index: src/sys/dev/ic/msm6258var.h
diff -u src/sys/dev/ic/msm6258var.h:1.10 src/sys/dev/ic/msm6258var.h:1.10.8.1
--- src/sys/dev/ic/msm6258var.h:1.10	Sat Sep  2 12:57:35 2017
+++ src/sys/dev/ic/msm6258var.h	Sun Apr 21 14:00:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: msm6258var.h,v 1.10 2017/09/02 12:57:35 isaki Exp $	*/
+/*	$NetBSD: msm6258var.h,v 1.10.8.1 2019/04/21 14:00:19 isaki Exp $	*/
 
 /*
  * Copyright (c) 2001 Tetsuya Isaki. All rights reserved.
@@ -28,7 +28,13 @@
 /*
  * OKI MSM6258 ADPCM voice synthesizer codec.
  */
-extern stream_filter_factory_t msm6258_slinear16_to_adpcm;
-extern stream_filter_factory_t msm6258_linear8_to_adpcm;
-extern stream_filter_factory_t msm6258_adpcm_to_slinear16;
-extern stream_filter_factory_t msm6258_adpcm_to_linear8;
+
+struct msm6258_codecvar {
+	int16_t		mc_amp;
+	int8_t		mc_estim;
+
+	aint_t pending_sample;	/* hold one pending sample. */
+};
+
+extern void msm6258_adpcm_to_internal(audio_filter_arg_t *);
+extern void msm6258_internal_to_adpcm(audio_filter_arg_t *);

Reply via email to