Ticket #6279: sofvol-trunk-6.patch

File sofvol-trunk-6.patch, 10.9 KB (added by JYA, 15 years ago)

Against trunk r21594

  • libs/libmyth/audiooutputalsa.cpp

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputalsa.cpp mythtv/libs/libmyth/audiooutputalsa.cpp
    old new  
    780780    if (mixer_handle != NULL)
    781781        CloseMixer();
    782782
     783    if (alsadevice.toLower() == "software")
     784        return;
     785
    783786    VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device));
    784787
    785788    // TODO: This is opening card 0. Fix for case of multiple soundcards
  • libs/libmyth/audiooutputbase.cpp

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputbase.cpp mythtv/libs/libmyth/audiooutputbase.cpp
    old new  
    11// Std C headers
    22#include <cmath>
     3#include <limits>
    34
    45// POSIX headers
    56#include <unistd.h>
     
    5354    needs_upmix(false),
    5455    surround_mode(FreeSurround::SurroundModePassive),
    5556    old_audio_stretchfactor(1.0),
     57    volume(80),
    5658
    5759    blocking(false),
    5860
     
    335337        return;
    336338    }
    337339
     340    // Only used for software volume
     341    if (set_initial_vol && internal_vol)
     342        volume = gContext->GetNumSetting("PCMMixerVolume", 80);
     343    {
     344        QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
     345        controlLabel += "MixerVolume";
     346        volume = gContext->GetNumSetting(controlLabel, 80);
     347    }
     348
    338349    SyncVolume();
    339350
    340351    VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1")
     
    628639     return audbuf_timecode - GetAudiotime();
    629640}
    630641
     642void AudioOutputBase::SetSWVolume(int new_volume, bool save)
     643{
     644    volume = new_volume;
     645    if (save)
     646    {
     647        QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
     648        controlLabel += "MixerVolume";
     649        gContext->SaveSetting(controlLabel, volume);
     650    }
     651}
     652
     653int AudioOutputBase::GetSWVolume()
     654{
     655    return volume;
     656}
     657
     658template <class AudioDataType>
     659void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music)
     660{
     661    float g = volume / 100.0;
     662
     663    // Should probably be exponential - this'll do
     664    g *= g;
     665   
     666    // Add gain to AC-3 - try to ~ match PCM volume
     667    if (audio_enc && audio_reenc)
     668        g *= 1.8;
     669
     670    // Music is relatively loud - ditto
     671    else if (music)
     672        g *= 0.4;
     673
     674    if (g == 1.0)
     675        return;
     676
     677    for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++)
     678    {
     679        float s = static_cast<float>(buffer[i]) * g /
     680                  static_cast<float>(numeric_limits<AudioDataType>::max());
     681        if (s >= 1.0)
     682            buffer[i] = numeric_limits<AudioDataType>::max();
     683        else if (s <= -1.0)
     684            buffer[i] = numeric_limits<AudioDataType>::min();
     685        else
     686            buffer[i] = static_cast<AudioDataType>
     687                        (s * numeric_limits<AudioDataType>::max());
     688    }
     689}
     690
     691void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music)
     692{
     693    if (audio_bits == 8)
     694        _AdjustVolume<char>((char *)buffer, len, music);
     695    else if (audio_bits == 16)
     696        _AdjustVolume<short>((short *)buffer, len, music);
     697}
     698
    631699bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    632700                                 long long timecode)
    633701{
     
    9691037        }
    9701038    }
    9711039
     1040    if (internal_vol && SWVolume())
     1041    {
     1042        int bdiff = kAudioRingBufferSize - waud;
     1043        bool music = (timecode < 1);
     1044
     1045        if (bdiff < len)
     1046        {
     1047            AdjustVolume(audiobuffer + waud, bdiff, music);
     1048            AdjustVolume(audiobuffer, len - bdiff, music);
     1049        }
     1050        else
     1051            AdjustVolume(audiobuffer + waud, len, music);
     1052    }
     1053
    9721054    // Encode to AC-3?
    9731055    if (encoder)
    9741056    {
  • libs/libmyth/audiooutputbase.h

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputbase.h mythtv/libs/libmyth/audiooutputbase.h
    old new  
    4747
    4848    virtual void Reset(void);
    4949
     50    void SetSWVolume(int new_volume, bool save);
     51    int GetSWVolume(void);
     52
    5053    // timecode is in milliseconds.
    5154    virtual bool AddSamples(char *buffer, int samples, long long timecode);
    5255    virtual bool AddSamples(char *buffers[], int samples, long long timecode);
     
    153156    int src_quality;
    154157
    155158 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
    156164    // resampler
    157165    bool need_resampler;
    158166    SRC_STATE *src_ctx;
     
    169177    int surround_mode;
    170178    bool allow_ac3_passthru;
    171179    float old_audio_stretchfactor;
     180    int volume;
    172181
    173182    bool blocking; // do AddSamples calls block?
    174183
  • libs/libmyth/audiooutputoss.cpp

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/audiooutputoss.cpp mythtv/libs/libmyth/audiooutputoss.cpp
    old new  
    317317    int volume = 0;
    318318
    319319    QString device = gContext->GetSetting("MixerDevice", "/dev/mixer");
     320    if (device.toLower() == "software")
     321        return;
     322
    320323    QByteArray dev = device.toAscii();
    321324    mixerfd = open(dev.constData(), O_RDONLY);
    322325
  • libs/libmyth/volumebase.cpp

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/volumebase.cpp mythtv/libs/libmyth/volumebase.cpp
    old new  
    1010    internal_vol(false), volume(80),
    1111    current_mute_state(kMuteOff)
    1212{
     13    swvol = swvol_setting =
     14        (gContext->GetSetting("MixerDevice", "default").toLower() == "software");
     15}
     16
     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;
    1327}
    1428
    1529uint VolumeBase::GetCurrentVolume(void) const
     
    7690void VolumeBase::UpdateVolume(void)
    7791{
    7892    int new_volume = volume;
     93    bool save = true;
    7994    if (current_mute_state == kMuteAll)
    8095    {
    8196        new_volume = 0;
     97        save = false;
     98    }
     99
     100    if (swvol)
     101    {
     102        SetSWVolume(new_volume, save);
     103        return;
    82104    }
    83105   
    84106    // TODO: Avoid assumption that there are 2 channels!
     
    102124void VolumeBase::SyncVolume(void)
    103125{
    104126    // 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);
    106131}
    107132
  • libs/libmyth/volumebase.h

    diff -Naur --exclude=.svn mythtv.ori/libs/libmyth/volumebase.h mythtv/libs/libmyth/volumebase.h
    old new  
    2020    VolumeBase();   
    2121    virtual ~VolumeBase() {};
    2222
     23    void SWVolume(bool set);
     24    bool SWVolume(void);
    2325    virtual uint GetCurrentVolume(void) const;
    2426    virtual void SetCurrentVolume(int value);
    2527    virtual void AdjustCurrentVolume(int change);
     
    3436
    3537    virtual int GetVolumeChannel(int channel) const = 0; // Returns 0-100
    3638    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;
    3741
    3842    void UpdateVolume(void);
    3943    void SyncVolume(void);
     
    4448   
    4549    int volume;
    4650    MuteState current_mute_state;
     51    bool swvol;
     52    bool swvol_setting;
    4753
    4854};
    4955
  • libs/libmythtv/avformatdecoder.cpp

    diff -Naur --exclude=.svn mythtv.ori/libs/libmythtv/avformatdecoder.cpp mythtv/libs/libmythtv/avformatdecoder.cpp
    old new  
    461461      // Audio
    462462      audioSamples(NULL),
    463463      allow_ac3_passthru(false),    allow_dts_passthru(false),
     464      internal_vol(false),
    464465      disable_passthru(false),      max_channels(2),
    465466      last_ac3_channels(0),         dummy_frame(NULL),
    466467      // DVD
     
    482483
    483484    allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);
    484485    allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false);
     486    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    485487    max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2);
    486488
    487489    audioIn.sample_size = -32; // force SetupAudioStream to run once
     
    42034205
    42044206    if (ctx->codec_id == CODEC_ID_AC3)
    42054207        passthru = allow_ac3_passthru &&
    4206                    ctx->channels >= (int)max_channels;
     4208                   ctx->channels >= (int)max_channels &&
     4209                   !internal_vol;
    42074210    else if (ctx->codec_id == CODEC_ID_DTS)
    4208         passthru = allow_dts_passthru;
     4211        passthru = allow_dts_passthru && !internal_vol;
    42094212
    42104213    passthru &= !transcoding && !disable_passthru;
    42114214    // Don't know any cards that support spdif clocked at < 44100
  • libs/libmythtv/avformatdecoder.h

    diff -Naur --exclude=.svn mythtv.ori/libs/libmythtv/avformatdecoder.h mythtv/libs/libmythtv/avformatdecoder.h
    old new  
    259259    short int        *audioSamples;
    260260    bool              allow_ac3_passthru;
    261261    bool              allow_dts_passthru;
     262    bool              internal_vol;
    262263    bool              disable_passthru;
    263264    uint              max_channels;
    264265    uint              last_ac3_channels;
  • programs/mythfrontend/globalsettings.cpp

    diff -Naur --exclude=.svn mythtv.ori/programs/mythfrontend/globalsettings.cpp mythtv/programs/mythfrontend/globalsettings.cpp
    old new  
    196196#ifdef USING_WINAUDIO
    197197    gc->addSelection("Windows:", "Windows:");
    198198#endif
     199#if !(defined(USING_DIRECTX) || defined(USING_WINAUDIO))
     200    gc->addSelection("software", "sofware");
     201#endif
    199202
    200203    return gc;
    201204}
  • programs/mythtranscode/transcode.cpp

    diff -Naur --exclude=.svn mythtv.ori/programs/mythtranscode/transcode.cpp mythtv/programs/mythtranscode/transcode.cpp
    old new  
    228228        return false;
    229229    }
    230230
     231    virtual void SetSWVolume(int new_volume, bool save)
     232    {
     233        // Do nothing
     234        return;
     235    }
     236    virtual int GetSWVolume(void)
     237    {
     238        // Do nothing
     239        return 100;
     240    }
     241
    231242    //  These are pure virtual in AudioOutput, but we don't need them here
    232243    virtual void bufferOutputData(bool){ return; }
    233244    virtual int readOutputData(unsigned char*, int ){ return 0; }