Ticket #6279: softvol-fixes-5.patch
File softvol-fixes-5.patch, 11.4 KB (added by , 15 years ago) |
---|
-
mythtv/libs/libmyth/audiooutputalsa.cpp
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp index dd5bad9..02b74c5 100644
a b void AudioOutputALSA::SetupMixer(void) 751 751 if (mixer_handle != NULL) 752 752 CloseMixer(); 753 753 754 if (alsadevice.lower() == "software") 755 return; 756 754 757 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 755 758 756 759 // TODO: This is opening card 0. Fix for case of multiple soundcards -
mythtv/libs/libmyth/audiooutputbase.cpp
diff --git a/mythtv/libs/libmyth/audiooutputbase.cpp b/mythtv/libs/libmyth/audiooutputbase.cpp index 2cb54ea..20d2bac 100644
a b AudioOutputBase::AudioOutputBase( 61 61 needs_upmix(false), 62 62 surround_mode(FreeSurround::SurroundModePassive), 63 63 old_audio_stretchfactor(1.0), 64 volume(80), 64 65 65 66 blocking(false), 66 67 … … void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 327 328 328 329 audio_bytes_per_sample = audio_channels * audio_bits / 8; 329 330 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; 331 332 if (internal_vol && audio_enc && audio_reenc) 333 { 334 VERBOSE(VB_AUDIO, LOC + "Using software vol control for AC-3"); 335 SWVolume(true); 336 } 337 else 338 SWVolume(false); 330 339 331 340 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4") 332 341 .arg(audio_main_device).arg(audio_channels) … … void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 343 352 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 344 353 return; 345 354 } 346 355 356 // Only used for software volume 357 if (set_initial_vol && internal_vol) 358 volume = gContext->GetNumSetting("PCMMixerVolume", 80); 359 347 360 SyncVolume(); 348 361 349 362 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") … … void AudioOutputBase::SetAudiotime(void) 651 664 pthread_mutex_unlock(&audio_buflock); 652 665 } 653 666 667 void AudioOutputBase::SetSWVolume(int new_volume, bool save) 668 { 669 volume = new_volume; 670 if (save) 671 { 672 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 673 controlLabel += "MixerVolume"; 674 gContext->SaveSetting(controlLabel, volume); 675 } 676 } 677 678 int AudioOutputBase::GetSWVolume() 679 { 680 return volume; 681 } 682 683 template <class AudioDataType> 684 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 685 { 686 float g = volume / 100.0; 687 688 // Should probably be exponential - this'll do 689 g *= g; 690 691 // Add gain to AC3 / DTS - try to ~ match PCM volume 692 if (audio_codec == CODEC_ID_AC3 || audio_codec == CODEC_ID_DTS) 693 g *= 1.8; 694 695 // Music is relatively loud - ditto 696 else if (music) 697 g *= 0.4; 698 699 if (g == 1.0) 700 return; 701 702 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 703 { 704 float s = static_cast<float>(buffer[i]) * g / 705 static_cast<float>(numeric_limits<AudioDataType>::max()); 706 if (s >= 1.0) 707 buffer[i] = numeric_limits<AudioDataType>::max(); 708 else if (s <= -1.0) 709 buffer[i] = numeric_limits<AudioDataType>::min(); 710 else 711 buffer[i] = static_cast<AudioDataType> 712 (s * numeric_limits<AudioDataType>::max()); 713 } 714 } 715 716 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) { 717 718 if (audio_bits == 8) 719 _AdjustVolume<char>((char *)buffer, len, music); 720 else if (audio_bits == 16) 721 _AdjustVolume<short>((short *)buffer, len, music); 722 723 } 724 654 725 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 655 726 long long timecode) 656 727 { … … void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 996 1067 997 1068 } 998 1069 1070 if (internal_vol && SWVolume()) 1071 { 1072 int bdiff = AUDBUFSIZE - waud; 1073 bool music = (timecode < 1); 1074 1075 if (bdiff < len) 1076 { 1077 AdjustVolume(audiobuffer + waud, bdiff, music); 1078 AdjustVolume(audiobuffer, len - bdiff, music); 1079 } 1080 else 1081 AdjustVolume(audiobuffer + waud, len, music); 1082 } 1083 999 1084 // Encode to AC-3? 1000 1085 if (encoder) 1001 1086 { -
mythtv/libs/libmyth/audiooutputbase.h
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h index bdf808c..acc2f43 100644
a b class AudioOutputBase : public AudioOutput 63 63 64 64 virtual void Reset(void); 65 65 66 void SetSWVolume(int new_volume, bool save); 67 int GetSWVolume(void); 68 66 69 // timecode is in milliseconds. 67 70 virtual bool AddSamples(char *buffer, int samples, long long timecode); 68 71 virtual bool AddSamples(char *buffers[], int samples, long long timecode); … … class AudioOutputBase : public AudioOutput 118 121 int audiofree(bool use_lock); // number of free bytes in audio buffer 119 122 120 123 void UpdateVolume(void); 121 124 122 125 void SetStretchFactorLocked(float factor); 123 126 124 127 int GetBaseAudioTime() const { return audiotime; } … … class AudioOutputBase : public AudioOutput 159 162 int src_quality; 160 163 161 164 private: 165 // software volume 166 template <class AudioDataType> 167 void _AdjustVolume(AudioDataType *buffer, int len, bool music); 168 void AdjustVolume(void *buffer, int len, bool music); 169 162 170 // resampler 163 171 bool need_resampler; 164 172 SRC_STATE *src_ctx; … … class AudioOutputBase : public AudioOutput 179 187 int surround_mode; 180 188 bool allow_ac3_passthru; 181 189 float old_audio_stretchfactor; 190 int volume; 182 191 183 192 bool blocking; // do AddSamples calls block? 184 193 -
mythtv/libs/libmyth/audiooutputoss.cpp
diff --git a/mythtv/libs/libmyth/audiooutputoss.cpp b/mythtv/libs/libmyth/audiooutputoss.cpp index 0f67c6a..2c98143 100644
a b void AudioOutputOSS::VolumeInit() 319 319 int volume = 0; 320 320 321 321 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 322 if (device.lower() == "software") 323 return; 322 324 mixerfd = open(device.ascii(), O_RDONLY); 323 325 324 326 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); -
mythtv/libs/libmyth/volumebase.cpp
diff --git a/mythtv/libs/libmyth/volumebase.cpp b/mythtv/libs/libmyth/volumebase.cpp index 6823bbc..2431ff2 100644
a b VolumeBase::VolumeBase() 10 10 volume = 80; 11 11 current_mute_state=MUTE_OFF; 12 12 internal_vol = false; 13 swvol = swvol_setting = 14 (gContext->GetSetting("MixerDevice", "default").lower() == "software"); 13 15 }; 14 16 17 bool VolumeBase::SWVolume(void) 18 { 19 return swvol; 20 } 21 22 void VolumeBase::SWVolume(bool set) 23 { 24 if (swvol_setting) 25 return; 26 swvol = set; 27 } 28 29 15 30 int VolumeBase::GetCurrentVolume(void) 16 31 { 17 32 return volume; … … kMuteState VolumeBase::IterateMutedChannels(void) 88 103 void VolumeBase::UpdateVolume(void) 89 104 { 90 105 int new_volume = volume; 106 bool save = true; 91 107 if (current_mute_state == MUTE_BOTH) 92 108 { 93 109 new_volume = 0; 110 save = false; 111 } 112 113 if (swvol) 114 { 115 SetSWVolume(new_volume, save); 116 return; 94 117 } 95 118 96 119 // TODO: Avoid assumption that there are 2 channels! … … void VolumeBase::UpdateVolume(void) 114 137 void VolumeBase::SyncVolume(void) 115 138 { 116 139 // Read the volume from the audio driver and setup our internal state to match 117 volume = GetVolumeChannel(0); 140 if (swvol) 141 volume = GetSWVolume(); 142 else 143 volume = GetVolumeChannel(0); 118 144 } 119 145 -
mythtv/libs/libmyth/volumebase.h
diff --git a/mythtv/libs/libmyth/volumebase.h b/mythtv/libs/libmyth/volumebase.h index f41a5d7..0601568 100644
a b class MPUBLIC VolumeBase 20 20 VolumeBase(); 21 21 virtual ~VolumeBase() {}; 22 22 23 void SWVolume(bool set); 24 bool SWVolume(void); 23 25 virtual int GetCurrentVolume(void); 24 26 virtual void SetCurrentVolume(int value); 25 27 virtual void AdjustCurrentVolume(int change); … … class MPUBLIC VolumeBase 32 34 33 35 virtual int GetVolumeChannel(int channel) = 0; // Returns 0-100 34 36 virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol 37 virtual void SetSWVolume(int new_volume, bool save) = 0; 38 virtual int GetSWVolume(void) = 0; 35 39 36 40 void UpdateVolume(void); 37 41 void SyncVolume(void); … … class MPUBLIC VolumeBase 42 46 43 47 int volume; 44 48 kMuteState current_mute_state; 49 bool swvol; 50 bool swvol_setting; 45 51 46 52 }; 47 53 -
mythtv/libs/libmythtv/avformatdecoder.cpp
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp index 972f0fd..75a152b 100644
a b AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 410 410 // Audio 411 411 audioSamples(new short int[AVCODEC_MAX_AUDIO_FRAME_SIZE]), 412 412 allow_ac3_passthru(false), allow_dts_passthru(false), 413 internal_vol(false), 413 414 disable_passthru(false), max_channels(2), 414 415 last_ac3_channels(0), dummy_frame(NULL), 415 416 // DVD … … AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 428 429 429 430 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false); 430 431 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 432 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 431 433 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 432 434 433 435 audioIn.sample_size = -32; // force SetupAudioStream to run once … … bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 3968 3970 3969 3971 if (ctx->codec_id == CODEC_ID_AC3) 3970 3972 passthru = allow_ac3_passthru && 3971 ctx->channels >= (int)max_channels; 3973 ctx->channels >= (int)max_channels && 3974 !internal_vol; 3972 3975 else if (ctx->codec_id == CODEC_ID_DTS) 3973 passthru = allow_dts_passthru ;3976 passthru = allow_dts_passthru && !internal_vol; 3974 3977 3975 3978 passthru &= !transcoding && !disable_passthru; 3976 3979 // Don't know any cards that support spdif clocked at < 44100 -
mythtv/libs/libmythtv/avformatdecoder.h
diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h index f008136..482ffe2 100644
a b class AvFormatDecoder : public DecoderBase 263 263 short int *audioSamples; 264 264 bool allow_ac3_passthru; 265 265 bool allow_dts_passthru; 266 bool internal_vol; 266 267 bool disable_passthru; 267 268 uint max_channels; 268 269 uint last_ac3_channels; -
mythtv/programs/mythtranscode/transcode.cpp
diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp index 653f9d4..64f6e8d 100644
a b class AudioReencodeBuffer : public AudioOutput 222 222 // Do nothing 223 223 return false; 224 224 } 225 virtual void SetSWVolume(int new_volume, bool save) 226 { 227 // Do nothing 228 return; 229 } 230 231 virtual int GetSWVolume(void) 232 { 233 // Do nothing 234 return 100; 235 } 225 236 226 237 // These are pure virtual in AudioOutput, but we don't need them here 227 238 virtual void bufferOutputData(bool){ return; }