Ticket #6279: sofvol-trunk-6.patch
File sofvol-trunk-6.patch, 10.9 KB (added by , 15 years ago) |
---|
-
libs/libmyth/audiooutputalsa.cpp
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputalsa.cpp mythtv/libs/libmyth/audiooutputalsa.cpp
old new 780 780 if (mixer_handle != NULL) 781 781 CloseMixer(); 782 782 783 if (alsadevice.toLower() == "software") 784 return; 785 783 786 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 784 787 785 788 // TODO: This is opening card 0. Fix for case of multiple soundcards -
libs/libmyth/audiooutputbase.cpp
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputbase.cpp mythtv/libs/libmyth/audiooutputbase.cpp
old new 1 1 // Std C headers 2 2 #include <cmath> 3 #include <limits> 3 4 4 5 // POSIX headers 5 6 #include <unistd.h> … … 53 54 needs_upmix(false), 54 55 surround_mode(FreeSurround::SurroundModePassive), 55 56 old_audio_stretchfactor(1.0), 57 volume(80), 56 58 57 59 blocking(false), 58 60 … … 335 337 return; 336 338 } 337 339 340 // Only used for software volume 341 if (set_initial_vol && internal_vol) 342 volume = gContext->GetNumSetting("PCMMixerVolume", 80); 343 { 344 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 345 controlLabel += "MixerVolume"; 346 volume = gContext->GetNumSetting(controlLabel, 80); 347 } 348 338 349 SyncVolume(); 339 350 340 351 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") … … 628 639 return audbuf_timecode - GetAudiotime(); 629 640 } 630 641 642 void AudioOutputBase::SetSWVolume(int new_volume, bool save) 643 { 644 volume = new_volume; 645 if (save) 646 { 647 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 648 controlLabel += "MixerVolume"; 649 gContext->SaveSetting(controlLabel, volume); 650 } 651 } 652 653 int AudioOutputBase::GetSWVolume() 654 { 655 return volume; 656 } 657 658 template <class AudioDataType> 659 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 660 { 661 float g = volume / 100.0; 662 663 // Should probably be exponential - this'll do 664 g *= g; 665 666 // Add gain to AC-3 - try to ~ match PCM volume 667 if (audio_enc && audio_reenc) 668 g *= 1.8; 669 670 // Music is relatively loud - ditto 671 else if (music) 672 g *= 0.4; 673 674 if (g == 1.0) 675 return; 676 677 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 678 { 679 float s = static_cast<float>(buffer[i]) * g / 680 static_cast<float>(numeric_limits<AudioDataType>::max()); 681 if (s >= 1.0) 682 buffer[i] = numeric_limits<AudioDataType>::max(); 683 else if (s <= -1.0) 684 buffer[i] = numeric_limits<AudioDataType>::min(); 685 else 686 buffer[i] = static_cast<AudioDataType> 687 (s * numeric_limits<AudioDataType>::max()); 688 } 689 } 690 691 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) 692 { 693 if (audio_bits == 8) 694 _AdjustVolume<char>((char *)buffer, len, music); 695 else if (audio_bits == 16) 696 _AdjustVolume<short>((short *)buffer, len, music); 697 } 698 631 699 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 632 700 long long timecode) 633 701 { … … 969 1037 } 970 1038 } 971 1039 1040 if (internal_vol && SWVolume()) 1041 { 1042 int bdiff = kAudioRingBufferSize - waud; 1043 bool music = (timecode < 1); 1044 1045 if (bdiff < len) 1046 { 1047 AdjustVolume(audiobuffer + waud, bdiff, music); 1048 AdjustVolume(audiobuffer, len - bdiff, music); 1049 } 1050 else 1051 AdjustVolume(audiobuffer + waud, len, music); 1052 } 1053 972 1054 // Encode to AC-3? 973 1055 if (encoder) 974 1056 { -
libs/libmyth/audiooutputbase.h
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputbase.h mythtv/libs/libmyth/audiooutputbase.h
old new 47 47 48 48 virtual void Reset(void); 49 49 50 void SetSWVolume(int new_volume, bool save); 51 int GetSWVolume(void); 52 50 53 // timecode is in milliseconds. 51 54 virtual bool AddSamples(char *buffer, int samples, long long timecode); 52 55 virtual bool AddSamples(char *buffers[], int samples, long long timecode); … … 153 156 int src_quality; 154 157 155 158 private: 159 // software volume 160 template <class AudioDataType> 161 void _AdjustVolume(AudioDataType *buffer, int len, bool music); 162 void AdjustVolume(void *buffer, int len, bool music); 163 156 164 // resampler 157 165 bool need_resampler; 158 166 SRC_STATE *src_ctx; … … 169 177 int surround_mode; 170 178 bool allow_ac3_passthru; 171 179 float old_audio_stretchfactor; 180 int volume; 172 181 173 182 bool blocking; // do AddSamples calls block? 174 183 -
libs/libmyth/audiooutputoss.cpp
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputoss.cpp mythtv/libs/libmyth/audiooutputoss.cpp
old new 317 317 int volume = 0; 318 318 319 319 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 320 if (device.toLower() == "software") 321 return; 322 320 323 QByteArray dev = device.toAscii(); 321 324 mixerfd = open(dev.constData(), O_RDONLY); 322 325 -
libs/libmyth/volumebase.cpp
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/volumebase.cpp mythtv/libs/libmyth/volumebase.cpp
old new 10 10 internal_vol(false), volume(80), 11 11 current_mute_state(kMuteOff) 12 12 { 13 swvol = swvol_setting = 14 (gContext->GetSetting("MixerDevice", "default").toLower() == "software"); 15 } 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; 13 27 } 14 28 15 29 uint VolumeBase::GetCurrentVolume(void) const … … 76 90 void VolumeBase::UpdateVolume(void) 77 91 { 78 92 int new_volume = volume; 93 bool save = true; 79 94 if (current_mute_state == kMuteAll) 80 95 { 81 96 new_volume = 0; 97 save = false; 98 } 99 100 if (swvol) 101 { 102 SetSWVolume(new_volume, save); 103 return; 82 104 } 83 105 84 106 // TODO: Avoid assumption that there are 2 channels! … … 102 124 void VolumeBase::SyncVolume(void) 103 125 { 104 126 // Read the volume from the audio driver and setup our internal state to match 105 volume = GetVolumeChannel(0); 127 if (swvol) 128 volume = GetSWVolume(); 129 else 130 volume = GetVolumeChannel(0); 106 131 } 107 132 -
libs/libmyth/volumebase.h
diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/volumebase.h mythtv/libs/libmyth/volumebase.h
old new 20 20 VolumeBase(); 21 21 virtual ~VolumeBase() {}; 22 22 23 void SWVolume(bool set); 24 bool SWVolume(void); 23 25 virtual uint GetCurrentVolume(void) const; 24 26 virtual void SetCurrentVolume(int value); 25 27 virtual void AdjustCurrentVolume(int change); … … 34 36 35 37 virtual int GetVolumeChannel(int channel) const = 0; // Returns 0-100 36 38 virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol 39 virtual void SetSWVolume(int new_volume, bool save) = 0; 40 virtual int GetSWVolume(void) = 0; 37 41 38 42 void UpdateVolume(void); 39 43 void SyncVolume(void); … … 44 48 45 49 int volume; 46 50 MuteState current_mute_state; 51 bool swvol; 52 bool swvol_setting; 47 53 48 54 }; 49 55 -
libs/libmythtv/avformatdecoder.cpp
diff -Naur --exclude=.svn mythtv.ori/libs/libmythtv/avformatdecoder.cpp mythtv/libs/libmythtv/avformatdecoder.cpp
old new 461 461 // Audio 462 462 audioSamples(NULL), 463 463 allow_ac3_passthru(false), allow_dts_passthru(false), 464 internal_vol(false), 464 465 disable_passthru(false), max_channels(2), 465 466 last_ac3_channels(0), dummy_frame(NULL), 466 467 // DVD … … 482 483 483 484 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false); 484 485 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 486 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 485 487 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 486 488 487 489 audioIn.sample_size = -32; // force SetupAudioStream to run once … … 4203 4205 4204 4206 if (ctx->codec_id == CODEC_ID_AC3) 4205 4207 passthru = allow_ac3_passthru && 4206 ctx->channels >= (int)max_channels; 4208 ctx->channels >= (int)max_channels && 4209 !internal_vol; 4207 4210 else if (ctx->codec_id == CODEC_ID_DTS) 4208 passthru = allow_dts_passthru ;4211 passthru = allow_dts_passthru && !internal_vol; 4209 4212 4210 4213 passthru &= !transcoding && !disable_passthru; 4211 4214 // Don't know any cards that support spdif clocked at < 44100 -
libs/libmythtv/avformatdecoder.h
diff -Naur --exclude=.svn mythtv.ori/libs/libmythtv/avformatdecoder.h mythtv/libs/libmythtv/avformatdecoder.h
old new 259 259 short int *audioSamples; 260 260 bool allow_ac3_passthru; 261 261 bool allow_dts_passthru; 262 bool internal_vol; 262 263 bool disable_passthru; 263 264 uint max_channels; 264 265 uint last_ac3_channels; -
programs/mythfrontend/globalsettings.cpp
diff -Naur --exclude=.svn mythtv.ori/programs/mythfrontend/globalsettings.cpp mythtv/programs/mythfrontend/globalsettings.cpp
old new 196 196 #ifdef USING_WINAUDIO 197 197 gc->addSelection("Windows:", "Windows:"); 198 198 #endif 199 #if !(defined(USING_DIRECTX) || defined(USING_WINAUDIO)) 200 gc->addSelection("software", "sofware"); 201 #endif 199 202 200 203 return gc; 201 204 } -
programs/mythtranscode/transcode.cpp
diff -Naur --exclude=.svn mythtv.ori/programs/mythtranscode/transcode.cpp mythtv/programs/mythtranscode/transcode.cpp
old new 228 228 return false; 229 229 } 230 230 231 virtual void SetSWVolume(int new_volume, bool save) 232 { 233 // Do nothing 234 return; 235 } 236 virtual int GetSWVolume(void) 237 { 238 // Do nothing 239 return 100; 240 } 241 231 242 // These are pure virtual in AudioOutput, but we don't need them here 232 243 virtual void bufferOutputData(bool){ return; } 233 244 virtual int readOutputData(unsigned char*, int ){ return 0; }