Ticket #6279: softvol-trunk.patch
File softvol-trunk.patch, 10.5 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 1a66dfe..cce3258 100644
a b void AudioOutputALSA::SetupMixer(void) 699 699 if (mixer_handle != NULL) 700 700 CloseMixer(); 701 701 702 if (alsadevice.toLower() == "software") 703 return; 704 702 705 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 703 706 704 707 // 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 112f554..efa098b 100644
a b AudioOutputBase::AudioOutputBase(const AudioSettings &settings) : 53 53 needs_upmix(false), 54 54 surround_mode(FreeSurround::SurroundModePassive), 55 55 old_audio_stretchfactor(1.0), 56 volume(80), 56 57 57 58 blocking(false), 58 59 … … void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings) 269 270 if(audio_passthru || audio_enc) 270 271 // AC-3 output - soundcard expects a 2ch 48k stream 271 272 audio_channels = 2; 273 274 if (internal_vol && audio_enc && audio_reenc) 275 { 276 VERBOSE(VB_AUDIO, LOC + "Using software vol control for AC-3"); 277 SWVolume(true); 278 } 279 else 280 SWVolume(false); 272 281 273 282 audio_bytes_per_sample = audio_channels * audio_bits / 8; 274 283 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; … … void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings) 309 318 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 310 319 return; 311 320 } 312 321 322 // Only used for software volume 323 if (set_initial_vol && internal_vol) 324 volume = gContext->GetNumSetting("PCMMixerVolume", 100); 325 313 326 SyncVolume(); 314 327 315 328 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") … … int AudioOutputBase::GetAudioBufferedTime(void) 600 613 return audbuf_timecode - GetAudiotime(); 601 614 } 602 615 616 void AudioOutputBase::SetSWVolume(int new_volume) 617 { 618 volume = new_volume; 619 } 620 621 int AudioOutputBase::GetSWVolume() 622 { 623 return volume; 624 } 625 626 template <class AudioDataType> 627 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 628 { 629 float g = volume / 100.0; 630 631 // Should probably be logarithmic - this'll do 632 g *= g; 633 634 // Add gain to AC-3 - try to ~ match PCM volume 635 if (audio_enc && audio_reenc) 636 g *= 1.8; 637 638 // Music is relatively loud - ditto 639 else if (music) 640 g *= 0.4; 641 642 if (g == 1.0) 643 return; 644 645 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 646 { 647 float s = static_cast<float>(buffer[i]) * g / 648 static_cast<float>(numeric_limits<AudioDataType>::max()); 649 if (s >= 1.0) 650 buffer[i] = numeric_limits<AudioDataType>::max(); 651 else if (s <= -1.0) 652 buffer[i] = numeric_limits<AudioDataType>::min(); 653 else 654 buffer[i] = static_cast<AudioDataType> 655 (s * numeric_limits<AudioDataType>::max()); 656 } 657 } 658 659 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) { 660 661 if (audio_bits == 8) 662 _AdjustVolume<char>((char *)buffer, len, music); 663 else if (audio_bits == 16) 664 _AdjustVolume<short>((short *)buffer, len, music); 665 666 } 667 668 603 669 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 604 670 long long timecode) 605 671 { … … void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 943 1009 944 1010 } 945 1011 1012 if (internal_vol && SWVolume()) 1013 { 1014 int bdiff = kAudioRingBufferSize - waud; 1015 bool music = (timecode < 1); 1016 1017 if (bdiff < len) 1018 { 1019 AdjustVolume(audiobuffer + waud, bdiff, music); 1020 AdjustVolume(audiobuffer, len - bdiff, music); 1021 } 1022 else 1023 AdjustVolume(audiobuffer + waud, len, music); 1024 } 1025 946 1026 // Encode to AC-3? 947 1027 if (encoder) 948 1028 { -
mythtv/libs/libmyth/audiooutputbase.h
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h index 9a264a7..20f32ef 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); 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 150 153 int src_quality; 151 154 152 155 private: 156 // software volume 157 template <class AudioDataType> 158 void _AdjustVolume(AudioDataType *buffer, int len, bool music); 159 void AdjustVolume(void *buffer, int len, bool music); 160 153 161 // resampler 154 162 bool need_resampler; 155 163 SRC_STATE *src_ctx; … … class AudioOutputBase : public AudioOutput, public QThread 166 174 int surround_mode; 167 175 bool allow_ac3_passthru; 168 176 float old_audio_stretchfactor; 177 int volume; 169 178 170 179 bool blocking; // do AddSamples calls block? 171 180 -
mythtv/libs/libmyth/audiooutputoss.cpp
diff --git a/mythtv/libs/libmyth/audiooutputoss.cpp b/mythtv/libs/libmyth/audiooutputoss.cpp index a18f147..348a60f 100644
a b void AudioOutputOSS::VolumeInit() 287 287 int volume = 0; 288 288 289 289 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 290 if (device.toLower() == "software") 291 return; 290 292 QByteArray dev = device.toAscii(); 291 293 mixerfd = open(dev.constData(), O_RDONLY); 292 294 -
mythtv/libs/libmyth/volumebase.cpp
diff --git a/mythtv/libs/libmyth/volumebase.cpp b/mythtv/libs/libmyth/volumebase.cpp index d1f1fb0..be28940 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 … … void VolumeBase::UpdateVolume(void) 80 94 { 81 95 new_volume = 0; 82 96 } 97 98 if (swvol) 99 { 100 SetSWVolume(new_volume); 101 return; 102 } 83 103 84 104 // TODO: Avoid assumption that there are 2 channels! 85 105 for (int i = 0; i < 2; i++) … … void VolumeBase::UpdateVolume(void) 102 122 void VolumeBase::SyncVolume(void) 103 123 { 104 124 // Read the volume from the audio driver and setup our internal state to match 105 volume = GetVolumeChannel(0); 125 if (swvol) 126 volume = GetSWVolume(); 127 else 128 volume = GetVolumeChannel(0); 106 129 } 107 130 -
mythtv/libs/libmyth/volumebase.h
diff --git a/mythtv/libs/libmyth/volumebase.h b/mythtv/libs/libmyth/volumebase.h index 4257f0b..8c658da 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) = 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 6145de8..721c851 100644
a b AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 426 426 // Audio 427 427 audioSamples(NULL), 428 428 allow_ac3_passthru(false), allow_dts_passthru(false), 429 internal_vol(false), 429 430 disable_passthru(false), max_channels(2), 430 431 last_ac3_channels(0), dummy_frame(NULL), 431 432 // DVD … … AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 447 448 448 449 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false); 449 450 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 451 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 450 452 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 451 453 452 454 audioIn.sample_size = -32; // force SetupAudioStream to run once … … bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 4126 4128 4127 4129 if (ctx->codec_id == CODEC_ID_AC3) 4128 4130 passthru = allow_ac3_passthru && 4129 ctx->channels >= (int)max_channels; 4131 ctx->channels >= (int)max_channels && 4132 !internal_vol; 4130 4133 else if (ctx->codec_id == CODEC_ID_DTS) 4131 4134 passthru = allow_dts_passthru; 4132 4135 -
mythtv/libs/libmythtv/avformatdecoder.h
diff --git a/mythtv/libs/libmythtv/avformatdecoder.h b/mythtv/libs/libmythtv/avformatdecoder.h index 57311b6..fb9cfe7 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 6721262..459d6a5 100644
a b class AudioReencodeBuffer : public AudioOutput 226 226 // Do nothing 227 227 return false; 228 228 } 229 virtual void SetSWVolume(int new_volume) 230 { 231 // Do nothing 232 return; 233 } 234 235 virtual int GetSWVolume(void) 236 { 237 // Do nothing 238 return 100; 239 } 229 240 230 241 // These are pure virtual in AudioOutput, but we don't need them here 231 242 virtual void bufferOutputData(bool){ return; }