Ticket #6279: softvol-fixes-4.patch

File softvol-fixes-4.patch, 12.8 KB (added by foobum@…, 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 
    8787/** Pre-calculated cosine modulation coefs for the QMF */
    8888static float cos_mod[544];
    8989
     90static int channel_map[6] = { 1, 0, 2, 3, 4, 5 };
     91
    9092static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx)
    9193{
    9294    return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset;
    static int dca_decode_frame(AVCodecContext * avctx, 
    11891191        dca_decode_block(s);
    11901192        s->dsp.float_to_int16(s->tsamples, s->samples, 256 * channels);
    11911193        /* 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            }
    11961207        }
    11971208        *data_size += 256 * sizeof(int16_t) * channels;
    11981209    }
  • 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..62751e5 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, 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
     652int AudioOutputBase::GetSWVolume()
     653{
     654    return volume;
     655}
     656
     657template <class AudioDataType>
     658void 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
     690void 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
    628699bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    629700                                 long long timecode)
    630701{
    void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples, 
    9701041       
    9711042    }
    9721043
     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
    9731058    // Encode to AC-3?
    9741059    if (encoder)
    9751060    {
  • 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 
    6262
    6363    virtual void Reset(void);
    6464
     65    void SetSWVolume(int new_volume, bool save);
     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..2431ff2 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;
    kMuteState VolumeBase::IterateMutedChannels(void) 
    88103void VolumeBase::UpdateVolume(void)
    89104{
    90105    int new_volume = volume;
     106    bool save = true;
    91107    if (current_mute_state == MUTE_BOTH)
    92108    {
    93109        new_volume = 0;
     110        save = false;
     111    }
     112
     113    if (swvol)
     114    {
     115        SetSWVolume(new_volume, save);
     116        return;
    94117    }
    95118   
    96119    // TODO: Avoid assumption that there are 2 channels!
    void VolumeBase::UpdateVolume(void) 
    114137void VolumeBase::SyncVolume(void)
    115138{
    116139    // 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);
    118144}
    119145
  • 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 
    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, bool save) = 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..cd58eba 100644
    a b class AudioReencodeBuffer : public AudioOutput 
    221221        // Do nothing
    222222        return false;
    223223    }
     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    }
    224235
    225236    //  These are pure virtual in AudioOutput, but we don't need them here
    226237    virtual void bufferOutputData(bool){ return; }