Tue Jul 28 21:24:43 2015 UTC ()
Reduce latency a bit. From nat@


(skrll)
diff -r1.9 -r1.10 src/sys/arch/arm/broadcom/bcm2835_vcaudio.c

cvs diff -r1.9 -r1.10 src/sys/arch/arm/broadcom/bcm2835_vcaudio.c (expand / switch to unified diff)

--- src/sys/arch/arm/broadcom/bcm2835_vcaudio.c 2015/03/15 18:31:29 1.9
+++ src/sys/arch/arm/broadcom/bcm2835_vcaudio.c 2015/07/28 21:24:43 1.10
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: bcm2835_vcaudio.c,v 1.9 2015/03/15 18:31:29 jmcneill Exp $ */ 1/* $NetBSD: bcm2835_vcaudio.c,v 1.10 2015/07/28 21:24:43 skrll Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 Jared D. McNeill <jmcneill@invisible.ca> 4 * Copyright (c) 2013 Jared D. McNeill <jmcneill@invisible.ca>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -21,27 +21,27 @@ @@ -21,27 +21,27 @@
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29/* 29/*
30 * VideoCore audio interface 30 * VideoCore audio interface
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.9 2015/03/15 18:31:29 jmcneill Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: bcm2835_vcaudio.c,v 1.10 2015/07/28 21:24:43 skrll Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/types.h> 37#include <sys/types.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/device.h> 39#include <sys/device.h>
40#include <sys/conf.h> 40#include <sys/conf.h>
41#include <sys/bus.h> 41#include <sys/bus.h>
42#include <sys/kmem.h> 42#include <sys/kmem.h>
43 43
44#include <sys/audioio.h> 44#include <sys/audioio.h>
45#include <dev/audio_if.h> 45#include <dev/audio_if.h>
46#include <dev/auconv.h> 46#include <dev/auconv.h>
47#include <dev/auvolconv.h> 47#include <dev/auvolconv.h>
@@ -71,40 +71,42 @@ enum { @@ -71,40 +71,42 @@ enum {
71 VCAUDIO_OUTPUT_AUTO_VOLUME, 71 VCAUDIO_OUTPUT_AUTO_VOLUME,
72 VCAUDIO_OUTPUT_HEADPHONE_VOLUME, 72 VCAUDIO_OUTPUT_HEADPHONE_VOLUME,
73 VCAUDIO_OUTPUT_HDMI_VOLUME, 73 VCAUDIO_OUTPUT_HDMI_VOLUME,
74 VCAUDIO_OUTPUT_SELECT, 74 VCAUDIO_OUTPUT_SELECT,
75 VCAUDIO_ENUM_LAST, 75 VCAUDIO_ENUM_LAST,
76}; 76};
77 77
78enum vcaudio_dest { 78enum vcaudio_dest {
79 VCAUDIO_DEST_AUTO = 0, 79 VCAUDIO_DEST_AUTO = 0,
80 VCAUDIO_DEST_HP = 1, 80 VCAUDIO_DEST_HP = 1,
81 VCAUDIO_DEST_HDMI = 2, 81 VCAUDIO_DEST_HDMI = 2,
82}; 82};
83 83
84 
85/* 84/*
86 * Standard message size is 4000 bytes and VCHIQ can accept 16 messages. 85 * Maximum message size is 4000 bytes and VCHIQ can accept 16 messages.
87 * 86 *
88 * 4000 bytes of 16bit 48kHz stereo is approximately 21ms. 87 * 4000 bytes of 16bit 48kHz stereo is approximately 21ms.
89 * 88 *
90 * We get complete messages at ~10ms intervals. 89 * We get complete messages at ~10ms intervals.
91 * 90 *
92 * Setting blocksize to 2 x 4000 means that we send approx 42ms of audio. We 91 * Setting blocksize to 4 x 1600 means that we send approx 33ms of audio. We
93 * prefill by two blocks before starting audio meaning we have 83ms of latency. 92 * prefill by two blocks before starting audio meaning we have 50ms of latency.
 93 *
 94 * Six messages of 1600 bytes was chosen working back from a desired latency of
 95 * 50ms.
94 */ 96 */
95 97
96#define VCAUDIO_MSGSIZE 4000 98#define VCAUDIO_MSGSIZE 1600
97#define VCAUDIO_NUMMSGS 2 99#define VCAUDIO_NUMMSGS 4
98#define VCAUDIO_BLOCKSIZE (VCAUDIO_MSGSIZE * VCAUDIO_NUMMSGS) 100#define VCAUDIO_BLOCKSIZE (VCAUDIO_MSGSIZE * VCAUDIO_NUMMSGS)
99#define VCAUDIO_BUFFERSIZE 128000 101#define VCAUDIO_BUFFERSIZE 128000
100#define VCAUDIO_PREFILLCOUNT 2 102#define VCAUDIO_PREFILLCOUNT 2
101 103
102struct vcaudio_softc { 104struct vcaudio_softc {
103 device_t sc_dev; 105 device_t sc_dev;
104 device_t sc_audiodev; 106 device_t sc_audiodev;
105 107
106 lwp_t *sc_lwp; 108 lwp_t *sc_lwp;
107 109
108 kmutex_t sc_lock; 110 kmutex_t sc_lock;
109 kmutex_t sc_intr_lock; 111 kmutex_t sc_intr_lock;
110 kcondvar_t sc_datacv; 112 kcondvar_t sc_datacv;