Ticket #6279: softvol-trunk-3.patch
File softvol-trunk-3.patch, 11.1 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..9138f9d 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, bool save) 617 { 618 volume = new_volume; 619 if (save) 620 { 621 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 622 controlLabel += "MixerVolume"; 623 gContext->SaveSetting(controlLabel, volume); 624 } 625 } 626 627 int AudioOutputBase::GetSWVolume() 628 { 629 return volume; 630 } 631 632 template <class AudioDataType> 633 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 634 { 635 float g = volume / 100.0; 636 637 // Should probably be logarithmic - this'll do 638 g *= g; 639 640 // Add gain to AC-3 - try to ~ match PCM volume 641 if (audio_enc && audio_reenc) 642 g *= 1.8; 643 644 // Music is relatively loud - ditto 645 else if (music) 646 g *= 0.4; 647 648 if (g == 1.0) 649 return; 650 651 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 652 { 653 float s = static_cast<float>(buffer[i]) * g / 654 static_cast<float>(numeric_limits<AudioDataType>::max()); 655 if (s >= 1.0) 656 buffer[i] = numeric_limits<AudioDataType>::max(); 657 else if (s <= -1.0) 658 buffer[i] = numeric_limits<AudioDataType>::min(); 659 else 660 buffer[i] = static_cast<AudioDataType> 661 (s * numeric_limits<AudioDataType>::max()); 662 } 663 } 664 665 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) { 666 667 if (audio_bits == 8) 668 _AdjustVolume<char>((char *)buffer, len, music); 669 else if (audio_bits == 16) 670 _AdjustVolume<short>((short *)buffer, len, music); 671 672 } 673 674 603 675 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 604 676 long long timecode) 605 677 { … … void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 943 1015 944 1016 } 945 1017 1018 if (internal_vol && SWVolume()) 1019 { 1020 int bdiff = kAudioRingBufferSize - waud; 1021 bool music = (timecode < 1); 1022 1023 if (bdiff < len) 1024 { 1025 AdjustVolume(audiobuffer + waud, bdiff, music); 1026 AdjustVolume(audiobuffer, len - bdiff, music); 1027 } 1028 else 1029 AdjustVolume(audiobuffer + waud, len, music); 1030 } 1031 946 1032 // Encode to AC-3? 947 1033 if (encoder) 948 1034 { -
mythtv/libs/libmyth/audiooutputbase.h
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h index 9a264a7..95634a4 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 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..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 50c2919..e963be9 100644
a b AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 427 427 // Audio 428 428 audioSamples(NULL), 429 429 allow_ac3_passthru(false), allow_dts_passthru(false), 430 internal_vol(false), 430 431 disable_passthru(false), max_channels(2), 431 432 last_ac3_channels(0), dummy_frame(NULL), 432 433 // DVD … … AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 448 449 449 450 allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false); 450 451 allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false); 452 internal_vol = gContext->GetNumSetting("MythControlsVolume", 0); 451 453 max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2); 452 454 453 455 audioIn.sample_size = -32; // force SetupAudioStream to run once … … bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 4129 4131 4130 4132 if (ctx->codec_id == CODEC_ID_AC3) 4131 4133 passthru = allow_ac3_passthru && 4132 ctx->channels >= (int)max_channels; 4134 ctx->channels >= (int)max_channels && 4135 !internal_vol; 4133 4136 else if (ctx->codec_id == CODEC_ID_DTS) 4134 passthru = allow_dts_passthru ;4137 passthru = allow_dts_passthru && !internal_vol; 4135 4138 4136 4139 passthru &= !transcoding && !disable_passthru; 4137 4140 // 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 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 f3b7f04..fe80532 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; }