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