Ticket #6279: softvol-fixes-2.patch

File softvol-fixes-2.patch, 11.1 KB (added by foobum@…, 15 years ago)
  • 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) 
    698698    if (mixer_handle != NULL)
    699699        CloseMixer();
    700700
     701    if (alsadevice.lower() == "software")
     702        return;
     703
    701704    VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device));
    702705
    703706    // 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..dc657fe 100644
    a b AudioOutputBase::AudioOutputBase( 
    6161    needs_upmix(false),
    6262    surround_mode(FreeSurround::SurroundModePassive),
    6363    old_audio_stretchfactor(1.0),
     64    volume(80),
    6465
    6566    blocking(false),
    6667
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    270271    if(audio_passthru || audio_enc)
    271272        // AC-3 output - soundcard expects a 2ch 48k stream
    272273        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);
    273282   
    274283    audio_bytes_per_sample = audio_channels * audio_bits / 8;
    275284    source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
    void AudioOutputBase::Reconfigure(int laudio_bits, int laudio_channels, 
    314323        VERBOSE(VB_AUDIO, "Aborting reconfigure");
    315324        return;
    316325    }
    317 
     326   
     327    // Only used for software volume
     328    if (set_initial_vol && internal_vol)
     329        volume = gContext->GetNumSetting("PCMMixerVolume", 100);
     330   
    318331    SyncVolume();
    319332   
    320333    VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1")
    void AudioOutputBase::SetAudiotime(void) 
    625638    pthread_mutex_unlock(&audio_buflock);
    626639}
    627640
     641void AudioOutputBase::SetSWVolume(int new_volume)
     642{
     643    volume = new_volume;
     644    QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
     645    controlLabel += "MixerVolume";
     646    gContext->SaveSetting(controlLabel, volume);   
     647}
     648
     649int AudioOutputBase::GetSWVolume()
     650{
     651    return volume;
     652}
     653
     654template <class AudioDataType>
     655void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music)
     656{
     657    float g = volume / 100.0;
     658
     659    // Should probably be logarithmic - this'll do
     660    g *= g;
     661   
     662    // Add gain to AC-3 - try to ~ match PCM volume
     663    if (audio_enc && audio_reenc)
     664        g *= 1.8;
     665
     666    // Music is relatively loud - ditto
     667    else if (music)
     668        g *= 0.4;
     669
     670    if (g == 1.0)
     671        return;
     672
     673    for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++)
     674    {
     675        float s = static_cast<float>(buffer[i]) * g /
     676                  static_cast<float>(numeric_limits<AudioDataType>::max());
     677        if (s >= 1.0)
     678            buffer[i] = numeric_limits<AudioDataType>::max();
     679        else if (s <= -1.0)
     680            buffer[i] = numeric_limits<AudioDataType>::min();
     681        else
     682            buffer[i] = static_cast<AudioDataType>
     683                        (s * numeric_limits<AudioDataType>::max());
     684    }
     685}
     686
     687void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music) {
     688
     689    if (audio_bits == 8)
     690        _AdjustVolume<char>((char *)buffer, len, music);
     691    else if (audio_bits == 16)
     692        _AdjustVolume<short>((short *)buffer, len, music);
     693
     694}
     695
    628696bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    629697                                 long long timecode)
    630698{
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    9701038       
    9711039    }
    9721040
     1041    if (internal_vol && SWVolume())
     1042    {
     1043        int bdiff = AUDBUFSIZE - waud;
     1044        bool music = (timecode < 1);
     1045
     1046        if (bdiff < len)
     1047        {
     1048            AdjustVolume(audiobuffer + waud, bdiff, music);
     1049            AdjustVolume(audiobuffer, len - bdiff, music);
     1050        }
     1051        else
     1052            AdjustVolume(audiobuffer + waud, len, music);
     1053    }
     1054
    9731055    // Encode to AC-3?
    9741056    if (encoder)
    9751057    {
  • mythtv/libs/libmyth/audiooutputbase.h

    diff --git a/mythtv/libs/libmyth/audiooutputbase.h b/mythtv/libs/libmyth/audiooutputbase.h
    index 334c530..bf11983 100644
    a b class AudioOutputBase : public AudioOutput 
    6262
    6363    virtual void Reset(void);
    6464
     65    void SetSWVolume(int new_volume);
     66    int GetSWVolume(void);
     67
    6568    // timecode is in milliseconds.
    6669    virtual bool AddSamples(char *buffer, int samples, long long timecode);
    6770    virtual bool AddSamples(char *buffers[], int samples, long long timecode);
    class AudioOutputBase : public AudioOutput 
    116119    int audiofree(bool use_lock); // number of free bytes in audio buffer
    117120
    118121    void UpdateVolume(void);
    119    
     122
    120123    void SetStretchFactorLocked(float factor);
    121124
    122125    int GetBaseAudioTime()                    const { return audiotime;       }
    class AudioOutputBase : public AudioOutput 
    156159    int src_quality;
    157160
    158161 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   
    159167    // resampler
    160168    bool need_resampler;
    161169    SRC_STATE *src_ctx;
    class AudioOutputBase : public AudioOutput 
    176184    int surround_mode;
    177185    bool allow_ac3_passthru;
    178186    float old_audio_stretchfactor;
     187    int volume;
    179188
    180189    bool blocking; // do AddSamples calls block?
    181190
  • 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() 
    291291    int volume = 0;
    292292
    293293    QString device = gContext->GetSetting("MixerDevice", "/dev/mixer");
     294    if (device.lower() == "software")
     295        return;
    294296    mixerfd = open(device.ascii(), O_RDONLY);
    295297
    296298    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..e2bce87 100644
    a b VolumeBase::VolumeBase() 
    1010    volume = 80;
    1111    current_mute_state=MUTE_OFF;
    1212    internal_vol = false;
     13    swvol = swvol_setting =
     14        (gContext->GetSetting("MixerDevice", "default").lower() == "software");
    1315};
    1416
     17bool VolumeBase::SWVolume(void)
     18{
     19    return swvol;
     20}
     21
     22void VolumeBase::SWVolume(bool set)
     23{
     24    if (swvol_setting)
     25        return;
     26    swvol = set;
     27}
     28
     29
    1530int VolumeBase::GetCurrentVolume(void)
    1631{
    1732    return volume;
    void VolumeBase::UpdateVolume(void) 
    92107    {
    93108        new_volume = 0;
    94109    }
     110
     111    if (swvol)
     112    {
     113        SetSWVolume(new_volume);
     114        return;
     115    }
    95116   
    96117    // TODO: Avoid assumption that there are 2 channels!
    97118    for (int i = 0; i < 2; i++)
    void VolumeBase::UpdateVolume(void) 
    114135void VolumeBase::SyncVolume(void)
    115136{
    116137    // Read the volume from the audio driver and setup our internal state to match
    117     volume = GetVolumeChannel(0);
     138    if (swvol)
     139        volume = GetSWVolume();
     140    else
     141        volume = GetVolumeChannel(0);
    118142}
    119143
  • mythtv/libs/libmyth/volumebase.h

    diff --git a/mythtv/libs/libmyth/volumebase.h b/mythtv/libs/libmyth/volumebase.h
    index f41a5d7..6592524 100644
    a b class MPUBLIC VolumeBase 
    2020    VolumeBase();   
    2121    virtual ~VolumeBase() {};
    2222
     23    void SWVolume(bool set);
     24    bool SWVolume(void);
    2325    virtual int GetCurrentVolume(void);
    2426    virtual void SetCurrentVolume(int value);
    2527    virtual void AdjustCurrentVolume(int change);
    class MPUBLIC VolumeBase 
    3234
    3335    virtual int GetVolumeChannel(int channel) = 0; // Returns 0-100
    3436    virtual void SetVolumeChannel(int channel, int volume) = 0; // range 0-100 for vol
     37    virtual void SetSWVolume(int new_volume) = 0;
     38    virtual int GetSWVolume(void) = 0;
    3539
    3640    void UpdateVolume(void);
    3741    void SyncVolume(void);
    class MPUBLIC VolumeBase 
    4246   
    4347    int volume;
    4448    kMuteState current_mute_state;
     49    bool swvol;
     50    bool swvol_setting;
    4551
    4652};
    4753
  • 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, 
    410410      // Audio
    411411      audioSamples(new short int[AVCODEC_MAX_AUDIO_FRAME_SIZE]),
    412412      allow_ac3_passthru(false),    allow_dts_passthru(false),
     413      internal_vol(false),
    413414      disable_passthru(false),      max_channels(2),
    414415      last_ac3_channels(0),         dummy_frame(NULL),
    415416      // DVD
    AvFormatDecoder::AvFormatDecoder(NuppelVideoPlayer *parent, 
    428429
    429430    allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);
    430431    allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false);
     432    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    431433    max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2);
    432434
    433435    audioIn.sample_size = -32; // force SetupAudioStream to run once
    bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx) 
    39583960
    39593961    if (ctx->codec_id == CODEC_ID_AC3)
    39603962        passthru = allow_ac3_passthru &&
    3961                    ctx->channels >= (int)max_channels;
     3963                   ctx->channels >= (int)max_channels &&
     3964                   !internal_vol;
    39623965    else if (ctx->codec_id == CODEC_ID_DTS)
    3963         passthru = allow_dts_passthru;
     3966        passthru = allow_dts_passthru && !internal_vol;
    39643967   
    39653968    passthru &= !transcoding && !disable_passthru;
    39663969    // 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 
    263263    short int        *audioSamples;
    264264    bool              allow_ac3_passthru;
    265265    bool              allow_dts_passthru;
     266    bool              internal_vol;
    266267    bool              disable_passthru;
    267268    uint              max_channels;
    268269    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..9112c03 100644
    a b class AudioReencodeBuffer : public AudioOutput 
    221221        // Do nothing
    222222        return false;
    223223    }
     224    virtual void SetSWVolume(int new_volume)
     225    {
     226        // Do nothing
     227        return;
     228    }
     229   
     230    virtual int GetSWVolume(void)
     231    {
     232        // Do nothing
     233        return 100;
     234    }
    224235
    225236    //  These are pure virtual in AudioOutput, but we don't need them here
    226237    virtual void bufferOutputData(bool){ return; }