xref: /haiku/src/add-ons/kernel/drivers/audio/echo/multi.cpp (revision d3ff06683af390a4c2e83b69177e0a2eb76679bc)
1 /*
2  * EchoGals/Echo24 BeOS Driver for Echo audio cards
3  *
4  * Copyright (c) 2003, Jerome Duval (jerome.duval@free.fr)
5  *
6  * Original code : BeOS Driver for Intel ICH AC'97 Link interface
7  * Copyright (c) 2002, Marcus Overhagen <marcus@overhagen.de>
8  *
9  * All rights reserved.
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
13  * - Redistributions of source code must retain the above copyright notice,
14  *   this list of conditions and the following disclaimer.
15  * - Redistributions in binary form must reproduce the above copyright notice,
16  *   this list of conditions and the following disclaimer in the documentation
17  *   and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
25  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  */
31 
32 #include <driver_settings.h>
33 #include <OS.h>
34 #include <MediaDefs.h>
35 #include "debug.h"
36 #include "hmulti_audio.h"
37 #include "multi.h"
38 
39 //#define DEBUG 1
40 
41 #include "echo.h"
42 #include "util.h"
43 
44 typedef enum {
45 	B_MIX_GAIN = 1 << 0,
46 	B_MIX_MUTE = 1 << 1,
47 	B_MIX_NOMINAL = 1 << 2
48 } mixer_type;
49 
50 typedef struct {
51 	uint8	channels;
52 	uint8	bitsPerSample;
53 	uint32	sample_rate;
54 	uint32	buffer_frames;
55 	int32	buffer_count;
56 } echo_settings;
57 
58 echo_settings current_settings = {
59 	2,	// channels
60 	16,	// bits per sample
61 	48000,	// sample rate
62 	512,	// buffer frames
63 	2	// buffer count
64 };
65 
66 
67 static void
68 echo_channel_get_mix(void *card, MIXER_AUDIO_CHANNEL channel, int32 type, float *values) {
69 	echo_dev *dev = (echo_dev*) card;
70 	MIXER_MULTI_FUNCTION multi_function[2];
71 	PMIXER_FUNCTION function = multi_function[0].MixerFunction;
72 	INT32 size = ComputeMixerMultiFunctionSize(2);
73 	function[0].Channel = channel;
74 	function[1].Channel = channel;
75 	function[1].Channel.wChannel++;
76 	switch (type) {
77 		case B_MIX_GAIN:
78 			function[0].iFunction = function[1].iFunction = MXF_GET_LEVEL;
79 			break;
80 		case B_MIX_MUTE:
81 			function[0].iFunction = function[1].iFunction = MXF_GET_MUTE;
82 			break;
83 		case B_MIX_NOMINAL:
84 			function[0].iFunction = function[1].iFunction = MXF_GET_NOMINAL;
85 			break;
86 	}
87 
88 	multi_function[0].iCount = 2;
89 	dev->pEG->ProcessMixerMultiFunction(multi_function, size);
90 
91 	if (function[0].RtnStatus == ECHOSTATUS_OK) {
92 		if (type == B_MIX_GAIN) {
93 			values[0] = (float)function[0].Data.iLevel / 256;
94 			values[1] = (float)function[1].Data.iLevel / 256;
95 		} else if (type == B_MIX_MUTE) {
96 			values[0] = function[0].Data.bMuteOn ? 1.0 : 0.0;
97 		} else {
98 			values[0] = function[0].Data.iNominal == 4 ? 1.0 : 0.0;
99 		}
100 		PRINT(("echo_channel_get_mix iLevel: %ld, %d, %ld\n", function[0].Data.iLevel,
101 			channel.wChannel, channel.dwType));
102 	}
103 
104 }
105 
106 
107 static void
108 echo_channel_set_mix(void *card, MIXER_AUDIO_CHANNEL channel, int32 type, float *values) {
109 	echo_dev *dev = (echo_dev*) card;
110 	MIXER_MULTI_FUNCTION multi_function[2];
111 	PMIXER_FUNCTION function = multi_function[0].MixerFunction;
112 	INT32 size = ComputeMixerMultiFunctionSize(2);
113 	function[0].Channel = channel;
114 	function[1].Channel = channel;
115 	function[1].Channel.wChannel++;
116 	if (type == B_MIX_GAIN) {
117 		function[0].Data.iLevel = (int)(values[0] * 256);
118 		function[0].iFunction = MXF_SET_LEVEL;
119 		function[1].Data.iLevel = (int)(values[1] * 256);
120 		function[1].iFunction = MXF_SET_LEVEL;
121 	} else if (type == B_MIX_MUTE) {
122 		function[0].Data.bMuteOn = values[0] == 1.0;
123 		function[0].iFunction = MXF_SET_MUTE;
124 		function[1].Data.bMuteOn = values[0] == 1.0;
125 		function[1].iFunction = MXF_SET_MUTE;
126 	} else {
127 		function[0].Data.iNominal = values[0] == 1.0 ? 4 : -10;
128 		function[0].iFunction = MXF_SET_NOMINAL;
129 		function[1].Data.iNominal = values[0] == 1.0 ? 4 : -10;
130 		function[1].iFunction = MXF_SET_NOMINAL;
131 	}
132 
133 	multi_function[0].iCount = 2;
134 	dev->pEG->ProcessMixerMultiFunction(multi_function, size);
135 
136 	if (function[0].RtnStatus == ECHOSTATUS_OK) {
137 		PRINT(("echo_channel_set_mix OK: %ld, %d, %ld\n", function[0].Data.iLevel,
138 			channel.wChannel, channel.dwType));
139 	}
140 
141 }
142 
143 
144 static int32
145 echo_create_group_control(multi_dev *multi, uint32 *index, int32 parent,
146 	enum strind_id string, const char* name) {
147 	uint32 i = *index;
148 	(*index)++;
149 	multi->controls[i].mix_control.id = MULTI_CONTROL_FIRSTID + i;
150 	multi->controls[i].mix_control.parent = parent;
151 	multi->controls[i].mix_control.flags = B_MULTI_MIX_GROUP;
152 	multi->controls[i].mix_control.master = MULTI_CONTROL_MASTERID;
153 	multi->controls[i].mix_control.string = string;
154 	if (name)
155 		strcpy(multi->controls[i].mix_control.name, name);
156 
157 	return multi->controls[i].mix_control.id;
158 }
159 
160 static void
161 echo_create_channel_control(multi_dev *multi, uint32 *index, int32 parent, int32 string,
162 	MIXER_AUDIO_CHANNEL channel, bool nominal) {
163 	uint32 i = *index, id;
164 	multi_mixer_control control;
165 
166 	control.mix_control.master = MULTI_CONTROL_MASTERID;
167 	control.mix_control.parent = parent;
168 	control.channel = channel;
169 	control.get = &echo_channel_get_mix;
170 	control.set = &echo_channel_set_mix;
171 	control.mix_control.gain.min_gain = -128;
172 	control.mix_control.gain.max_gain = 6;
173 	control.mix_control.gain.granularity = 0.5;
174 
175 	control.mix_control.id = MULTI_CONTROL_FIRSTID + i;
176 	control.mix_control.flags = B_MULTI_MIX_ENABLE;
177 	control.mix_control.string = S_MUTE;
178 	control.type = B_MIX_MUTE;
179 	multi->controls[i] = control;
180 	i++;
181 
182 	control.mix_control.id = MULTI_CONTROL_FIRSTID + i;
183 	control.mix_control.flags = B_MULTI_MIX_GAIN;
184 	control.mix_control.string = S_null;
185 	control.type = B_MIX_GAIN;
186 	strcpy(control.mix_control.name, "Gain");
187 	multi->controls[i] = control;
188 	id = control.mix_control.id;
189 	i++;
190 
191 	// second channel
192 	control.mix_control.id = MULTI_CONTROL_FIRSTID + i;
193 	control.mix_control.master = id;
194 	multi->controls[i] = control;
195 	i++;
196 
197 	// nominal level (+4/-10)
198 	if (nominal) {
199 		control.mix_control.id = MULTI_CONTROL_FIRSTID + i;
200 		control.mix_control.master = MULTI_CONTROL_MASTERID;
201 		control.mix_control.flags = B_MULTI_MIX_ENABLE;
202 		control.mix_control.string = S_null;
203 		control.type = B_MIX_NOMINAL;
204 		strcpy(control.mix_control.name, "+4dB");
205 		multi->controls[i] = control;
206 		i++;
207 	}
208 
209 	*index = i;
210 }
211 
212 
213 static status_t
214 echo_create_controls_list(multi_dev *multi)
215 {
216 	uint32 	i = 0, index = 0, parent, parent2;
217 	echo_dev *card = (echo_dev*)multi->card;
218 
219 	parent = echo_create_group_control(multi, &index, 0, S_OUTPUT, NULL);
220 
221 	MIXER_AUDIO_CHANNEL channel;
222 	channel.wCardId = 0;
223 	channel.dwType = ECHO_BUS_OUT;
224 	for (i = 0; i < card->caps.wNumBussesOut / 2; i++) {
225 		channel.wChannel = i * 2;
226 		parent2 = echo_create_group_control(multi, &index, parent, S_null, "Output");
227 
228 		echo_create_channel_control(multi, &index, parent2, 0, channel,
229 			card->caps.dwBusOutCaps[i * 2] & ECHOCAPS_NOMINAL_LEVEL);
230 	}
231 
232 	parent = echo_create_group_control(multi, &index, 0, S_INPUT, NULL);
233 
234 	channel.dwType = ECHO_BUS_IN;
235 	for (i = 0; i < card->caps.wNumBussesIn / 2; i++) {
236 		channel.wChannel = i * 2;
237 
238 		parent2 = echo_create_group_control(multi, &index, parent, S_null, "Input");
239 
240 		echo_create_channel_control(multi, &index, parent2, 0, channel,
241 			card->caps.dwBusInCaps[i * 2] & ECHOCAPS_NOMINAL_LEVEL);
242 	}
243 
244 	multi->control_count = index;
245 	PRINT(("multi->control_count %lu\n", multi->control_count));
246 	return B_OK;
247 }
248 
249 
250 static status_t
251 echo_get_mix(echo_dev *card, multi_mix_value_info * mmvi)
252 {
253 	int32 i;
254 	uint32 id;
255 	multi_mixer_control *control = NULL;
256 	for (i = 0; i < mmvi->item_count; i++) {
257 		id = mmvi->values[i].id - MULTI_CONTROL_FIRSTID;
258 		if (id < 0 || id >= card->multi.control_count) {
259 			PRINT(("echo_get_mix : invalid control id requested : %li\n", id));
260 			continue;
261 		}
262 		control = &card->multi.controls[id];
263 
264 		if (control->mix_control.flags & B_MULTI_MIX_GAIN) {
265 			if (control->get) {
266 				float values[2];
267 				control->get(card, control->channel, control->type, values);
268 				if (control->mix_control.master == MULTI_CONTROL_MASTERID)
269 					mmvi->values[i].gain = values[0];
270 				else
271 					mmvi->values[i].gain = values[1];
272 			}
273 		}
274 
275 		if (control->mix_control.flags & B_MULTI_MIX_ENABLE && control->get) {
276 			float values[1];
277 			control->get(card, control->channel, control->type, values);
278 			mmvi->values[i].enable = (values[0] == 1.0);
279 		}
280 
281 		if (control->mix_control.flags & B_MULTI_MIX_MUX && control->get) {
282 			float values[1];
283 			control->get(card, control->channel, control->type, values);
284 			mmvi->values[i].mux = (int32)values[0];
285 		}
286 	}
287 	return B_OK;
288 }
289 
290 
291 static status_t
292 echo_set_mix(echo_dev *card, multi_mix_value_info * mmvi)
293 {
294 	int32 i;
295 	uint32 id;
296 	multi_mixer_control *control = NULL;
297 	for (i = 0; i < mmvi->item_count; i++) {
298 		id = mmvi->values[i].id - MULTI_CONTROL_FIRSTID;
299 		if (id < 0 || id >= card->multi.control_count) {
300 			PRINT(("echo_set_mix : invalid control id requested : %li\n", id));
301 			continue;
302 		}
303 		control = &card->multi.controls[id];
304 
305 		if (control->mix_control.flags & B_MULTI_MIX_GAIN) {
306 			multi_mixer_control *control2 = NULL;
307 			if (i + 1 < mmvi->item_count) {
308 				id = mmvi->values[i + 1].id - MULTI_CONTROL_FIRSTID;
309 				if (id < 0 || id >= card->multi.control_count) {
310 					PRINT(("echo_set_mix : invalid control id requested : %li\n", id));
311 				} else {
312 					control2 = &card->multi.controls[id];
313 					if (control2->mix_control.master != control->mix_control.id)
314 						control2 = NULL;
315 				}
316 			}
317 
318 			if (control->set) {
319 				float values[2];
320 				values[0] = 0.0;
321 				values[1] = 0.0;
322 
323 				if (control->mix_control.master == MULTI_CONTROL_MASTERID)
324 					values[0] = mmvi->values[i].gain;
325 				else
326 					values[1] = mmvi->values[i].gain;
327 
328 				if (control2 && control2->mix_control.master != MULTI_CONTROL_MASTERID)
329 					values[1] = mmvi->values[i + 1].gain;
330 
331 				control->set(card, control->channel, control->type, values);
332 			}
333 
334 			if (control2)
335 				i++;
336 		}
337 
338 		if (control->mix_control.flags & B_MULTI_MIX_ENABLE && control->set) {
339 			float values[1];
340 
341 			values[0] = mmvi->values[i].enable ? 1.0 : 0.0;
342 			control->set(card, control->channel, control->type, values);
343 		}
344 
345 		if (control->mix_control.flags & B_MULTI_MIX_MUX && control->set) {
346 			float values[1];
347 
348 			values[0] = (float)mmvi->values[i].mux;
349 			control->set(card, control->channel, control->type, values);
350 		}
351 	}
352 	return B_OK;
353 }
354 
355 
356 static status_t
357 echo_list_mix_controls(echo_dev *card, multi_mix_control_info * mmci)
358 {
359 	multi_mix_control	*mmc;
360 	uint32 i;
361 
362 	mmc = mmci->controls;
363 	if (mmci->control_count < 24)
364 		return B_ERROR;
365 
366 	if (echo_create_controls_list(&card->multi) < B_OK)
367 		return B_ERROR;
368 	for (i = 0; i < card->multi.control_count; i++) {
369 		mmc[i] = card->multi.controls[i].mix_control;
370 	}
371 
372 	mmci->control_count = card->multi.control_count;
373 	return B_OK;
374 }
375 
376 
377 static status_t
378 echo_list_mix_connections(echo_dev* card, multi_mix_connection_info* data)
379 {
380 	return B_ERROR;
381 }
382 
383 
384 static status_t
385 echo_list_mix_channels(echo_dev *card, multi_mix_channel_info *data)
386 {
387 	return B_ERROR;
388 }
389 
390 /*multi_channel_info chans[] = {
391 {  0, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
392 {  1, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
393 {  2, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
394 {  3, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
395 {  4, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
396 {  5, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
397 {  6, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
398 {  7, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
399 {  8, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
400 {  9, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
401 {  10, B_MULTI_INPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
402 {  11, B_MULTI_INPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
403 };*/
404 
405 /*multi_channel_info chans[] = {
406 {  0, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
407 {  1, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
408 {  2, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_SURROUND_BUS, 0 },
409 {  3, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_SURROUND_BUS, 0 },
410 {  4, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_REARLEFT | B_CHANNEL_SURROUND_BUS, 0 },
411 {  5, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_REARRIGHT | B_CHANNEL_SURROUND_BUS, 0 },
412 {  6, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
413 {  7, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
414 {  8, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
415 {  9, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
416 {  10, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
417 {  11, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
418 {  12, B_MULTI_INPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
419 {  13, B_MULTI_INPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
420 };*/
421 
422 
423 static void
424 echo_create_channels_list(multi_dev *multi)
425 {
426 	echo_stream *stream;
427 	int32 mode;
428 	uint32 index, i, designations;
429 	multi_channel_info *chans;
430 	uint32 chan_designations[] = {
431 		B_CHANNEL_LEFT,
432 		B_CHANNEL_RIGHT,
433 		B_CHANNEL_REARLEFT,
434 		B_CHANNEL_REARRIGHT,
435 		B_CHANNEL_CENTER,
436 		B_CHANNEL_SUB
437 	};
438 
439 	chans = multi->chans;
440 	index = 0;
441 
442 	for (mode=ECHO_USE_PLAY; mode!=-1;
443 		mode = (mode == ECHO_USE_PLAY) ? ECHO_USE_RECORD : -1) {
444 		LIST_FOREACH(stream, &((echo_dev*)multi->card)->streams, next) {
445 			if ((stream->use & mode) == 0)
446 				continue;
447 
448 			if (stream->channels == 2)
449 				designations = B_CHANNEL_STEREO_BUS;
450 			else
451 				designations = B_CHANNEL_SURROUND_BUS;
452 
453 			for (i = 0; i < stream->channels; i++) {
454 				chans[index].channel_id = index;
455 				chans[index].kind = (mode == ECHO_USE_PLAY) ? B_MULTI_OUTPUT_CHANNEL : B_MULTI_INPUT_CHANNEL;
456 				chans[index].designations = designations | chan_designations[i];
457 				chans[index].connectors = 0;
458 				index++;
459 			}
460 		}
461 
462 		if (mode==ECHO_USE_PLAY) {
463 			multi->output_channel_count = index;
464 		} else {
465 			multi->input_channel_count = index - multi->output_channel_count;
466 		}
467 	}
468 
469 	chans[index].channel_id = index;
470 	chans[index].kind = B_MULTI_OUTPUT_BUS;
471 	chans[index].designations = B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS;
472 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
473 	index++;
474 
475 	chans[index].channel_id = index;
476 	chans[index].kind = B_MULTI_OUTPUT_BUS;
477 	chans[index].designations = B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS;
478 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
479 	index++;
480 
481 	multi->output_bus_channel_count = index - multi->output_channel_count
482 		- multi->input_channel_count;
483 
484 	chans[index].channel_id = index;
485 	chans[index].kind = B_MULTI_INPUT_BUS;
486 	chans[index].designations = B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS;
487 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
488 	index++;
489 
490 	chans[index].channel_id = index;
491 	chans[index].kind = B_MULTI_INPUT_BUS;
492 	chans[index].designations = B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS;
493 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
494 	index++;
495 
496 	multi->input_bus_channel_count = index - multi->output_channel_count
497 		- multi->input_channel_count - multi->output_bus_channel_count;
498 
499 	multi->aux_bus_channel_count = 0;
500 }
501 
502 
503 static status_t
504 echo_get_description(echo_dev *card, multi_description *data)
505 {
506 	int32 size;
507 
508 	data->interface_version = B_CURRENT_INTERFACE_VERSION;
509 	data->interface_minimum = B_CURRENT_INTERFACE_VERSION;
510 
511 	strlcpy(data->friendly_name, card->caps.szName, sizeof(data->friendly_name));
512 	strlcpy(data->vendor_info, AUTHOR, sizeof(data->vendor_info));
513 
514 	data->output_channel_count = card->multi.output_channel_count;
515 	data->input_channel_count = card->multi.input_channel_count;
516 	data->output_bus_channel_count = card->multi.output_bus_channel_count;
517 	data->input_bus_channel_count = card->multi.input_bus_channel_count;
518 	data->aux_bus_channel_count = card->multi.aux_bus_channel_count;
519 
520 	size = card->multi.output_channel_count + card->multi.input_channel_count
521 			+ card->multi.output_bus_channel_count + card->multi.input_bus_channel_count
522 			+ card->multi.aux_bus_channel_count;
523 
524 	// for each channel, starting with the first output channel,
525 	// then the second, third..., followed by the first input
526 	// channel, second, third, ..., followed by output bus
527 	// channels and input bus channels and finally auxillary channels,
528 
529 	LOG(("request_channel_count = %d\n",data->request_channel_count));
530 	if (data->request_channel_count >= size) {
531 		LOG(("copying data\n"));
532 		memcpy(data->channels, card->multi.chans, size * sizeof(card->multi.chans[0]));
533 	}
534 
535 	switch (current_settings.sample_rate) {
536 		case 192000: data->output_rates = data->input_rates = B_SR_192000; break;
537 		case 96000: data->output_rates = data->input_rates = B_SR_96000; break;
538 		case 48000: data->output_rates = data->input_rates = B_SR_48000; break;
539 		case 44100: data->output_rates = data->input_rates = B_SR_44100; break;
540 	}
541 	data->min_cvsr_rate = 0;
542 	data->max_cvsr_rate = 48000;
543 
544 	switch (current_settings.bitsPerSample) {
545 		case 8: data->output_formats = data->input_formats = B_FMT_8BIT_U; break;
546 		case 16: data->output_formats = data->input_formats = B_FMT_16BIT; break;
547 		case 24: data->output_formats = data->input_formats = B_FMT_24BIT; break;
548 		case 32: data->output_formats = data->input_formats = B_FMT_32BIT; break;
549 	}
550 	data->lock_sources = B_MULTI_LOCK_INTERNAL;
551 	data->timecode_sources = 0;
552 	data->interface_flags = B_MULTI_INTERFACE_PLAYBACK | B_MULTI_INTERFACE_RECORD;
553 	data->start_latency = 3000;
554 
555 	strcpy(data->control_panel, "");
556 
557 	return B_OK;
558 }
559 
560 
561 static status_t
562 echo_get_enabled_channels(echo_dev *card, multi_channel_enable *data)
563 {
564 	B_SET_CHANNEL(data->enable_bits, 0, true);
565 	B_SET_CHANNEL(data->enable_bits, 1, true);
566 	B_SET_CHANNEL(data->enable_bits, 2, true);
567 	B_SET_CHANNEL(data->enable_bits, 3, true);
568 	data->lock_source = B_MULTI_LOCK_INTERNAL;
569 /*
570 	uint32			lock_source;
571 	int32			lock_data;
572 	uint32			timecode_source;
573 	uint32 *		connectors;
574 */
575 	return B_OK;
576 }
577 
578 
579 static status_t
580 echo_set_enabled_channels(echo_dev *card, multi_channel_enable *data)
581 {
582 	PRINT(("set_enabled_channels 0 : %s\n", B_TEST_CHANNEL(data->enable_bits, 0) ? "enabled": "disabled"));
583 	PRINT(("set_enabled_channels 1 : %s\n", B_TEST_CHANNEL(data->enable_bits, 1) ? "enabled": "disabled"));
584 	PRINT(("set_enabled_channels 2 : %s\n", B_TEST_CHANNEL(data->enable_bits, 2) ? "enabled": "disabled"));
585 	PRINT(("set_enabled_channels 3 : %s\n", B_TEST_CHANNEL(data->enable_bits, 3) ? "enabled": "disabled"));
586 	return B_OK;
587 }
588 
589 
590 static status_t
591 echo_get_global_format(echo_dev *card, multi_format_info *data)
592 {
593 	data->output_latency = 0;
594 	data->input_latency = 0;
595 	data->timecode_kind = 0;
596 	switch (current_settings.sample_rate) {
597 		case 192000: data->output.rate = data->input.rate = B_SR_192000; break;
598 		case 96000: data->output.rate = data->input.rate = B_SR_96000; break;
599 		case 48000: data->output.rate = data->input.rate = B_SR_48000; break;
600 		case 44100: data->output.rate = data->input.rate = B_SR_44100; break;
601 	}
602 	switch (current_settings.bitsPerSample) {
603 		case 8: data->input.format = data->output.format = B_FMT_8BIT_U; break;
604 		case 16: data->input.format = data->output.format = B_FMT_16BIT; break;
605 		case 24: data->input.format = data->output.format = B_FMT_24BIT; break;
606 		case 32: data->input.format = data->output.format = B_FMT_32BIT; break;
607 	}
608 	data->input.cvsr = data->output.cvsr = current_settings.sample_rate;
609 	return B_OK;
610 }
611 
612 
613 static status_t
614 echo_get_buffers(echo_dev *card, multi_buffer_list *data)
615 {
616 	int32 i, j, channels;
617 	echo_stream *stream;
618 
619 	LOG(("flags = %#x\n",data->flags));
620 	LOG(("request_playback_buffers = %#x\n",data->request_playback_buffers));
621 	LOG(("request_playback_channels = %#x\n",data->request_playback_channels));
622 	LOG(("request_playback_buffer_size = %#x\n",data->request_playback_buffer_size));
623 	LOG(("request_record_buffers = %#x\n",data->request_record_buffers));
624 	LOG(("request_record_channels = %#x\n",data->request_record_channels));
625 	LOG(("request_record_buffer_size = %#x\n",data->request_record_buffer_size));
626 
627 	if (data->request_playback_buffers < current_settings.buffer_count ||
628 		data->request_record_buffers < current_settings.buffer_count) {
629 		LOG(("not enough channels/buffers\n"));
630 	}
631 
632 	ASSERT(current_settings.buffer_count == 2);
633 
634 	data->flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD; // XXX ???
635 
636 	data->return_playback_buffers = current_settings.buffer_count;	/* playback_buffers[b][] */
637 	data->return_playback_channels = 0;	/* playback_buffers[][c] */
638 	data->return_playback_buffer_size = current_settings.buffer_frames;		/* frames */
639 
640 	LIST_FOREACH(stream, &card->streams, next) {
641 		if ((stream->use & ECHO_USE_PLAY) == 0)
642 			continue;
643 		LOG(("get_buffers pipe %d\n", stream->pipe));
644 		channels = data->return_playback_channels;
645 		data->return_playback_channels += stream->channels;
646 		if (data->request_playback_channels < data->return_playback_channels) {
647 			LOG(("not enough channels\n"));
648 		}
649 		for (i = 0; i < current_settings.buffer_count; i++)
650 			for (j=0; j<stream->channels; j++)
651 				echo_stream_get_nth_buffer(stream, j, i,
652 					&data->playback_buffers[i][channels+j].base,
653 					&data->playback_buffers[i][channels+j].stride);
654 	}
655 
656 	data->return_record_buffers = current_settings.buffer_count;
657 	data->return_record_channels = 0;
658 	data->return_record_buffer_size = current_settings.buffer_frames;	/* frames */
659 
660 	LIST_FOREACH(stream, &card->streams, next) {
661 		if ((stream->use & ECHO_USE_PLAY) != 0)
662 			continue;
663 		LOG(("get_buffers pipe %d\n", stream->pipe));
664 		channels = data->return_record_channels;
665 		data->return_record_channels += stream->channels;
666 		if (data->request_record_channels < data->return_record_channels) {
667 			LOG(("not enough channels\n"));
668 		}
669 		for (i = 0; i < current_settings.buffer_count; i++)
670 			for (j = 0; j < stream->channels; j++)
671 				echo_stream_get_nth_buffer(stream, j, i,
672 					&data->record_buffers[i][channels + j].base,
673 					&data->record_buffers[i][channels + j].stride);
674 	}
675 
676 	return B_OK;
677 }
678 
679 
680 void
681 echo_play_inth(void* inthparams)
682 {
683 	echo_stream *stream = (echo_stream *)inthparams;
684 	//int32 count;
685 
686 	//TRACE(("echo_play_inth\n"));
687 
688 	acquire_spinlock(&slock);
689 	stream->real_time = system_time();
690 	stream->frames_count += current_settings.buffer_frames;
691 	stream->buffer_cycle = (stream->trigblk
692 		+ stream->blkmod) % stream->blkmod;
693 	stream->update_needed = true;
694 	release_spinlock(&slock);
695 
696 	//get_sem_count(stream->card->buffer_ready_sem, &count);
697 	//if (count <= 0)
698 		release_sem_etc(stream->card->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE);
699 }
700 
701 
702 void
703 echo_record_inth(void* inthparams)
704 {
705 	echo_stream *stream = (echo_stream *)inthparams;
706 	//int32 count;
707 
708 	//TRACE(("echo_record_inth\n"));
709 
710 	acquire_spinlock(&slock);
711 	stream->real_time = system_time();
712 	stream->frames_count += current_settings.buffer_frames;
713 	stream->buffer_cycle = (stream->trigblk
714 		+ stream->blkmod - 1) % stream->blkmod;
715 	stream->update_needed = true;
716 	release_spinlock(&slock);
717 
718 	//get_sem_count(stream->card->buffer_ready_sem, &count);
719 	//if (count <= 0)
720 		release_sem_etc(stream->card->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE);
721 }
722 
723 
724 static status_t
725 echo_buffer_exchange(echo_dev *card, multi_buffer_info *data)
726 {
727 	cpu_status status;
728 	echo_stream *pstream, *rstream, *stream;
729 	multi_buffer_info buffer_info;
730 
731 #ifdef __HAIKU__
732 	if (user_memcpy(&buffer_info, data, sizeof(buffer_info)) < B_OK)
733 		return B_BAD_ADDRESS;
734 #else
735 	memcpy(&buffer_info, data, sizeof(buffer_info));
736 #endif
737 
738 	buffer_info.flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD;
739 
740 	LIST_FOREACH(stream, &card->streams, next) {
741 		if ((stream->state & ECHO_STATE_STARTED) != 0)
742 			continue;
743 		echo_stream_start(stream,
744 			((stream->use & ECHO_USE_PLAY) == 0) ? echo_record_inth : echo_play_inth, stream);
745 	}
746 
747 	if (acquire_sem_etc(card->buffer_ready_sem, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, 50000)
748 		== B_TIMED_OUT) {
749 		LOG(("buffer_exchange timeout ff\n"));
750 	}
751 
752 	status = lock();
753 
754 	LIST_FOREACH(pstream, &card->streams, next) {
755 		if ((pstream->use & ECHO_USE_PLAY) == 0 ||
756 			(pstream->state & ECHO_STATE_STARTED) == 0)
757 			continue;
758 		if (pstream->update_needed)
759 			break;
760 	}
761 
762 	LIST_FOREACH(rstream, &card->streams, next) {
763 		if ((rstream->use & ECHO_USE_RECORD) == 0 ||
764 			(rstream->state & ECHO_STATE_STARTED) == 0)
765 			continue;
766 		if (rstream->update_needed)
767 			break;
768 	}
769 
770 	if (!pstream)
771 		pstream = card->pstream;
772 	if (!rstream)
773 		rstream = card->rstream;
774 
775 	/* do playback */
776 	buffer_info.playback_buffer_cycle = pstream->buffer_cycle;
777 	buffer_info.played_real_time = pstream->real_time;
778 	buffer_info.played_frames_count = pstream->frames_count;
779 	buffer_info._reserved_0 = pstream->first_channel;
780 	pstream->update_needed = false;
781 
782 	/* do record */
783 	buffer_info.record_buffer_cycle = rstream->buffer_cycle;
784 	buffer_info.recorded_frames_count = rstream->frames_count;
785 	buffer_info.recorded_real_time = rstream->real_time;
786 	buffer_info._reserved_1 = rstream->first_channel;
787 	rstream->update_needed = false;
788 	unlock(status);
789 
790 #ifdef __HAIKU__
791 	if (user_memcpy(data, &buffer_info, sizeof(buffer_info)) < B_OK)
792 		return B_BAD_ADDRESS;
793 #else
794 	memcpy(data, &buffer_info, sizeof(buffer_info));
795 #endif
796 
797 	//TRACE(("buffer_exchange ended\n"));
798 	return B_OK;
799 }
800 
801 
802 static status_t
803 echo_buffer_force_stop(echo_dev *card)
804 {
805 	//echo_voice_halt(card->pvoice);
806 	return B_OK;
807 }
808 
809 
810 static status_t
811 echo_multi_control(void *cookie, uint32 op, void *data, size_t length)
812 {
813 	echo_dev *card = (echo_dev *)cookie;
814 
815 #ifdef CARDBUS
816 	// Check
817 	if (card->plugged == false) {
818 		LOG(("device %s unplugged\n", card->name));
819 		return B_ERROR;
820 	}
821 #endif
822 
823 	switch (op) {
824 		case B_MULTI_GET_DESCRIPTION:
825 			LOG(("B_MULTI_GET_DESCRIPTION\n"));
826 			return echo_get_description(card, (multi_description *)data);
827 		case B_MULTI_GET_EVENT_INFO:
828 			LOG(("B_MULTI_GET_EVENT_INFO\n"));
829 			return B_ERROR;
830 		case B_MULTI_SET_EVENT_INFO:
831 			LOG(("B_MULTI_SET_EVENT_INFO\n"));
832 			return B_ERROR;
833 		case B_MULTI_GET_EVENT:
834 			LOG(("B_MULTI_GET_EVENT\n"));
835 			return B_ERROR;
836 		case B_MULTI_GET_ENABLED_CHANNELS:
837 			LOG(("B_MULTI_GET_ENABLED_CHANNELS\n"));
838 			return echo_get_enabled_channels(card, (multi_channel_enable *)data);
839 		case B_MULTI_SET_ENABLED_CHANNELS:
840 			LOG(("B_MULTI_SET_ENABLED_CHANNELS\n"));
841 			return echo_set_enabled_channels(card, (multi_channel_enable *)data);
842 		case B_MULTI_GET_GLOBAL_FORMAT:
843 			LOG(("B_MULTI_GET_GLOBAL_FORMAT\n"));
844 			return echo_get_global_format(card, (multi_format_info *)data);
845 		case B_MULTI_SET_GLOBAL_FORMAT:
846 			LOG(("B_MULTI_SET_GLOBAL_FORMAT\n"));
847 			return B_OK; /* XXX BUG! we *MUST* return B_OK, returning B_ERROR will prevent
848 						  * BeOS to accept the format returned in B_MULTI_GET_GLOBAL_FORMAT
849 						  */
850 		case B_MULTI_GET_CHANNEL_FORMATS:
851 			LOG(("B_MULTI_GET_CHANNEL_FORMATS\n"));
852 			return B_ERROR;
853 		case B_MULTI_SET_CHANNEL_FORMATS:	/* only implemented if possible */
854 			LOG(("B_MULTI_SET_CHANNEL_FORMATS\n"));
855 			return B_ERROR;
856 		case B_MULTI_GET_MIX:
857 			LOG(("B_MULTI_GET_MIX\n"));
858 			return echo_get_mix(card, (multi_mix_value_info *)data);
859 		case B_MULTI_SET_MIX:
860 			LOG(("B_MULTI_SET_MIX\n"));
861 			return echo_set_mix(card, (multi_mix_value_info *)data);
862 		case B_MULTI_LIST_MIX_CHANNELS:
863 			LOG(("B_MULTI_LIST_MIX_CHANNELS\n"));
864 			return echo_list_mix_channels(card, (multi_mix_channel_info *)data);
865 		case B_MULTI_LIST_MIX_CONTROLS:
866 			LOG(("B_MULTI_LIST_MIX_CONTROLS\n"));
867 			return echo_list_mix_controls(card, (multi_mix_control_info *)data);
868 		case B_MULTI_LIST_MIX_CONNECTIONS:
869 			LOG(("B_MULTI_LIST_MIX_CONNECTIONS\n"));
870 			return echo_list_mix_connections(card, (multi_mix_connection_info *)data);
871 		case B_MULTI_GET_BUFFERS:			/* Fill out the struct for the first time; doesn't start anything. */
872 			LOG(("B_MULTI_GET_BUFFERS\n"));
873 			return echo_get_buffers(card, (multi_buffer_list*)data);
874 		case B_MULTI_SET_BUFFERS:			/* Set what buffers to use, if the driver supports soft buffers. */
875 			LOG(("B_MULTI_SET_BUFFERS\n"));
876 			return B_ERROR; /* we do not support soft buffers */
877 		case B_MULTI_SET_START_TIME:			/* When to actually start */
878 			LOG(("B_MULTI_SET_START_TIME\n"));
879 			return B_ERROR;
880 		case B_MULTI_BUFFER_EXCHANGE:		/* stop and go are derived from this being called */
881 			//TRACE(("B_MULTI_BUFFER_EXCHANGE\n"));
882 			return echo_buffer_exchange(card, (multi_buffer_info *)data);
883 		case B_MULTI_BUFFER_FORCE_STOP:		/* force stop of playback, nothing in data */
884 			LOG(("B_MULTI_BUFFER_FORCE_STOP\n"));
885 			return echo_buffer_force_stop(card);
886 	}
887 	LOG(("ERROR: unknown multi_control %#x\n",op));
888 	return B_ERROR;
889 }
890 
891 
892 static status_t echo_open(const char *name, uint32 flags, void** cookie);
893 static status_t echo_close(void* cookie);
894 static status_t echo_free(void* cookie);
895 static status_t echo_control(void* cookie, uint32 op, void* arg, size_t len);
896 static status_t echo_read(void* cookie, off_t position, void *buf, size_t* num_bytes);
897 static status_t echo_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes);
898 
899 
900 device_hooks multi_hooks = {
901 	echo_open, 			/* -> open entry point */
902 	echo_close, 			/* -> close entry point */
903 	echo_free,			/* -> free cookie */
904 	echo_control, 		/* -> control entry point */
905 	echo_read,			/* -> read entry point */
906 	echo_write,			/* -> write entry point */
907 	NULL,					/* start select */
908 	NULL,					/* stop select */
909 	NULL,					/* scatter-gather read from the device */
910 	NULL					/* scatter-gather write to the device */
911 };
912 
913 
914 static status_t
915 echo_open(const char *name, uint32 flags, void** cookie)
916 {
917 	echo_dev *card = NULL;
918 	int i, first_record_channel;
919 	echo_stream *stream = NULL;
920 
921 	LOG(("echo_open()\n"));
922 
923 #ifdef CARDBUS
924 	LIST_FOREACH(card, &devices, next) {
925 		if (!strcmp(card->name, name)) {
926 			break;
927 		}
928 	}
929 #else
930 	for (i = 0; i < num_cards; i++) {
931 		if (!strcmp(cards[i].name, name)) {
932 			card = &cards[i];
933 		}
934 	}
935 #endif
936 
937 	if (card == NULL) {
938 		LOG(("open() card not found %s\n", name));
939 #ifdef CARDBUS
940 		LIST_FOREACH(card, &devices, next) {
941 			LOG(("open() card available %s\n", card->name));
942 		}
943 #else
944 		for (int ix=0; ix<num_cards; ix++) {
945 			LOG(("open() card available %s\n", cards[ix].name));
946 		}
947 #endif
948 		return B_ERROR;
949 	}
950 
951 #ifdef CARDBUS
952 	if (card->plugged == false) {
953 		LOG(("device %s unplugged\n", name));
954 		return B_ERROR;
955 	}
956 #endif
957 
958 	LOG(("open() got card\n"));
959 
960 	if (card->pstream != NULL)
961 		return B_ERROR;
962 	if (card->rstream != NULL)
963 		return B_ERROR;
964 
965 	*cookie = card;
966 	card->multi.card = card;
967 #ifdef CARDBUS
968 	card->opened = true;
969 #endif
970 
971 	void *settings_handle;
972 	// get driver settings
973 	settings_handle = load_driver_settings ("echo.settings");
974 	if (settings_handle != NULL) {
975 		const char* item;
976 		char* end;
977 		uint32 value;
978 
979 		item = get_driver_parameter (settings_handle, "channels", NULL, NULL);
980 		if (item) {
981 			value = strtoul (item, &end, 0);
982 			if (*end == '\0') current_settings.channels = value;
983 		}
984 		PRINT(("channels %u\n", current_settings.channels));
985 
986 		item = get_driver_parameter (settings_handle, "bitsPerSample", NULL, NULL);
987 		if (item) {
988 			value = strtoul (item, &end, 0);
989 			if (*end == '\0') current_settings.bitsPerSample = value;
990 		}
991 		PRINT(("bitsPerSample %u\n", current_settings.bitsPerSample));
992 
993 		item = get_driver_parameter (settings_handle, "sample_rate", NULL, NULL);
994 		if (item) {
995 			value = strtoul (item, &end, 0);
996 			if (*end == '\0') current_settings.sample_rate = value;
997 		}
998 		PRINT(("sample_rate %lu\n", current_settings.sample_rate));
999 
1000 		item = get_driver_parameter (settings_handle, "buffer_frames", NULL, NULL);
1001 		if (item) {
1002 			value = strtoul (item, &end, 0);
1003 			if (*end == '\0') current_settings.buffer_frames = value;
1004 		}
1005 		PRINT(("buffer_frames %lu\n", current_settings.buffer_frames));
1006 
1007 		item = get_driver_parameter (settings_handle, "buffer_count", NULL, NULL);
1008 		if (item) {
1009 			value = strtoul (item, &end, 0);
1010 			if (*end == '\0') current_settings.buffer_count = value;
1011 		}
1012 		PRINT(("buffer_count %lu\n", current_settings.buffer_count));
1013 
1014 		unload_driver_settings (settings_handle);
1015 	}
1016 
1017 	LOG(("creating play streams\n"));
1018 
1019 	i = card->caps.wNumPipesOut - 2;
1020 	first_record_channel = card->caps.wNumPipesOut;
1021 #ifdef ECHO3G_FAMILY
1022 	if (current_settings.sample_rate > 50000) {
1023 		i = card->caps.wFirstDigitalBusOut;
1024 		first_record_channel = card->caps.wFirstDigitalBusOut + 2;
1025 	}
1026 #endif
1027 
1028 	for (; i >= 0 ; i -= 2) {
1029 		stream = echo_stream_new(card, ECHO_USE_PLAY, current_settings.buffer_frames, current_settings.buffer_count);
1030 		if (!card->pstream)
1031 			card->pstream = stream;
1032 		echo_stream_set_audioparms(stream, current_settings.channels,
1033 			current_settings.bitsPerSample, current_settings.sample_rate, i);
1034 		stream->first_channel = i;
1035 	}
1036 
1037 	LOG(("creating record streams\n"));
1038 	i = card->caps.wNumPipesIn - 2;
1039 #ifdef ECHO3G_FAMILY
1040 	if (current_settings.sample_rate > 50000) {
1041 		i = card->caps.wFirstDigitalBusIn;
1042 	}
1043 #endif
1044 
1045 	for (; i >= 0; i-=2) {
1046 		stream = echo_stream_new(card, ECHO_USE_RECORD, current_settings.buffer_frames, current_settings.buffer_count);
1047 		if (!card->rstream)
1048 			card->rstream = stream;
1049 		echo_stream_set_audioparms(stream, current_settings.channels,
1050 			current_settings.bitsPerSample, current_settings.sample_rate, i);
1051 		stream->first_channel = i + first_record_channel;
1052 	}
1053 
1054 	card->buffer_ready_sem = create_sem(0, "pbuffer ready");
1055 
1056 	LOG(("creating channels list\n"));
1057 	echo_create_channels_list(&card->multi);
1058 
1059 	return B_OK;
1060 }
1061 
1062 
1063 static status_t
1064 echo_close(void* cookie)
1065 {
1066 	LOG(("close()\n"));
1067 #ifdef CARDBUS
1068 	echo_dev *card = (echo_dev *) cookie;
1069 	card->opened = false;
1070 #endif
1071 
1072 	return B_OK;
1073 }
1074 
1075 
1076 static status_t
1077 echo_free(void* cookie)
1078 {
1079 	echo_dev *card = (echo_dev *) cookie;
1080 	echo_stream *stream;
1081 	LOG(("echo_free()\n"));
1082 
1083 	if (card->buffer_ready_sem > B_OK)
1084 			delete_sem(card->buffer_ready_sem);
1085 
1086 	LIST_FOREACH(stream, &card->streams, next) {
1087 		echo_stream_halt(stream);
1088 	}
1089 
1090 	while (!LIST_EMPTY(&card->streams)) {
1091 		echo_stream_delete(LIST_FIRST(&card->streams));
1092 	}
1093 
1094 	card->pstream = NULL;
1095 	card->rstream = NULL;
1096 
1097 	return B_OK;
1098 }
1099 
1100 
1101 static status_t
1102 echo_control(void* cookie, uint32 op, void* arg, size_t len)
1103 {
1104 	return echo_multi_control(cookie, op, arg, len);
1105 }
1106 
1107 
1108 static status_t
1109 echo_read(void* cookie, off_t position, void *buf, size_t* num_bytes)
1110 {
1111 	*num_bytes = 0;				/* tell caller nothing was read */
1112 	return B_IO_ERROR;
1113 }
1114 
1115 
1116 static status_t
1117 echo_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
1118 {
1119 	*num_bytes = 0;				/* tell caller nothing was written */
1120 	return B_IO_ERROR;
1121 }
1122