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