Ticket #6279: softvol-fixes-4.patch
File softvol-fixes-4.patch, 12.8 KB (added by , 15 years ago) |
---|
-
mythtv/libs/libavcodec/dca.c
diff --git a/mythtv/libs/libavcodec/dca.c b/mythtv/libs/libavcodec/dca.c index b3803ad..050a1e7 100644
a b static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs 87 87 /** Pre-calculated cosine modulation coefs for the QMF */ 88 88 static float cos_mod[544]; 89 89 90 static int channel_map[6] = { 1, 0, 2, 3, 4, 5 }; 91 90 92 static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) 91 93 { 92 94 return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset; … … static int dca_decode_frame(AVCodecContext * avctx, 1189 1191 dca_decode_block(s); 1190 1192 s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels); 1191 1193 /* interleave samples */ 1192 for (j = 0; j < 256; j++) { 1193 for (k = 0; k < channels; k++) 1194 samples[k] = s->tsamples[j + k * 256]; 1195 samples += channels; 1194 if (channels == 6) { 1195 for (j = 0; j < 256; j++) { 1196 for (k = 0; k < channels; k++) 1197 samples[k] = s->tsamples[j + channel_map[k] * 256]; 1198 samples += channels; 1199 } 1200 } 1201 else { 1202 for (j = 0; j < 256; j++) { 1203 for (k = 0; k < channels; k++) 1204 samples[k] = s->tsamples[j + k * 256]; 1205 samples += channels; 1206 } 1196 1207 } 1197 1208 *data_size += 256 * sizeof(int16_t) * channels; 1198 1209 } -
mythtv/libs/libmyth/audiooutputalsa.cpp
diff --git a/mythtv/libs/libmyth/audiooutputalsa.cpp b/mythtv/libs/libmyth/audiooutputalsa.cpp index 96e06cb..1f5fde3 100644
a b void AudioOutputALSA::SetupMixer(void) 698 698 if (mixer_handle != NULL) 699 699 CloseMixer(); 700 700 701 if (alsadevice.lower() == "software") 702 return; 703 701 704 VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device)); 702 705 703 706 // 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 ad58b26..62751e5 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, 270 271 if(audio_passthru || audio_enc) 271 272 // AC-3 output - soundcard expects a 2ch 48k stream 272 273 audio_channels = 2; 274 275 if (internal_vol && audio_enc && audio_reenc) 276 { 277 VERBOSE(VB_AUDIO, LOC + "Using software vol control for AC-3"); 278 SWVolume(true); 279 } 280 else 281 SWVolume(false); 273 282 274 283 audio_bytes_per_sample = audio_channels * audio_bits / 8; 275 284 source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8; … … void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 314 323 VERBOSE(VB_AUDIO, "Aborting reconfigure"); 315 324 return; 316 325 } 317 326 327 // Only used for software volume 328 if (set_initial_vol && internal_vol) 329 volume = gContext->GetNumSetting("PCMMixerVolume", 100); 330 318 331 SyncVolume(); 319 332 320 333 VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1") … … void AudioOutputBase::SetAudiotime(void) 625 638 pthread_mutex_unlock(&audio_buflock); 626 639 } 627 640 641 void AudioOutputBase::SetSWVolume(int new_volume, bool save) 642 { 643 volume = new_volume; 644 if (save) 645 { 646 QString controlLabel = gContext->GetSetting("MixerControl", "PCM"); 647 controlLabel += "MixerVolume"; 648 gContext->SaveSetting(controlLabel, volume); 649 } 650 } 651 652 int AudioOutputBase::GetSWVolume() 653 { 654 return volume; 655 } 656 657 template <class AudioDataType> 658 void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music) 659 { 660 float g = volume / 100.0; 661 662 // Should probably be logarithmic - this'll do 663 g *= g; 664 665 // Add gain to AC-3 - try to ~ match PCM volume 666 if (audio_enc && audio_reenc) 667 g *= 1.8; 668 669 // Music is relatively loud - ditto 670 else if (music) 671 g *= 0.4; 672 673 if (g == 1.0) 674 return; 675 676 for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++) 677 { 678 float s = static_cast<float>(buffer[i]) * g / 679 static_cast<float>(numeric_limits<AudioDataType>::max()); 680 if (s >= 1.0) 681 buffer[i] = numeric_limits<AudioDataType>::max(); 682 else if (s <= -1.0) 683 buffer[i] = numeric_limits<AudioDataType>::min(); 684 else 685 buffer[i] = static_cast<AudioDataType> 686 (s * numeric_limits<AudioDataType>::max()); 687 } 688 } 689 690 void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) { 691 692 if (audio_bits == 8) 693 _AdjustVolume<char>((char *)buffer, len, music); 694 else if (audio_bits == 16) 695 _AdjustVolume<short>((short *)buffer, len, music); 696 697 } 698 628 699 bool AudioOutputBase::AddSamples(char *buffers[], int samples, 629 700 long long timecode) 630 701 { … … void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 970 1041 971 1042 } 972 1043 1044 if (internal_vol && SWVolume()) 1045 { 1046 int bdiff = AUDBUFSIZE - waud; 1047 bool music = (timecode < 1); 1048 1049 if (bdiff < len) 1050 { 1051 AdjustVolume(audiobuffer + waud, bdiff, music); 1052 AdjustVolume(audiobuffer, len - bdiff, music); 1053 } 1054 else 1055 AdjustVolume(audiobuffer + waud, len, music); 1056 } 1057 973 1058 // Encode to AC-3? 974 1059 if (encoder) 975 1060 { -
mythtv/libs/libmyth/audiooutputbase.h
diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h index 334c530..b6ebe99 100644
a b class AudioOutputBase : public AudioOutput 62 62 63 63 virtual void Reset(void); 64 64 65 void SetSWVolume(int new_volume, bool save); 66 int GetSWVolume(void); 67 65 68 // timecode is in milliseconds. 66 69 virtual bool AddSamples(char *buffer, int samples, long long timecode); 67 70 virtual bool AddSamples(char *buffers[], int samples, long long timecode); … … class AudioOutputBase : public AudioOutput 116 119 int audiofree(bool use_lock); // number of free bytes in audio buffer 117 120 118 121 void UpdateVolume(void); 119 122 120 123 void SetStretchFactorLocked(float factor); 121 124 122 125 int GetBaseAudioTime() const { return audiotime; } … … class AudioOutputBase : public AudioOutput 156 159 int src_quality; 157 160 158 161 private: 162 // software volume 163 template <class AudioDataType> 164 void _AdjustVolume(AudioDataType *buffer, int len, bool music); 165 void AdjustVolume(void *buffer, int len, bool music); 166 159 167 // resampler 160 168 bool need_resampler; 161 169 SRC_STATE *src_ctx; … … class AudioOutputBase : public AudioOutput 176 184 int surround_mode; 177 185 bool allow_ac3_passthru; 178 186 float old_audio_stretchfactor; 187 int volume; 179 188 180 189 bool blocking; // do AddSamples calls block? 181 190 -
mythtv/libs/libmyth/audiooutputoss.cpp
diff --git a/mythtv/libs/libmyth/audiooutputoss.cpp b/mythtv/libs/libmyth/audiooutputoss.cpp index 3436579..f0cd5e8 100644
a b void AudioOutputOSS::VolumeInit() 291 291 int volume = 0; 292 292 293 293 QString device = gContext->GetSetting("MixerDevice", "/dev/mixer"); 294 if (device.lower() == "software") 295 return; 294 296 mixerfd = open(device.ascii(), O_RDONLY); 295 297 296 298 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 9ffb7a0..d5221cd 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) 3958 3960 3959 3961 if (ctx->codec_id == CODEC_ID_AC3) 3960 3962 passthru = allow_ac3_passthru && 3961 ctx->channels >= (int)max_channels; 3963 ctx->channels >= (int)max_channels && 3964 !internal_vol; 3962 3965 else if (ctx->codec_id == CODEC_ID_DTS) 3963 passthru = allow_dts_passthru ;3966 passthru = allow_dts_passthru && !internal_vol; 3964 3967 3965 3968 passthru &= !transcoding && !disable_passthru; 3966 3969 // 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 c6adf51..cd58eba 100644
a b class AudioReencodeBuffer : public AudioOutput 221 221 // Do nothing 222 222 return false; 223 223 } 224 virtual void SetSWVolume(int new_volume, bool save) 225 { 226 // Do nothing 227 return; 228 } 229 230 virtual int GetSWVolume(void) 231 { 232 // Do nothing 233 return 100; 234 } 224 235 225 236 // These are pure virtual in AudioOutput, but we don't need them here 226 237 virtual void bufferOutputData(bool){ return; }