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