xref: /freebsd/sys/dev/sound/pcm/channel_if.m (revision f856af0466c076beef4ea9b15d088e1119a945b8)
1#-
2# KOBJ
3#
4# Copyright (c) 2000 Cameron Grant <cg@freebsd.org>
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11#    notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright
13#    notice, this list of conditions and the following disclaimer in the
14#    documentation and/or other materials provided with the distribution.
15#
16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD$
29#
30
31#include <dev/sound/pcm/sound.h>
32
33INTERFACE channel;
34
35CODE {
36
37	static int
38	channel_nosetdir(kobj_t obj, void *data, int dir)
39	{
40		return 0;
41	}
42
43	static int
44	channel_noreset(kobj_t obj, void *data)
45	{
46		return 0;
47	}
48
49	static int
50	channel_noresetdone(kobj_t obj, void *data)
51	{
52		return 0;
53	}
54
55	static int
56	channel_nofree(kobj_t obj, void *data)
57	{
58		return 1;
59	}
60
61	static u_int32_t
62	channel_nogetptr(kobj_t obj, void *data)
63	{
64		return 0;
65	}
66
67	static int
68	channel_nonotify(kobj_t obj, void *data, u_int32_t changed)
69	{
70		return 0;
71	}
72
73	static int
74	channel_nogetpeaks(kobj_t obj, void *data, int *lpeak, int *rpeak)
75	{
76		return -1;
77	}
78
79	static int
80	channel_nogetrates(kobj_t obj, void *data, int **rates)
81	{
82		*rates = NULL;
83		return 0;
84	}
85
86};
87
88METHOD void* init {
89	kobj_t obj;
90	void *devinfo;
91	struct snd_dbuf *b;
92	struct pcm_channel *c;
93	int dir;
94};
95
96METHOD int free {
97	kobj_t obj;
98	void *data;
99} DEFAULT channel_nofree;
100
101METHOD int reset {
102	kobj_t obj;
103	void *data;
104} DEFAULT channel_noreset;
105
106METHOD int resetdone {
107	kobj_t obj;
108	void *data;
109} DEFAULT channel_noresetdone;
110
111METHOD int setdir {
112	kobj_t obj;
113	void *data;
114	int dir;
115} DEFAULT channel_nosetdir;
116
117METHOD u_int32_t setformat {
118	kobj_t obj;
119	void *data;
120	u_int32_t format;
121};
122
123METHOD u_int32_t setspeed {
124	kobj_t obj;
125	void *data;
126	u_int32_t speed;
127};
128
129METHOD u_int32_t setblocksize {
130	kobj_t obj;
131	void *data;
132	u_int32_t blocksize;
133};
134
135METHOD int trigger {
136	kobj_t obj;
137	void *data;
138	int go;
139};
140
141METHOD u_int32_t getptr {
142	kobj_t obj;
143	void *data;
144} DEFAULT channel_nogetptr;
145
146METHOD struct pcmchan_caps* getcaps {
147	kobj_t obj;
148	void *data;
149};
150
151METHOD int notify {
152	kobj_t obj;
153	void *data;
154	u_int32_t changed;
155} DEFAULT channel_nonotify;
156
157/**
158 * @brief Retrieve channel peak values
159 *
160 * This function is intended to obtain peak volume values for samples
161 * played/recorded on a channel.  Values are on a linear scale from 0 to
162 * 32767.  If the channel is monaural, a single value should be recorded
163 * in @c lpeak.
164 *
165 * If hardware support isn't available, the SNDCTL_DSP_GET[IO]PEAKS
166 * operation should return EINVAL.  However, we may opt to provide
167 * software support that the user may toggle via sysctl/mixext.
168 *
169 * @param obj	standard kobj object (usually @c channel->methods)
170 * @param data	driver-specific data (usually @c channel->devinfo)
171 * @param lpeak	pointer to store left peak level
172 * @param rpeak	pointer to store right peak level
173 *
174 * @retval -1	Error; usually operation isn't supported.
175 * @retval 0	success
176 */
177METHOD int getpeaks {
178	kobj_t obj;
179	void *data;
180	int *lpeak;
181	int *rpeak;
182} DEFAULT channel_nogetpeaks;
183
184/**
185 * @brief Retrieve discrete supported sample rates
186 *
187 * Some cards operate at fixed rates, and this call is intended to retrieve
188 * those rates primarily for when in-kernel rate adjustment is undesirable
189 * (e.g., application wants direct DMA access after setting a channel to run
190 * "uncooked").
191 *
192 * The parameter @c rates is a double pointer which will be reset to
193 * point to an array of supported sample rates.  The number of elements
194 * in the array is returned to the caller.
195 *
196 * @param obj	standard kobj object (usually @c channel->methods)
197 * @param data	driver-specific data (usually @c channel->devinfo)
198 * @param rates	rate array pointer
199 *
200 * @return Number of rates in the array
201 */
202METHOD int getrates {
203	kobj_t obj;
204	void *data;
205	int **rates;
206} DEFAULT channel_nogetrates;
207