Ticket #6279: softvol-trunk-5.patch
File softvol-trunk-5.patch, 11.1 KB (added by , 16 years ago) |
---|
-
mythtv/libs/libmyth/audiooutputalsa.cpp
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp index 788ae18..8ae7419 100644
a b void AudioOutputALSA::SetupMixer(void) 752 752 if (mixer_handle != NULL) 753 753 CloseMixer(); 754 754 755 if (alsadevice.toLower() == "software") 756 return; 757 755 758 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 756 759 757 760 // 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 63f90a4..6b2d085 100644
a b 1 1 // Std C headers 2 2 #include <cmath> 3 #include <limits> 3 4 4 5 // POSIX headers 5 6 #include <unistd.h> … … AudioOutputBase::AudioOutputBase(const AudioSettings &settings) : 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 … … void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings) 322 324 audio_bytes_per_sample = audio_channels * audio_bits / 8; 323 325 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; 324 326 325 326 327 VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4") 327 328 .arg(audio_main_device).arg(audio_channels) 328 329 .arg(source_audio_channels).arg(audio_samplerate)); … … void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings) 336 337 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 337 338 return; 338 339 } 339 340 341 // Only used for software volume 342 if (set_initial_vol && internal_vol) 343 volume = gContext->GetNumSetting("PCMMixerVolume", 80); 344 340 345 SyncVolume(); 341 346 342 347 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") … … int AudioOutputBase::GetAudioBufferedTime(void) 627 632 return audbuf_timecode - GetAudiotime(); 628 633 } 629 634 635 void AudioOutputBase::SetSWVolume(int new_volume, bool save) 636 { 637 volume = new_volume; 638 if (save) 639 { 640 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 641 controlLabel += "MixerVolume"; 642 gContext->SaveSetting(controlLabel, volume); 643 } 644 } 645 646 int AudioOutputBase::GetSWVolume() 647 { 648 return volume; 649 } 650 651 template <class AudioDataType> 652 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 653 { 654 float g = volume / 100.0; 655 656 // Should probably be exponential - this'll do 657 g *= g; 658 659 // Add gain to AC-3 - try to ~ match PCM volume 660 if (audio_enc && audio_reenc) 661 g *= 1.8; 662 663 // Music is relatively loud - ditto 664 else if (music) 665 g *= 0.4; 666 667 if (g == 1.0) 668 return; 669 670 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 671 { 672 float s = static_cast<float>(buffer[i]) * g / 673 static_cast<float>(numeric_limits<AudioDataType>::max()); 674 if (s >= 1.0) 675 buffer[i] = numeric_limits<AudioDataType>::max(); 676 else if (s <= -1.0) 677 buffer[i] = numeric_limits<AudioDataType>::min(); 678 else 679 buffer[i] = static_cast<AudioDataType> 680 (s * numeric_limits<AudioDataType>::max()); 681 } 682 } 683 684 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) { 685 686 if (audio_bits == 8) 687 _AdjustVolume<char>((char *)buffer, len, music); 688 else if (audio_bits == 16) 689 _AdjustVolume<short>((short *)buffer, len, music); 690 691 } 692 693 630 694 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 631 695 long long timecode) 632 696 { … … void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 970 1034 971 1035 } 972 1036 1037 if (internal_vol && SWVolume()) 1038 { 1039 int bdiff = kAudioRingBufferSize - waud; 1040 bool music = (timecode < 1); 1041 1042 if (bdiff < len) 1043 { 1044 AdjustVolume(audiobuffer + waud, bdiff, music); 1045 AdjustVolume(audiobuffer, len - bdiff, music); 1046 } 1047 else 1048 AdjustVolume(audiobuffer + waud, len, music); 1049 } 1050 973 1051 // Encode to AC-3? 974 1052 if (encoder) 975 1053 { -
mythtv/libs/libmyth/audiooutputbase.h
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h index 4bcaaa4..da4b0d7 100644
a b class AudioOutputBase : public AudioOutput, public QThread 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); … … class AudioOutputBase : public AudioOutput, public QThread 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; … … class AudioOutputBase : public AudioOutput, public QThread 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 -
mythtv/libs/libmyth/audiooutputoss.cpp
diff --git a/mythtv/libs/libmyth/audiooutputoss.cpp b/mythtv/libs/libmyth/audiooutputoss.cpp index 8d3b135..69f9f02 100644
a b void AudioOutputOSS::VolumeInit() 313 313 int volume = 0; 314 314 315 315 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 316 if (device.toLower() == "software") 317 return; 316 318 QByteArray dev = device.toAscii(); 317 319 mixerfd = open(dev.constData(), O_RDONLY); 318 320 -
mythtv/libs/libmyth/volumebase.cpp
diff --git a/mythtv/libs/libmyth/volumebase.cpp b/mythtv/libs/libmyth/volumebase.cpp index d1f1fb0..a6d053a 100644
a b VolumeBase::VolumeBase() : 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 … … MuteState VolumeBase::NextMuteState(MuteState cur) 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! … … void VolumeBase::UpdateVolume(void) 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 -
mythtv/libs/libmyth/volumebase.h
diff --git a/mythtv/libs/libmyth/volumebase.h b/mythtv/libs/libmyth/volumebase.h index 4257f0b..68fb6f1 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 uint GetCurrentVolume(void) const; 24 26 virtual void SetCurrentVolume(int value); 25 27 virtual void AdjustCurrentVolume(int change); … … class MPUBLIC VolumeBase 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); … … class MPUBLIC VolumeBase 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 -
mythtv/libs/libmythtv/avformatdecoder.cpp
diff --git a/mythtv/libs/libmythtv/avformatdecoder.cpp b/mythtv/libs/libmythtv/avformatdecoder.cpp index 4530bc4..dec51e3 100644
a b AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 443 443 // Audio 444 444 audioSamples(NULL), 445 445 allow_ac3_passthru(false), allow_dts_passthru(false), 446 internal_vol(false), 446 447 disable_passthru(false), max_channels(2), 447 448 last_ac3_channels(0), dummy_frame(NULL), 448 449 // DVD … … AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 464 465 465 466 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false); 466 467 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 468 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 467 469 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 468 470 469 471 audioIn.sample_size = -32; // force SetupAudioStream to run once … … bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 4204 4206 4205 4207 if (ctx->codec_id == CODEC_ID_AC3) 4206 4208 passthru = allow_ac3_passthru && 4207 ctx->channels >= (int)max_channels; 4209 ctx->channels >= (int)max_channels && 4210 !internal_vol; 4208 4211 else if (ctx->codec_id == CODEC_ID_DTS) 4209 passthru = allow_dts_passthru ;4212 passthru = allow_dts_passthru && !internal_vol; 4210 4213 4211 4214 passthru &= !transcoding && !disable_passthru; 4212 4215 // 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 ea1fb23..4fe8d65 100644
a b class AvFormatDecoder : public DecoderBase 269 269 short int *audioSamples; 270 270 bool allow_ac3_passthru; 271 271 bool allow_dts_passthru; 272 bool internal_vol; 272 273 bool disable_passthru; 273 274 uint max_channels; 274 275 uint last_ac3_channels; -
mythtv/programs/mythtranscode/transcode.cpp
diff --git a/mythtv/programs/mythtranscode/transcode.cpp b/mythtv/programs/mythtranscode/transcode.cpp index 9958473..77ca720 100644
a b class AudioReencodeBuffer : public AudioOutput 227 227 // Do nothing 228 228 return false; 229 229 } 230 virtual void SetSWVolume(int new_volume, bool save) 231 { 232 // Do nothing 233 return; 234 } 235 236 virtual int GetSWVolume(void) 237 { 238 // Do nothing 239 return 100; 240 } 230 241 231 242 // These are pure virtual in AudioOutput, but we don't need them here 232 243 virtual void bufferOutputData(bool){ return; }