Ticket #1217: alsa.patch
File alsa.patch, 4.0 KB (added by , 20 years ago) |
---|
-
libs/libmyth/audiooutputalsa.cpp
450 450 451 451 int AudioOutputALSA::GetVolumeChannel(int channel) 452 452 { 453 snd_mixer_selem_id_t *sid; 454 snd_mixer_elem_t *elem; 453 455 long actual_volume, volume; 454 456 455 457 if (mixer_handle == NULL) … … 461 463 462 464 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 463 465 { 464 Error(QString("mixer unable to find control %1").arg(mixer_control)); 465 CloseMixer(); 466 return 0; 466 VERBOSE(VB_IMPORTANT, QString("mixer unable to find control %1").arg(mixer_control)); 467 return 100; 467 468 } 468 469 469 GetVolumeRange(); 470 if (!snd_mixer_selem_has_playback_channel(elem, (snd_mixer_selem_channel_id_t)channel)) 471 { 472 snd_mixer_selem_id_set_index(sid, channel); 473 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 474 { 475 VERBOSE(VB_IMPORTANT, QString("mixer unable to find control %1 %2").arg(mixer_control).arg(channel)); 476 return 100; 477 } 478 } 470 479 480 GetVolumeRange(elem); 481 471 482 snd_mixer_selem_get_playback_volume(elem, (snd_mixer_selem_channel_id_t)channel, 472 483 &actual_volume); 473 484 volume = (int)((actual_volume - playback_vol_min) * … … 482 493 483 494 void AudioOutputALSA::SetCurrentVolume(QString control, int channel, int volume) 484 495 { 496 snd_mixer_selem_id_t *sid; 497 snd_mixer_elem_t *elem; 485 498 int err, set_vol; 486 499 487 500 VERBOSE(VB_AUDIO, QString("Setting %1 volume to %2") … … 495 508 496 509 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 497 510 { 498 Error(QString("mixer unable to find control %1").arg(control));511 VERBOSE(VB_IMPORTANT, QString("mixer unable to find control %1").arg(control)); 499 512 return; 500 513 } 501 514 502 GetVolumeRange(); 515 if (!snd_mixer_selem_has_playback_channel(elem, (snd_mixer_selem_channel_id_t)channel)) 516 { 517 snd_mixer_selem_id_set_index(sid, channel); 518 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 519 { 520 VERBOSE(VB_IMPORTANT, QString("mixer unable to find control %1 %2").arg(control).arg(channel)); 521 return; 522 } 523 } 503 524 525 GetVolumeRange(elem); 526 504 527 set_vol = (int)(volume / volume_range_multiplier + 505 528 playback_vol_min + 0.5); 506 529 507 530 if ((err = snd_mixer_selem_set_playback_volume(elem, 508 531 (snd_mixer_selem_channel_id_t)channel, set_vol)) < 0) 509 532 { 510 Error(QString("mixer set channel %1 err %2: %3")533 VERBOSE(VB_IMPORTANT, QString("mixer set channel %1 err %2: %3") 511 534 .arg(channel).arg(err).arg(snd_strerror(err))); 512 535 return; 513 536 } … … 558 581 559 582 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 560 583 561 // TODO: This is opening card 0. Fix for case of multiple soundcards562 584 if ((err = snd_mixer_open(&mixer_handle, 0)) < 0) 563 585 { 564 586 Error(QString("Mixer device open error %1: %2") … … 592 614 } 593 615 } 594 616 595 inline void AudioOutputALSA::GetVolumeRange( void)617 inline void AudioOutputALSA::GetVolumeRange(snd_mixer_elem_t *elem) 596 618 { 597 619 snd_mixer_selem_get_playback_volume_range(elem, &playback_vol_min, 598 620 &playback_vol_max); -
libs/libmyth/audiooutputalsa.h
53 53 void OpenMixer(bool setstartingvolume); 54 54 void CloseMixer(void); 55 55 void SetupMixer(void); 56 inline void GetVolumeRange( void);56 inline void GetVolumeRange(snd_mixer_elem_t *elem); 57 57 58 58 snd_mixer_t *mixer_handle; 59 snd_mixer_elem_t *elem;60 snd_mixer_selem_id_t *sid;61 59 62 60 QString mixer_control; // e.g. "PCM" 63 61