xref: /freebsd/sys/dev/sound/pcm/vchan.h (revision 3612ef642f511a1bd9f759da87abeafe7d6ff110)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause
3  *
4  * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
5  * Copyright (c) 2001 Cameron Grant <cg@FreeBSD.org>
6  * All rights reserved.
7  * Copyright (c) 2024-2025 The FreeBSD Foundation
8  *
9  * Portions of this software were developed by Christos Margiolis
10  * <christos@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33 
34 #ifndef _SND_VCHAN_H_
35 #define _SND_VCHAN_H_
36 
37 extern bool snd_vchans_enable;
38 
39 int vchan_create(struct pcm_channel *, struct pcm_channel **);
40 int vchan_destroy(struct pcm_channel *);
41 
42 int vchan_sync(struct pcm_channel *);
43 
44 #define VCHAN_SYNC_REQUIRED(c)						\
45 	(((c)->flags & CHN_F_VIRTUAL) && (((c)->flags & CHN_F_DIRTY) ||	\
46 	(c)->bufhard->fmt != (c)->parentchannel->format ||		\
47 	(c)->bufhard->spd != (c)->parentchannel->speed))
48 
49 void vchan_initsys(device_t);
50 
51 /*
52  * Default format / rate
53  */
54 #define VCHAN_DEFAULT_FORMAT	SND_FORMAT(AFMT_S16_LE, 2, 0)
55 #define VCHAN_DEFAULT_RATE	48000
56 
57 #define VCHAN_PLAY		0
58 #define VCHAN_REC		1
59 
60 /*
61  * Offset by +/- 1 so we can distinguish bogus pointer.
62  */
63 #define VCHAN_SYSCTL_DATA(x, y)						\
64 		((void *)((intptr_t)(((((x) + 1) & 0xfff) << 2) |	\
65 		(((VCHAN_##y) + 1) & 0x3))))
66 
67 #define VCHAN_SYSCTL_DATA_SIZE	sizeof(void *)
68 #define VCHAN_SYSCTL_UNIT(x)	((int)(((intptr_t)(x) >> 2) & 0xfff) - 1)
69 #define VCHAN_SYSCTL_DIR(x)	((int)((intptr_t)(x) & 0x3) - 1)
70 
71 #endif	/* _SND_VCHAN_H_ */
72