xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/auich/multi.c (revision bddcee2a27042b4d8d6b0142b466f30abc886648)
1 /*
2  * Auich BeOS Driver for Intel Southbridge audio
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 <string.h>
36 #include <strings.h>
37 
38 #include <kernel.h>
39 
40 #include "hmulti_audio.h"
41 #include "multi.h"
42 #include "ac97.h"
43 
44 //#define DEBUG 1
45 
46 #include "debug.h"
47 #include "auich.h"
48 #include "util.h"
49 #include "io.h"
50 
51 
52 static void
53 auich_ac97_get_mix(void *card, const void *cookie, int32 type, float *values) {
54 	auich_dev *dev = (auich_dev*)card;
55 	ac97_source_info *info = (ac97_source_info *)cookie;
56 	uint16 value, mask;
57 	float gain;
58 
59 	switch(type) {
60 		case B_MIX_GAIN:
61 			value = auich_codec_read(&dev->config, info->reg);
62 			//PRINT(("B_MIX_GAIN value : %u\n", value));
63 			if (info->type & B_MIX_STEREO) {
64 				mask = ((1 << (info->bits + 1)) - 1) << 8;
65 				gain = ((value & mask) >> 8) * info->granularity;
66 				if (info->polarity == 1)
67 					values[0] = info->max_gain - gain;
68 				else
69 					values[0] = gain - info->min_gain;
70 
71 				mask = ((1 << (info->bits + 1)) - 1);
72 				gain = (value & mask) * info->granularity;
73 				if (info->polarity == 1)
74 					values[1] = info->max_gain - gain;
75 				else
76 					values[1] = gain - info->min_gain;
77 			} else {
78 				mask = ((1 << (info->bits + 1)) - 1);
79 				gain = (value & mask) * info->granularity;
80 				if (info->polarity == 1)
81 					values[0] = info->max_gain - gain;
82 				else
83 					values[0] = gain - info->min_gain;
84 			}
85 			break;
86 		case B_MIX_MUTE:
87 			mask = ((1 << 1) - 1) << 15;
88 			value = auich_codec_read(&dev->config, info->reg);
89 			//PRINT(("B_MIX_MUTE value : %u\n", value));
90 			value &= mask;
91 			values[0] = ((value >> 15) == 1) ? 1.0 : 0.0;
92 			break;
93 		case B_MIX_MICBOOST:
94 			mask = ((1 << 1) - 1) << 6;
95 			value = auich_codec_read(&dev->config, info->reg);
96 			//PRINT(("B_MIX_MICBOOST value : %u\n", value));
97 			value &= mask;
98 			values[0] = ((value >> 6) == 1) ? 1.0 : 0.0;
99 			break;
100 		case B_MIX_MUX:
101 			mask = ((1 << 3) - 1);
102 			value = auich_codec_read(&dev->config, AC97_RECORD_SELECT);
103 			value &= mask;
104 			//PRINT(("B_MIX_MUX value : %u\n", value));
105 			values[0] = (float)value;
106 			break;
107 	}
108 }
109 
110 
111 static void
112 auich_ac97_set_mix(void *card, const void *cookie, int32 type, float *values) {
113 	auich_dev *dev = (auich_dev*)card;
114 	ac97_source_info *info = (ac97_source_info *)cookie;
115 	uint16 value, mask;
116 	float gain;
117 
118 	switch(type) {
119 		case B_MIX_GAIN:
120 			value = auich_codec_read(&dev->config, info->reg);
121 			if (info->type & B_MIX_STEREO) {
122 				mask = ((1 << (info->bits + 1)) - 1) << 8;
123 				value &= ~mask;
124 
125 				if (info->polarity == 1)
126 					gain = info->max_gain - values[0];
127 				else
128 					gain =  values[0] - info->min_gain;
129 				value |= ((uint16)(gain	/ info->granularity) << 8) & mask;
130 
131 				mask = ((1 << (info->bits + 1)) - 1);
132 				value &= ~mask;
133 				if (info->polarity == 1)
134 					gain = info->max_gain - values[1];
135 				else
136 					gain =  values[1] - info->min_gain;
137 				value |= ((uint16)(gain / info->granularity)) & mask;
138 			} else {
139 				mask = ((1 << (info->bits + 1)) - 1);
140 				value &= ~mask;
141 				if (info->polarity == 1)
142 					gain = info->max_gain - values[0];
143 				else
144 					gain =  values[0] - info->min_gain;
145 				value |= ((uint16)(gain / info->granularity)) & mask;
146 			}
147 			//PRINT(("B_MIX_GAIN value : %u\n", value));
148 			auich_codec_write(&dev->config, info->reg, value);
149 			break;
150 		case B_MIX_MUTE:
151 			mask = ((1 << 1) - 1) << 15;
152 			value = auich_codec_read(&dev->config, info->reg);
153 			value &= ~mask;
154 			value |= ((values[0] == 1.0 ? 1 : 0 ) << 15 & mask);
155 			if (info->reg == AC97_SURR_VOLUME) {
156 				// there is a independent mute for each channel
157 				mask = ((1 << 1) - 1) << 7;
158 				value &= ~mask;
159 				value |= ((values[0] == 1.0 ? 1 : 0 ) << 7 & mask);
160 			}
161 			//PRINT(("B_MIX_MUTE value : %u\n", value));
162 			auich_codec_write(&dev->config, info->reg, value);
163 			break;
164 		case B_MIX_MICBOOST:
165 			mask = ((1 << 1) - 1) << 6;
166 			value = auich_codec_read(&dev->config, info->reg);
167 			value &= ~mask;
168 			value |= ((values[0] == 1.0 ? 1 : 0 ) << 6 & mask);
169 			//PRINT(("B_MIX_MICBOOST value : %u\n", value));
170 			auich_codec_write(&dev->config, info->reg, value);
171 			break;
172 		case B_MIX_MUX:
173 			mask = ((1 << 3) - 1);
174 			value = ((int32)values[0]) & mask;
175 			value = value | (value << 8);
176 			//PRINT(("B_MIX_MUX value : %u\n", value));
177 			auich_codec_write(&dev->config, AC97_RECORD_SELECT, value);
178 			break;
179 	}
180 
181 }
182 
183 
184 static int32
185 auich_create_group_control(multi_dev *multi, int32 *index, int32 parent,
186 	int32 string, const char* name) {
187 	int32 i = *index;
188 	(*index)++;
189 	multi->controls[i].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + i;
190 	multi->controls[i].mix_control.parent = parent;
191 	multi->controls[i].mix_control.flags = B_MULTI_MIX_GROUP;
192 	multi->controls[i].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
193 	multi->controls[i].mix_control.string = string;
194 	if (name)
195 		strcpy(multi->controls[i].mix_control.name, name);
196 
197 	return multi->controls[i].mix_control.id;
198 }
199 
200 
201 static status_t
202 auich_create_controls_list(multi_dev *multi)
203 {
204 	uint32 	i = 0, index = 0, count, id, parent, parent2, parent3;
205 	const ac97_source_info *info;
206 
207 	/* AC97 Mixer */
208 	parent = auich_create_group_control(multi, &index, 0, 0, "AC97 mixer");
209 
210 	count = source_info_size;
211 	//Note that we ignore first item in source_info
212 	//It's for recording, but do match this with ac97.c's source_info
213 	for (i = 1; i < count ; i++) {
214 		info = &source_info[i];
215 		PRINT(("name : %s\n", info->name));
216 
217 		parent2 = auich_create_group_control(multi, &index, parent, 0, info->name);
218 
219 		if (info->type & B_MIX_GAIN) {
220 			if (info->type & B_MIX_MUTE) {
221 				multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
222 				multi->controls[index].mix_control.flags = B_MULTI_MIX_ENABLE;
223 				multi->controls[index].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
224 				multi->controls[index].mix_control.parent = parent2;
225 				multi->controls[index].mix_control.string = S_MUTE;
226 				multi->controls[index].cookie = info;
227 				multi->controls[index].type = B_MIX_MUTE;
228 				multi->controls[index].get = &auich_ac97_get_mix;
229 				multi->controls[index].set = &auich_ac97_set_mix;
230 				index++;
231 			}
232 
233 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
234 			multi->controls[index].mix_control.flags = B_MULTI_MIX_GAIN;
235 			multi->controls[index].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
236 			multi->controls[index].mix_control.parent = parent2;
237 			strcpy(multi->controls[index].mix_control.name, info->name);
238 			multi->controls[index].mix_control.u.gain.min_gain = info->min_gain;
239 			multi->controls[index].mix_control.u.gain.max_gain = info->max_gain;
240 			multi->controls[index].mix_control.u.gain.granularity = info->granularity;
241 			multi->controls[index].cookie = info;
242 			multi->controls[index].type = B_MIX_GAIN;
243 			multi->controls[index].get = &auich_ac97_get_mix;
244 			multi->controls[index].set = &auich_ac97_set_mix;
245 			id = multi->controls[index].mix_control.id;
246 			index++;
247 
248 			if (info->type & B_MIX_STEREO) {
249 				multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
250 				multi->controls[index].mix_control.flags = B_MULTI_MIX_GAIN;
251 				multi->controls[index].mix_control.master = id;
252 				multi->controls[index].mix_control.parent = parent2;
253 				strcpy(multi->controls[index].mix_control.name, info->name);
254 				multi->controls[index].mix_control.u.gain.min_gain = info->min_gain;
255 				multi->controls[index].mix_control.u.gain.max_gain = info->max_gain;
256 				multi->controls[index].mix_control.u.gain.granularity = info->granularity;
257 				multi->controls[index].cookie = info;
258 				multi->controls[index].type = B_MIX_GAIN;
259 				multi->controls[index].get = &auich_ac97_get_mix;
260 				multi->controls[index].set = &auich_ac97_set_mix;
261 				index++;
262 			}
263 
264 			if (info->type & B_MIX_MICBOOST) {
265 				multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
266 				multi->controls[index].mix_control.flags = B_MULTI_MIX_ENABLE;
267 				multi->controls[index].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
268 				multi->controls[index].mix_control.parent = parent2;
269 				strcpy(multi->controls[index].mix_control.name, "+20 dB");
270 				multi->controls[index].cookie = info;
271 				multi->controls[index].type = B_MIX_MICBOOST;
272 				multi->controls[index].get = &auich_ac97_get_mix;
273 				multi->controls[index].set = &auich_ac97_set_mix;
274 				index++;
275 			}
276 		}
277 	}
278 
279 	/* AC97 Record */
280 	parent = auich_create_group_control(multi, &index, 0, 0, "Recording");
281 
282 	info = &source_info[0];
283 	PRINT(("name : %s\n", info->name));
284 
285 	parent2 = auich_create_group_control(multi, &index, parent, 0, info->name);
286 
287 	if (info->type & B_MIX_GAIN) {
288 		if (info->type & B_MIX_MUTE) {
289 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
290 			multi->controls[index].mix_control.flags = B_MULTI_MIX_ENABLE;
291 			multi->controls[index].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
292 			multi->controls[index].mix_control.parent = parent2;
293 			multi->controls[index].mix_control.string = S_MUTE;
294 			multi->controls[index].cookie = info;
295 			multi->controls[index].type = B_MIX_MUTE;
296 			multi->controls[index].get = &auich_ac97_get_mix;
297 			multi->controls[index].set = &auich_ac97_set_mix;
298 			index++;
299 		}
300 
301 		multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
302 		multi->controls[index].mix_control.flags = B_MULTI_MIX_GAIN;
303 		multi->controls[index].mix_control.master = EMU_MULTI_CONTROL_MASTERID;
304 		multi->controls[index].mix_control.parent = parent2;
305 		strcpy(multi->controls[index].mix_control.name, info->name);
306 		multi->controls[index].mix_control.u.gain.min_gain = info->min_gain;
307 		multi->controls[index].mix_control.u.gain.max_gain = info->max_gain;
308 		multi->controls[index].mix_control.u.gain.granularity = info->granularity;
309 		multi->controls[index].cookie = info;
310 		multi->controls[index].type = B_MIX_GAIN;
311 		multi->controls[index].get = &auich_ac97_get_mix;
312 		multi->controls[index].set = &auich_ac97_set_mix;
313 		id = multi->controls[index].mix_control.id;
314 		index++;
315 
316 		if (info->type & B_MIX_STEREO) {
317 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
318 			multi->controls[index].mix_control.flags = B_MULTI_MIX_GAIN;
319 			multi->controls[index].mix_control.master = id;
320 			multi->controls[index].mix_control.parent = parent2;
321 			strcpy(multi->controls[index].mix_control.name, info->name);
322 			multi->controls[index].mix_control.u.gain.min_gain = info->min_gain;
323 			multi->controls[index].mix_control.u.gain.max_gain = info->max_gain;
324 			multi->controls[index].mix_control.u.gain.granularity = info->granularity;
325 			multi->controls[index].cookie = info;
326 			multi->controls[index].type = B_MIX_GAIN;
327 			multi->controls[index].get = &auich_ac97_get_mix;
328 			multi->controls[index].set = &auich_ac97_set_mix;
329 			index++;
330 		}
331 
332 		if (info->type & B_MIX_RECORDMUX) {
333 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
334 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX;
335 			multi->controls[index].mix_control.parent = parent2;
336 			strcpy(multi->controls[index].mix_control.name, "Record mux");
337 			multi->controls[index].cookie = info;
338 			multi->controls[index].type = B_MIX_MUX;
339 			multi->controls[index].get = &auich_ac97_get_mix;
340 			multi->controls[index].set = &auich_ac97_set_mix;
341 			parent3 = multi->controls[index].mix_control.id;
342 			index++;
343 
344 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
345 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
346 			multi->controls[index].mix_control.parent = parent3;
347 			multi->controls[index].mix_control.string = S_MIC;
348 			index++;
349 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
350 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
351 			multi->controls[index].mix_control.parent = parent3;
352 			strcpy(multi->controls[index].mix_control.name, "CD in");
353 			index++;
354 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
355 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
356 			multi->controls[index].mix_control.parent = parent3;
357 			strcpy(multi->controls[index].mix_control.name, "Video in");
358 			index++;
359 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
360 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
361 			multi->controls[index].mix_control.parent = parent3;
362 			strcpy(multi->controls[index].mix_control.name, "Aux in");
363 			index++;
364 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
365 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
366 			multi->controls[index].mix_control.parent = parent3;
367 			strcpy(multi->controls[index].mix_control.name, "Line in");
368 			index++;
369 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
370 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
371 			multi->controls[index].mix_control.parent = parent3;
372 			multi->controls[index].mix_control.string = S_STEREO_MIX;
373 			index++;
374 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
375 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
376 			multi->controls[index].mix_control.parent = parent3;
377 			multi->controls[index].mix_control.string = S_MONO_MIX;
378 			index++;
379 			multi->controls[index].mix_control.id = EMU_MULTI_CONTROL_FIRSTID + index;
380 			multi->controls[index].mix_control.flags = B_MULTI_MIX_MUX_VALUE;
381 			multi->controls[index].mix_control.parent = parent3;
382 			strcpy(multi->controls[index].mix_control.name, "TAD");
383 			index++;
384 		}
385 	}
386 
387 	multi->control_count = index;
388 	PRINT(("multi->control_count %lu\n", multi->control_count));
389 	return B_OK;
390 }
391 
392 
393 static status_t
394 auich_get_mix(auich_dev *card, multi_mix_value_info * mmvi)
395 {
396 	int32 i, id;
397 	multi_mixer_control *control = NULL;
398 	for (i = 0; i < mmvi->item_count; i++) {
399 		id = mmvi->values[i].id - EMU_MULTI_CONTROL_FIRSTID;
400 		if (id < 0 || id >= card->multi.control_count) {
401 			PRINT(("auich_get_mix : invalid control id requested : %li\n", id));
402 			continue;
403 		}
404 		control = &card->multi.controls[id];
405 
406 		if (control->mix_control.flags & B_MULTI_MIX_GAIN) {
407 			if (control->get) {
408 				float values[2];
409 				control->get(card, control->cookie, control->type, values);
410 				if (control->mix_control.master == EMU_MULTI_CONTROL_MASTERID)
411 					mmvi->values[i].u.gain = values[0];
412 				else
413 					mmvi->values[i].u.gain = values[1];
414 			}
415 		}
416 
417 		if (control->mix_control.flags & B_MULTI_MIX_ENABLE && control->get) {
418 			float values[1];
419 			control->get(card, control->cookie, control->type, values);
420 			mmvi->values[i].u.enable = (values[0] == 1.0);
421 		}
422 
423 		if (control->mix_control.flags & B_MULTI_MIX_MUX && control->get) {
424 			float values[1];
425 			control->get(card, control->cookie, control->type, values);
426 			mmvi->values[i].u.mux = (int32)values[0];
427 		}
428 	}
429 	return B_OK;
430 }
431 
432 
433 static status_t
434 auich_set_mix(auich_dev *card, multi_mix_value_info * mmvi)
435 {
436 	int32 i, id;
437 	multi_mixer_control *control = NULL;
438 	for (i = 0; i < mmvi->item_count; i++) {
439 		id = mmvi->values[i].id - EMU_MULTI_CONTROL_FIRSTID;
440 		if (id < 0 || id >= card->multi.control_count) {
441 			PRINT(("auich_set_mix : invalid control id requested : %li\n", id));
442 			continue;
443 		}
444 		control = &card->multi.controls[id];
445 
446 		if (control->mix_control.flags & B_MULTI_MIX_GAIN) {
447 			multi_mixer_control *control2 = NULL;
448 			if (i+1<mmvi->item_count) {
449 				id = mmvi->values[i + 1].id - EMU_MULTI_CONTROL_FIRSTID;
450 				if (id < 0 || id >= card->multi.control_count) {
451 					PRINT(("auich_set_mix : invalid control id requested : %li\n", id));
452 				} else {
453 					control2 = &card->multi.controls[id];
454 					if (control2->mix_control.master != control->mix_control.id)
455 						control2 = NULL;
456 				}
457 			}
458 
459 			if (control->set) {
460 				float values[2];
461 				values[0] = 0.0;
462 				values[1] = 0.0;
463 
464 				if (control->mix_control.master == EMU_MULTI_CONTROL_MASTERID)
465 					values[0] = mmvi->values[i].u.gain;
466 				else
467 					values[1] = mmvi->values[i].u.gain;
468 
469 				if (control2 && control2->mix_control.master != EMU_MULTI_CONTROL_MASTERID)
470 					values[1] = mmvi->values[i+1].u.gain;
471 
472 				control->set(card, control->cookie, control->type, values);
473 			}
474 
475 			if (control2)
476 				i++;
477 		}
478 
479 		if (control->mix_control.flags & B_MULTI_MIX_ENABLE && control->set) {
480 			float values[1];
481 
482 			values[0] = mmvi->values[i].u.enable ? 1.0 : 0.0;
483 			control->set(card, control->cookie, control->type, values);
484 		}
485 
486 		if (control->mix_control.flags & B_MULTI_MIX_MUX && control->set) {
487 			float values[1];
488 
489 			values[0] = (float)mmvi->values[i].u.mux;
490 			control->set(card, control->cookie, control->type, values);
491 		}
492 	}
493 	return B_OK;
494 }
495 
496 
497 static status_t
498 auich_list_mix_controls(auich_dev *card, multi_mix_control_info * mmci)
499 {
500 	multi_mix_control	*mmc;
501 	int32 i;
502 
503 	mmc = mmci->controls;
504 	if (mmci->control_count < 24)
505 		return B_ERROR;
506 
507 	if (auich_create_controls_list(&card->multi) < B_OK)
508 		return B_ERROR;
509 	for (i = 0; i < card->multi.control_count; i++) {
510 		mmc[i] = card->multi.controls[i].mix_control;
511 	}
512 
513 	mmci->control_count = card->multi.control_count;
514 	return B_OK;
515 }
516 
517 
518 static status_t
519 auich_list_mix_connections(auich_dev *card, multi_mix_connection_info * data)
520 {
521 	return B_ERROR;
522 }
523 
524 
525 static status_t
526 auich_list_mix_channels(auich_dev *card, multi_mix_channel_info *data)
527 {
528 	return B_ERROR;
529 }
530 
531 /*multi_channel_info chans[] = {
532 {  0, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
533 {  1, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
534 {  2, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
535 {  3, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
536 {  4, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
537 {  5, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
538 {  6, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
539 {  7, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
540 {  8, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
541 {  9, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
542 {  10, B_MULTI_INPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
543 {  11, B_MULTI_INPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
544 };*/
545 
546 /*multi_channel_info chans[] = {
547 {  0, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
548 {  1, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
549 {  2, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_SURROUND_BUS, 0 },
550 {  3, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_SURROUND_BUS, 0 },
551 {  4, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_REARLEFT | B_CHANNEL_SURROUND_BUS, 0 },
552 {  5, B_MULTI_OUTPUT_CHANNEL, 	B_CHANNEL_REARRIGHT | B_CHANNEL_SURROUND_BUS, 0 },
553 {  6, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
554 {  7, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
555 {  8, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 0 },
556 {  9, B_MULTI_INPUT_CHANNEL, 	B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, 0 },
557 {  10, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
558 {  11, B_MULTI_OUTPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
559 {  12, B_MULTI_INPUT_BUS, 		B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS, 	B_CHANNEL_MINI_JACK_STEREO },
560 {  13, B_MULTI_INPUT_BUS, 		B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS, B_CHANNEL_MINI_JACK_STEREO },
561 };*/
562 
563 
564 static void
565 auich_create_channels_list(multi_dev *multi)
566 {
567 	auich_stream *stream;
568 	uint32 index, i, mode, designations;
569 	multi_channel_info *chans;
570 	uint32 chan_designations[] = {
571 		B_CHANNEL_LEFT,
572 		B_CHANNEL_RIGHT,
573 		B_CHANNEL_REARLEFT,
574 		B_CHANNEL_REARRIGHT,
575 		B_CHANNEL_CENTER,
576 		B_CHANNEL_SUB
577 	};
578 
579 	chans = multi->chans;
580 	index = 0;
581 
582 	for (mode=AUICH_USE_PLAY; mode!=-1;
583 		mode = (mode == AUICH_USE_PLAY) ? AUICH_USE_RECORD : -1) {
584 		LIST_FOREACH(stream, &((auich_dev*)multi->card)->streams, next) {
585 			if ((stream->use & mode) == 0)
586 				continue;
587 
588 			if (stream->channels == 2)
589 				designations = B_CHANNEL_STEREO_BUS;
590 			else
591 				designations = B_CHANNEL_SURROUND_BUS;
592 
593 			for (i = 0; i < stream->channels; i++) {
594 				chans[index].channel_id = index;
595 				chans[index].kind = (mode == AUICH_USE_PLAY) ? B_MULTI_OUTPUT_CHANNEL : B_MULTI_INPUT_CHANNEL;
596 				chans[index].designations = designations | chan_designations[i];
597 				chans[index].connectors = 0;
598 				index++;
599 			}
600 		}
601 
602 		if (mode==AUICH_USE_PLAY) {
603 			multi->output_channel_count = index;
604 		} else {
605 			multi->input_channel_count = index - multi->output_channel_count;
606 		}
607 	}
608 
609 	chans[index].channel_id = index;
610 	chans[index].kind = B_MULTI_OUTPUT_BUS;
611 	chans[index].designations = B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS;
612 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
613 	index++;
614 
615 	chans[index].channel_id = index;
616 	chans[index].kind = B_MULTI_OUTPUT_BUS;
617 	chans[index].designations = B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS;
618 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
619 	index++;
620 
621 	multi->output_bus_channel_count = index - multi->output_channel_count
622 		- multi->input_channel_count;
623 
624 	chans[index].channel_id = index;
625 	chans[index].kind = B_MULTI_INPUT_BUS;
626 	chans[index].designations = B_CHANNEL_LEFT | B_CHANNEL_STEREO_BUS;
627 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
628 	index++;
629 
630 	chans[index].channel_id = index;
631 	chans[index].kind = B_MULTI_INPUT_BUS;
632 	chans[index].designations = B_CHANNEL_RIGHT | B_CHANNEL_STEREO_BUS;
633 	chans[index].connectors = B_CHANNEL_MINI_JACK_STEREO;
634 	index++;
635 
636 	multi->input_bus_channel_count = index - multi->output_channel_count
637 		- multi->input_channel_count - multi->output_bus_channel_count;
638 
639 	multi->aux_bus_channel_count = 0;
640 }
641 
642 
643 static status_t
644 auich_get_description(auich_dev *card, multi_description *data)
645 {
646 	uint32 size;
647 
648 	data->interface_version = B_CURRENT_INTERFACE_VERSION;
649 	data->interface_minimum = B_CURRENT_INTERFACE_VERSION;
650 
651 	switch(card->info.vendor_id) {
652 		case INTEL_VENDOR_ID:
653 			strncpy(data->friendly_name, FRIENDLY_NAME_ICH, 32);
654 		break;
655 		case SIS_VENDOR_ID:
656 			strncpy(data->friendly_name, FRIENDLY_NAME_SIS, 32);
657 		break;
658 		case NVIDIA_VENDOR_ID:
659 			strncpy(data->friendly_name, FRIENDLY_NAME_NVIDIA, 32);
660 		break;
661 		case AMD_VENDOR_ID:
662 			strncpy(data->friendly_name, FRIENDLY_NAME_AMD, 32);
663 		break;
664 	}
665 
666 	strcpy(data->vendor_info, AUTHOR);
667 
668 	/*data->output_channel_count = 6;
669 	data->input_channel_count = 4;
670 	data->output_bus_channel_count = 2;
671 	data->input_bus_channel_count = 2;
672 	data->aux_bus_channel_count = 0;*/
673 
674 	data->output_channel_count = card->multi.output_channel_count;
675 	data->input_channel_count = card->multi.input_channel_count;
676 	data->output_bus_channel_count = card->multi.output_bus_channel_count;
677 	data->input_bus_channel_count = card->multi.input_bus_channel_count;
678 	data->aux_bus_channel_count = card->multi.aux_bus_channel_count;
679 
680 	size = card->multi.output_channel_count + card->multi.input_channel_count
681 			+ card->multi.output_bus_channel_count + card->multi.input_bus_channel_count
682 			+ card->multi.aux_bus_channel_count;
683 
684 	// for each channel, starting with the first output channel,
685 	// then the second, third..., followed by the first input
686 	// channel, second, third, ..., followed by output bus
687 	// channels and input bus channels and finally auxillary channels,
688 
689 	LOG(("request_channel_count = %d\n",data->request_channel_count));
690 	if (data->request_channel_count >= size) {
691 		LOG(("copying data\n"));
692 		memcpy(data->channels, card->multi.chans, size * sizeof(card->multi.chans[0]));
693 	}
694 
695 	switch (current_settings.sample_rate) {
696 		case 48000: data->output_rates = data->input_rates = B_SR_48000; break;
697 		case 44100: data->output_rates = data->input_rates = B_SR_44100; break;
698 	}
699 	data->min_cvsr_rate = 0;
700 	data->max_cvsr_rate = 48000;
701 
702 	data->output_formats = B_FMT_16BIT;
703 	data->input_formats = B_FMT_16BIT;
704 	data->lock_sources = B_MULTI_LOCK_INTERNAL;
705 	data->timecode_sources = 0;
706 	data->interface_flags = B_MULTI_INTERFACE_PLAYBACK | B_MULTI_INTERFACE_RECORD;
707 	data->start_latency = 3000;
708 
709 	strcpy(data->control_panel,"");
710 
711 	return B_OK;
712 }
713 
714 
715 static status_t
716 auich_get_enabled_channels(auich_dev *card, multi_channel_enable *data)
717 {
718 	B_SET_CHANNEL(data->enable_bits, 0, true);
719 	B_SET_CHANNEL(data->enable_bits, 1, true);
720 	B_SET_CHANNEL(data->enable_bits, 2, true);
721 	B_SET_CHANNEL(data->enable_bits, 3, true);
722 	data->lock_source = B_MULTI_LOCK_INTERNAL;
723 /*
724 	uint32			lock_source;
725 	int32			lock_data;
726 	uint32			timecode_source;
727 	uint32 *		connectors;
728 */
729 	return B_OK;
730 }
731 
732 
733 static status_t
734 auich_get_global_format(auich_dev *card, multi_format_info *data)
735 {
736 	data->output_latency = 0;
737 	data->input_latency = 0;
738 	data->timecode_kind = 0;
739 	switch (current_settings.sample_rate) {
740 		case 48000:
741 			data->input.rate = data->output.rate = B_SR_48000;
742 			data->input.cvsr = data->output.cvsr = 48000;
743 			break;
744 		case 44100:
745 			data->input.rate = data->output.rate = B_SR_44100;
746 			data->input.cvsr = data->output.cvsr = 44100;
747 			break;
748 	}
749 	data->input.format = data->output.format = B_FMT_16BIT;
750 	return B_OK;
751 }
752 
753 
754 static status_t
755 auich_set_global_format(auich_dev *card, multi_format_info* data)
756 {
757 	// TODO: it looks like we're not supposed to fail; fix this!
758 	return B_OK;
759 }
760 
761 
762 static status_t
763 auich_get_buffers(auich_dev *card, multi_buffer_list *data)
764 {
765 	uint8 i, j, pchannels, rchannels, bufcount;
766 
767 	LOG(("flags = %#x\n",data->flags));
768 	LOG(("request_playback_buffers = %#x\n",data->request_playback_buffers));
769 	LOG(("request_playback_channels = %#x\n",data->request_playback_channels));
770 	LOG(("request_playback_buffer_size = %#x\n",data->request_playback_buffer_size));
771 	LOG(("request_record_buffers = %#x\n",data->request_record_buffers));
772 	LOG(("request_record_channels = %#x\n",data->request_record_channels));
773 	LOG(("request_record_buffer_size = %#x\n",data->request_record_buffer_size));
774 
775 	pchannels = card->pstream->channels;
776 	rchannels = card->rstream->channels;
777 
778 	if (data->request_playback_buffers < current_settings.buffer_count ||
779 		data->request_playback_channels < (pchannels) ||
780 		data->request_record_buffers < current_settings.buffer_count ||
781 		data->request_record_channels < (rchannels)) {
782 		LOG(("not enough channels/buffers\n"));
783 	}
784 
785 	ASSERT(current_settings.buffer_count == 2);
786 
787 	data->flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD; // XXX ???
788 //	data->flags = 0;
789 
790 	data->return_playback_buffers = current_settings.buffer_count;	/* playback_buffers[b][] */
791 	data->return_playback_channels = pchannels;		/* playback_buffers[][c] */
792 	data->return_playback_buffer_size = current_settings.buffer_frames;		/* frames */
793 
794 	bufcount = current_settings.buffer_count;
795 	if (bufcount > data->request_playback_buffers)
796 		bufcount = data->request_playback_buffers;
797 
798 	for (i = 0; i < bufcount; i++) {
799 		struct buffer_desc descs[data->return_playback_channels];
800 		for (j=0; j<pchannels; j++)
801 			auich_stream_get_nth_buffer(card->pstream, j, i,
802 				&descs[j].base,
803 				&descs[j].stride);
804 		if (!IS_USER_ADDRESS(data->playback_buffers[i])
805 			|| user_memcpy(data->playback_buffers[i], descs, sizeof(descs))
806 			< B_OK) {
807 			return B_BAD_ADDRESS;
808 		}
809 	}
810 	data->return_record_buffers = current_settings.buffer_count;
811 	data->return_record_channels = rchannels;
812 	data->return_record_buffer_size = current_settings.buffer_frames;	/* frames */
813 
814 	bufcount = current_settings.buffer_count;
815 	if (bufcount > data->request_record_buffers)
816 		bufcount = data->request_record_buffers;
817 
818 	for (i = 0; i < bufcount; i++) {
819 		struct buffer_desc descs[data->return_record_channels];
820 		for (j=0; j<rchannels; j++)
821 			auich_stream_get_nth_buffer(card->rstream, j, i,
822 				&descs[j].base,
823 				&descs[j].stride);
824 		if (!IS_USER_ADDRESS(data->record_buffers[i])
825 			|| user_memcpy(data->record_buffers[i], descs, sizeof(descs))
826 			< B_OK) {
827 			return B_BAD_ADDRESS;
828 		}
829 	}
830 	return B_OK;
831 }
832 
833 
834 static void
835 auich_play_inth(void* inthparams)
836 {
837 	auich_stream *stream = (auich_stream *)inthparams;
838 	//int32 count;
839 
840 	acquire_spinlock(&slock);
841 	stream->real_time = system_time();
842 	stream->frames_count += current_settings.buffer_frames;
843 	stream->buffer_cycle = (stream->trigblk
844 		+ stream->blkmod - 1) % stream->blkmod;
845 	stream->update_needed = true;
846 	release_spinlock(&slock);
847 
848 	TRACE(("auich_play_inth : cycle : %d\n", stream->buffer_cycle));
849 
850 	//get_sem_count(stream->card->buffer_ready_sem, &count);
851 	//if (count <= 0)
852 		release_sem_etc(stream->card->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE);
853 }
854 
855 
856 static void
857 auich_record_inth(void* inthparams)
858 {
859 	auich_stream *stream = (auich_stream *)inthparams;
860 	//int32 count;
861 
862 	acquire_spinlock(&slock);
863 	stream->real_time = system_time();
864 	stream->frames_count += current_settings.buffer_frames;
865 	stream->buffer_cycle = (stream->trigblk
866 		+ stream->blkmod - 1) % stream->blkmod;
867 	stream->update_needed = true;
868 	release_spinlock(&slock);
869 
870 	TRACE(("auich_record_inth : cycle : %d\n", stream->buffer_cycle));
871 
872 	//get_sem_count(stream->card->buffer_ready_sem, &count);
873 	//if (count <= 0)
874 		release_sem_etc(stream->card->buffer_ready_sem, 1, B_DO_NOT_RESCHEDULE);
875 }
876 
877 
878 static status_t
879 auich_buffer_exchange(auich_dev *card, multi_buffer_info *data)
880 {
881 	cpu_status status;
882 	auich_stream *pstream, *rstream;
883 	multi_buffer_info buffer_info;
884 
885 #ifdef __HAIKU__
886 	if (user_memcpy(&buffer_info, data, sizeof(buffer_info)) < B_OK)
887 		return B_BAD_ADDRESS;
888 #else
889 	memcpy(&buffer_info, data, sizeof(buffer_info));
890 #endif
891 
892 	buffer_info.flags = B_MULTI_BUFFER_PLAYBACK | B_MULTI_BUFFER_RECORD;
893 
894 	if (!(card->pstream->state & AUICH_STATE_STARTED))
895 		auich_stream_start(card->pstream, auich_play_inth, card->pstream);
896 
897 	if (!(card->rstream->state & AUICH_STATE_STARTED))
898 		auich_stream_start(card->rstream, auich_record_inth, card->rstream);
899 
900 	if (acquire_sem_etc(card->buffer_ready_sem, 1, B_RELATIVE_TIMEOUT | B_CAN_INTERRUPT, 50000)
901 		== B_TIMED_OUT) {
902 		LOG(("buffer_exchange timeout ff\n"));
903 	}
904 
905 	status = lock();
906 
907 	LIST_FOREACH(pstream, &card->streams, next) {
908 		if ((pstream->use & AUICH_USE_PLAY) == 0 ||
909 			(pstream->state & AUICH_STATE_STARTED) == 0)
910 			continue;
911 		if (pstream->update_needed)
912 			break;
913 	}
914 
915 	LIST_FOREACH(rstream, &card->streams, next) {
916 		if ((rstream->use & AUICH_USE_RECORD) == 0 ||
917 			(rstream->state & AUICH_STATE_STARTED) == 0)
918 			continue;
919 		if (rstream->update_needed)
920 			break;
921 	}
922 
923 	if (!pstream)
924 		pstream = card->pstream;
925 	if (!rstream)
926 		rstream = card->rstream;
927 
928 	/* do playback */
929 	buffer_info.playback_buffer_cycle = pstream->buffer_cycle;
930 	buffer_info.played_real_time = pstream->real_time;
931 	buffer_info.played_frames_count = pstream->frames_count;
932 	buffer_info._reserved_0 = pstream->first_channel;
933 	pstream->update_needed = false;
934 
935 	/* do record */
936 	buffer_info.record_buffer_cycle = rstream->buffer_cycle;
937 	buffer_info.recorded_frames_count = rstream->frames_count;
938 	buffer_info.recorded_real_time = rstream->real_time;
939 	buffer_info._reserved_1 = rstream->first_channel;
940 	rstream->update_needed = false;
941 	unlock(status);
942 
943 #ifdef __HAIKU__
944 	if (user_memcpy(data, &buffer_info, sizeof(buffer_info)) < B_OK)
945 		return B_BAD_ADDRESS;
946 #else
947 	memcpy(data, &buffer_info, sizeof(buffer_info));
948 #endif
949 
950 	//TRACE(("buffer_exchange ended\n"));
951 	return B_OK;
952 }
953 
954 
955 static status_t
956 auich_buffer_force_stop(auich_dev *card)
957 {
958 	//auich_voice_halt(card->pvoice);
959 	return B_OK;
960 }
961 
962 
963 #define cookie_type auich_dev
964 #define get_description auich_get_description
965 #define get_enabled_channels auich_get_enabled_channels
966 #define get_global_format auich_get_global_format
967 #define set_global_format auich_set_global_format
968 #define list_mix_channels auich_list_mix_channels
969 #define list_mix_controls auich_list_mix_controls
970 #define list_mix_connections auich_list_mix_connections
971 #define get_mix auich_get_mix
972 #define set_mix auich_set_mix
973 #define get_buffers auich_get_buffers
974 #define buffer_exchange auich_buffer_exchange
975 #define buffer_force_stop auich_buffer_force_stop
976 #include "../generic/multi.c"
977 
978 
979 static status_t
980 auich_multi_control(void *cookie, uint32 op, void *arg, size_t length)
981 {
982 	auich_dev *card = (auich_dev *)cookie;
983 
984 	return multi_audio_control_generic(card, op, arg, length);
985 }
986 
987 static status_t auich_open(const char *name, uint32 flags, void** cookie);
988 static status_t auich_close(void* cookie);
989 static status_t auich_free(void* cookie);
990 static status_t auich_control(void* cookie, uint32 op, void* arg, size_t len);
991 static status_t auich_read(void* cookie, off_t position, void *buf, size_t* num_bytes);
992 static status_t auich_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes);
993 
994 device_hooks multi_hooks = {
995 	auich_open, 			/* -> open entry point */
996 	auich_close, 			/* -> close entry point */
997 	auich_free,			/* -> free cookie */
998 	auich_control, 		/* -> control entry point */
999 	auich_read,			/* -> read entry point */
1000 	auich_write,			/* -> write entry point */
1001 	NULL,					/* start select */
1002 	NULL,					/* stop select */
1003 	NULL,					/* scatter-gather read from the device */
1004 	NULL					/* scatter-gather write to the device */
1005 };
1006 
1007 
1008 static status_t
1009 auich_open(const char *name, uint32 flags, void** cookie)
1010 {
1011 	auich_dev *card = NULL;
1012 	void *settings_handle;
1013 	int ix;
1014 
1015 	LOG(("open()\n"));
1016 
1017 	for (ix=0; ix<num_cards; ix++) {
1018 		if (!strcmp(cards[ix].name, name)) {
1019 			card = &cards[ix];
1020 		}
1021 	}
1022 
1023 	if (card == NULL) {
1024 		LOG(("open() card not found %s\n", name));
1025 		for (ix=0; ix<num_cards; ix++) {
1026 			LOG(("open() card available %s\n", cards[ix].name));
1027 		}
1028 		return B_ERROR;
1029 	}
1030 
1031 	LOG(("open() got card\n"));
1032 
1033 	if (card->pstream !=NULL)
1034 		return B_ERROR;
1035 	if (card->rstream !=NULL)
1036 		return B_ERROR;
1037 
1038 	*cookie = card;
1039 	card->multi.card = card;
1040 
1041 	// get driver settings
1042 	settings_handle = load_driver_settings(AUICH_SETTINGS);
1043 	if (settings_handle != NULL) {
1044 		const char *item;
1045 		char       *end;
1046 		uint32      value;
1047 
1048 		item = get_driver_parameter (settings_handle, "sample_rate", "48000", "48000");
1049 		value = strtoul (item, &end, 0);
1050 		if (*end == '\0')
1051 			current_settings.sample_rate = value;
1052 
1053 		item = get_driver_parameter (settings_handle, "buffer_frames", "256", "256");
1054 		value = strtoul (item, &end, 0);
1055 		if (*end == '\0')
1056 			current_settings.buffer_frames = value;
1057 
1058 		item = get_driver_parameter (settings_handle, "buffer_count", "4", "4");
1059 		value = strtoul (item, &end, 0);
1060 		if (*end == '\0')
1061 			current_settings.buffer_count = value;
1062 
1063 		unload_driver_settings(settings_handle);
1064 	}
1065 
1066 	LOG(("stream_new\n"));
1067 
1068 	card->rstream = auich_stream_new(card, AUICH_USE_RECORD, current_settings.buffer_frames, current_settings.buffer_count);
1069 	card->pstream = auich_stream_new(card, AUICH_USE_PLAY, current_settings.buffer_frames, current_settings.buffer_count);
1070 
1071 	card->buffer_ready_sem = create_sem(0, "pbuffer ready");
1072 
1073 	LOG(("stream_setaudio\n"));
1074 
1075 	auich_stream_set_audioparms(card->pstream, 2, true, current_settings.sample_rate);
1076 	auich_stream_set_audioparms(card->rstream, 2, true, current_settings.sample_rate);
1077 
1078 	card->pstream->first_channel = 0;
1079 	card->rstream->first_channel = 2;
1080 
1081 	auich_stream_commit_parms(card->pstream);
1082 	auich_stream_commit_parms(card->rstream);
1083 
1084 	auich_create_channels_list(&card->multi);
1085 
1086 	return B_OK;
1087 }
1088 
1089 
1090 static status_t
1091 auich_close(void* cookie)
1092 {
1093 	//auich_dev *card = cookie;
1094 	LOG(("close()\n"));
1095 
1096 	return B_OK;
1097 }
1098 
1099 
1100 static status_t
1101 auich_free(void* cookie)
1102 {
1103 	auich_dev *card = cookie;
1104 	auich_stream *stream;
1105 	LOG(("free()\n"));
1106 
1107 	if (card->buffer_ready_sem > B_OK)
1108 			delete_sem(card->buffer_ready_sem);
1109 
1110 	LIST_FOREACH(stream, &card->streams, next) {
1111 		auich_stream_halt(stream);
1112 	}
1113 
1114 	while (!LIST_EMPTY(&card->streams)) {
1115 		auich_stream_delete(LIST_FIRST(&card->streams));
1116 	}
1117 
1118 	card->pstream = NULL;
1119 	card->rstream = NULL;
1120 
1121 	return B_OK;
1122 }
1123 
1124 
1125 static status_t
1126 auich_control(void* cookie, uint32 op, void* arg, size_t len)
1127 {
1128 	return auich_multi_control(cookie, op, arg, len);
1129 }
1130 
1131 
1132 static status_t
1133 auich_read(void* cookie, off_t position, void *buf, size_t* num_bytes)
1134 {
1135 	*num_bytes = 0;				/* tell caller nothing was read */
1136 	return B_IO_ERROR;
1137 }
1138 
1139 
1140 static status_t
1141 auich_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
1142 {
1143 	*num_bytes = 0;				/* tell caller nothing was written */
1144 	return B_IO_ERROR;
1145 }
1146