Subject: Re: kern/15845: audio drivers without auconv attribute won't link
To: None <tech-kern@netbsd.org>
From: TAMURA Kent <kent@netbsd.org>
List: tech-kern
Date: 03/10/2002 01:51:14
In message "re: kern/15845: audio drivers without auconv attribute won't link"
on 02/03/10, matthew green <mrg@eterna.com.au> writes:
> i'd rather all this new code went into a new file, with a new
> device attribute. keep this away from the user, they don't
> need it....
I see.
o New files:
- dev/aurateconv.c
- dev/aurateconvreg.h (Is this suitable name?)
Move sampling rate conversion functions to aurateconv.c from
auconv.c, and move prototypes to aurateconvreg.h from auconv.h
o The following patch
(not include diffs against auconv.h and auconv.c)
--
TAMURA Kent <kent2002@hauN.org> <kent@netbsd.org>
Index: conf/files
===================================================================
RCS file: /cvsroot/syssrc/sys/conf/files,v
retrieving revision 1.499
diff -u -r1.499 files
--- conf/files 2002/03/04 13:24:11 1.499
+++ conf/files 2002/03/09 16:40:05
@@ -209,6 +209,8 @@
#
define mulaw
define auconv
+define aurateconv
+file dev/aurateconv.c aurateconv needs-flag
# audio and midi devices, attaches to audio hardware driver
#
Index: dev/audio.c
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/audio.c,v
retrieving revision 1.147
diff -u -r1.147 audio.c
--- dev/audio.c 2002/03/08 02:30:54 1.147
+++ dev/audio.c 2002/03/09 16:40:06
@@ -776,9 +776,11 @@
DPRINTF(("audio_initbufs: mode=0x%x\n", sc->sc_mode));
audio_init_ringbuffer(&sc->sc_rr);
+#if NAURATECONV > 0
auconv_init_context(&sc->sc_rconv, sc->sc_rparams.hw_sample_rate,
sc->sc_rparams.sample_rate,
sc->sc_rr.start, sc->sc_rr.end);
+#endif
sc->sc_rconvbuffer_begin = 0;
sc->sc_rconvbuffer_end = 0;
if (hw->init_input && (sc->sc_mode & AUMODE_RECORD)) {
@@ -789,9 +791,11 @@
}
audio_init_ringbuffer(&sc->sc_pr);
+#if NAURATECONV > 0
auconv_init_context(&sc->sc_pconv, sc->sc_pparams.sample_rate,
sc->sc_pparams.hw_sample_rate,
sc->sc_pr.start, sc->sc_pr.end);
+#endif
sc->sc_sil_count = 0;
if (hw->init_output && (sc->sc_mode & AUMODE_PLAY)) {
error = hw->init_output(sc->hw_hdl, sc->sc_pr.start,
@@ -1235,9 +1239,21 @@
* The format of data in the ring buffer is
* [hw_sample_rate, hw_encoding, hw_precision, hw_channels]
*/
+#if NAURATECONV > 0
sc->sc_rconvbuffer_end =
auconv_record(&sc->sc_rconv, params,
sc->sc_rconvbuffer, outp, cc);
+#else
+ n = cb->end - outp;
+ if (cc <= n) {
+ memcpy(sc->sc_rconvbuffer, outp, cc);
+ } else {
+ memcpy(sc->sc_rconvbuffer, outp, n);
+ memcpy(sc->sc_rconvbuffer + n, cb->start,
+ cc - n);
+ }
+ sc->sc_rconvbuffer_end = cc;
+#endif /* !NAURATECONV */
/*
* The format of data in sc_rconvbuffer is
* [sample_rate, hw_encoding, hw_precision, channels]
@@ -1627,8 +1643,18 @@
* The format of data in sc_pconvbuffer is:
* [sample_rate, hw_encoding, hw_precision, channels]
*/
+#if NAURATECONV > 0
cc = auconv_play(&sc->sc_pconv, params, inp,
sc->sc_pconvbuffer, cc);
+#else
+ n = cb->end - inp;
+ if (cc <= n) {
+ memcpy(inp, sc->sc_pconvbuffer, cc);
+ } else {
+ memcpy(inp, sc->sc_pconvbuffer, n);
+ memcpy(cb->start, sc->sc_pconvbuffer + n, cc - n);
+ }
+#endif /* !NAURATECONV */
/*
* The format of data in inp is:
* [hw_sample_rate, hw_encoding, hw_precision, hw_channels]
@@ -2563,6 +2589,18 @@
}
return aumask;
}
+
+#if NAURATECONV <= 0
+/* dummy function for the case that auconv.o is not linked */
+int
+auconv_check_params(const struct audio_params *params)
+{
+ if (params->hw_channels == params->channels
+ && params->hw_sample_rate == params->sample_rate)
+ return 0; /* No conversion */
+ return (EINVAL);
+}
+#endif /* !NAURATECONV */
int
audiosetinfo(struct audio_softc *sc, struct audio_info *ai)
Index: dev/audiovar.h
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/audiovar.h,v
retrieving revision 1.21
diff -u -r1.21 audiovar.h
--- dev/audiovar.h 2002/03/07 14:37:02 1.21
+++ dev/audiovar.h 2002/03/09 16:40:06
@@ -35,7 +35,7 @@
* From: Header: audiovar.h,v 1.3 93/07/18 14:07:25 mccanne Exp (LBL)
*/
-#include "auconv.h" /* for AUDIO_MAX_CHANNELS */
+#include "aurateconvreg.h" /* for AUDIO_MAX_CHANNELS */
/*
* Initial/default block duration is both configurable and patchable.
@@ -119,13 +119,17 @@
u_char sc_input_fragment[MAX_SAMPLE_SIZE];
int sc_pconvbuffer_size;
u_char *sc_pconvbuffer;
+#if NAURATECONV > 0
struct auconv_context sc_pconv;
+#endif
int sc_rconvbuffer_size;
int sc_rconvbuffer_begin;
int sc_rconvbuffer_end;
u_char *sc_rconvbuffer;
+#if NAURATECONV > 0
struct auconv_context sc_rconv;
+#endif
u_char sc_blkset; /* Blocksize has been set */
Index: dev/pci/files.pci
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/pci/files.pci,v
retrieving revision 1.162
diff -u -r1.162 files.pci
--- dev/pci/files.pci 2002/02/02 18:37:46 1.162
+++ dev/pci/files.pci 2002/03/09 16:40:06
@@ -280,7 +280,7 @@
file dev/pci/eap.c eap
# Intel ICH AC'97 audio
-device auich: audio, auconv, mulaw, ac97
+device auich: audio, auconv, mulaw, ac97, aurateconv
attach auich at pci
file dev/pci/auich.c auich
Index: dev/usb/files.usb
===================================================================
RCS file: /cvsroot/syssrc/sys/dev/usb/files.usb,v
retrieving revision 1.40
diff -u -r1.40 files.usb
--- dev/usb/files.usb 2002/01/07 17:44:45 1.40
+++ dev/usb/files.usb 2002/03/09 16:40:06
@@ -31,7 +31,7 @@
file dev/usb/ezload.c ezload
# Audio devices
-device uaudio: audio, auconv, mulaw
+device uaudio: audio, auconv, mulaw, aurateconv
attach uaudio at uhub
file dev/usb/uaudio.c uaudio