Ticket #6975: new_audio.diff

File new_audio.diff, 105.1 KB (added by JYA, 15 years ago)

New audio setup + upmixer + software volume control patch

  • mythplugins/mythmusic/mythmusic/playbackbox.cpp

     
    365365            changeSpeed(true);
    366366        else if (action == "MUTE")
    367367            toggleMute();
     368        else if (action == "TOGGLEUPMIX")
     369            toggleUpmix();
    368370        else if (action == "MENU" && visualizer_status != 2)
    369371        {
    370372            menufilters = false;
     
    12021204    }
    12031205}
    12041206
     1207void PlaybackBoxMusic::toggleUpmix()
     1208{
     1209    if (gPlayer->getOutput())
     1210        gPlayer->getOutput()->ToggleUpmix();
     1211}
     1212   
     1213
    12051214void PlaybackBoxMusic::showProgressBar()
    12061215{
    12071216    if (progress_bar && visualizer_status != 2)
  • mythplugins/mythmusic/mythmusic/globalsettings.cpp

     
    6767    return gc;
    6868};
    6969
     70static HostCheckBox *MusicUpmixer()
     71{
     72    HostCheckBox *gc = new HostCheckBox("MusicDefaultUpmix");
     73    gc->setLabel(QObject::tr("Upconvert stereo to 5.1 surround"));
     74    gc->setValue(false);
     75    gc->setHelpText(QObject::tr("MythTV can upconvert stereo tracks to 5.1 audio. "
     76                                "Set this option to enable it by default. "
     77                                "You can enable or disable the upconversion during playback at anytime."));
     78    return gc;
     79};
     80
    7081static HostLineEdit *CDDevice()
    7182{
    7283    HostLineEdit *gc = new HostLineEdit("CDDevice");
     
    545556    general->setLabel(QObject::tr("General Settings (1)"));
    546557    general->addChild(SetMusicDirectory());
    547558    general->addChild(MusicAudioDevice());
     559    general->addChild(MusicUpmixer());
    548560    general->addChild(CDDevice());
    549561    general->addChild(AutoLookupCD());
    550562    general->addChild(AutoPlayCD());
  • mythplugins/mythmusic/mythmusic/avfdecoder.cpp

     
    256256    if (output())
    257257    {
    258258        const AudioSettings settings(
    259             16 /*bits*/, m_audioDec->channels, m_audioDec->sample_rate,
    260             false /* AC3/DTS pass through */);
     259            16 /*bits*/, m_audioDec->channels, m_audioDec->codec_id,
     260            m_audioDec->sample_rate, false /* AC3/DTS pass through */);
    261261        output()->Reconfigure(settings);
    262262        output()->SetSourceBitrate(m_audioDec->bit_rate);
    263263    }
  • mythplugins/mythmusic/mythmusic/main.cpp

     
    389389    REG_KEY("Music", "VOLUMEDOWN", "Volume down",       "[,{,F10,Volume Down");
    390390    REG_KEY("Music", "VOLUMEUP",   "Volume up",         "],},F11,Volume Up");
    391391    REG_KEY("Music", "MUTE",       "Mute",              "|,\\,F9,Volume Mute");
     392    REG_KEY("Music", "TOGGLEUPMIX","Toggle upmixer",             "Ctrl+U");
    392393    REG_KEY("Music", "CYCLEVIS",   "Cycle visualizer mode",      "6");
    393394    REG_KEY("Music", "BLANKSCR",   "Blank screen",               "5");
    394395    REG_KEY("Music", "THMBUP",     "Increase rating",            "9");
  • mythplugins/mythmusic/mythmusic/musicplayer.cpp

     
    348348
    349349void MusicPlayer::openOutputDevice(void)
    350350{
    351     QString adevice;
     351    QString adevice, pdevice;
    352352
    353353    if (gContext->GetSetting("MusicAudioDevice") == "default")
    354354        adevice = gContext->GetSetting("AudioOutputDevice");
    355355    else
    356356        adevice = gContext->GetSetting("MusicAudioDevice");
    357357
     358    pdevice = gContext->GetSetting("PassThruOutputDevice");
     359
    358360    // TODO: Error checking that device is opened correctly!
    359     m_output = AudioOutput::OpenAudio(adevice, "default", 16, 2, 44100,
    360                                     AUDIOOUTPUT_MUSIC, true, false);
     361    m_output = AudioOutput::OpenAudio(adevice, pdevice, 16, 2, 0, 44100,
     362                                      AUDIOOUTPUT_MUSIC, true, false,
     363                                      gContext->GetNumSetting("MusicDefaultUpmix", 0) + 1);
    361364    m_output->setBufferSize(256 * 1024);
    362365    m_output->SetBlocking(false);
    363366
  • mythplugins/mythmusic/mythmusic/playbackbox.h

     
    6969    void changeVolume(bool up_or_down);
    7070    void changeSpeed(bool up_or_down);
    7171    void toggleMute();
     72    void toggleUpmix();
    7273    void resetTimer();
    7374    void hideVolume(){showVolume(false);}
    7475    void showVolume(bool on_or_off);
  • mythplugins/mythmusic/mythmusic/cddecoder.cpp

     
    1414
    1515#include <mythtv/mythcontext.h>
    1616#include <mythtv/mythmediamonitor.h>
     17#include <mythtv/libavcodec/avcodec.h>
    1718
    1819CdDecoder::CdDecoder(const QString &file, DecoderFactory *d, QIODevice *i,
    1920                     AudioOutput *o) :
     
    149150    if (output())
    150151    {
    151152        const AudioSettings settings(
    152             16 /*bits*/, chan, freq, false /* AC3/DTS passthru */);
     153            16 /*bits*/, chan, CODEC_ID_PCM_S16LE, freq,
     154            false /* AC3/DTS passthru */);
    153155        output()->Reconfigure(settings);
    154156        output()->SetSourceBitrate(44100 * 2 * 16);
    155157    }
  • mythtv/libs/libmythtv/nuppeldecoder.cpp

     
    495495#endif
    496496        GetNVP()->SetAudioParams(extradata.audio_bits_per_sample,
    497497                                 extradata.audio_channels,
     498                                 CODEC_ID_NONE,
    498499                                 extradata.audio_sample_rate,
    499500                                 false /* AC3/DTS pass through */);
    500501        GetNVP()->ReinitAudio();
  • mythtv/libs/libmythtv/NuppelVideoPlayer.cpp

     
    219219      audioOutput(NULL),
    220220      audio_main_device(QString::null),
    221221      audio_passthru_device(QString::null),
    222       audio_channels(2),            audio_bits(-1),
    223       audio_samplerate(44100),      audio_stretchfactor(1.0f),
    224       audio_codec(NULL),            audio_lock(QMutex::Recursive),
     222      audio_channels(2),            audio_codec(0),
     223      audio_bits(-1),               audio_samplerate(44100),
     224      audio_stretchfactor(1.0f),    audio_lock(QMutex::Recursive),
    225225      // Picture-in-Picture stuff
    226226      pip_active(false),            pip_visible(true),
    227227      // Preview window support
     
    922922        audioOutput = AudioOutput::OpenAudio(audio_main_device,
    923923                                             audio_passthru_device,
    924924                                             audio_bits, audio_channels,
    925                                              audio_samplerate,
     925                                             audio_codec, audio_samplerate,
    926926                                             AUDIOOUTPUT_VIDEO,
    927927                                             setVolume, audio_passthru);
    928928        if (!audioOutput)
     
    950950
    951951    if (audioOutput)
    952952    {
    953         const AudioSettings settings(
    954             audio_bits, audio_channels, audio_samplerate,
    955             audio_passthru, audio_codec);
     953        const AudioSettings settings(audio_bits, audio_channels, audio_codec,
     954                                     audio_samplerate, audio_passthru);
    956955        audioOutput->Reconfigure(settings);
     956        if (audio_passthru)
     957            audio_channels = 2;
    957958        errMsg = audioOutput->GetError();
    958959        if (!errMsg.isEmpty())
    959960            audioOutput->SetStretchFactor(audio_stretchfactor);
     
    38983899    return !IsErrored();
    38993900}
    39003901
    3901 void NuppelVideoPlayer::SetAudioParams(int bps, int channels,
     3902void NuppelVideoPlayer::SetAudioParams(int bps, int channels, int codec,
    39023903                                       int samplerate, bool passthru)
    39033904{
    39043905    audio_bits = bps;
    39053906    audio_channels = channels;
     3907    audio_codec = codec;
    39063908    audio_samplerate = samplerate;
    39073909    audio_passthru = passthru;
    39083910}
    39093911
    3910 void NuppelVideoPlayer::SetAudioCodec(void *ac)
    3911 {
    3912     audio_codec = ac;
    3913 }
    3914 
    39153912void NuppelVideoPlayer::SetEffDsp(int dsprate)
    39163913{
    39173914    if (audioOutput)
     
    53355332    }
    53365333}
    53375334
     5335bool NuppelVideoPlayer::ToggleUpmix()
     5336{
     5337    if (audioOutput)
     5338        return audioOutput->ToggleUpmix();
     5339    return false;
     5340}
     5341
    53385342void NuppelVideoPlayer::Zoom(ZoomDirection direction)
    53395343{
    53405344    if (videoOutput)
  • mythtv/libs/libmythtv/avformatdecoder.cpp

     
    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),
    465       dummy_frame(NULL),
     466      last_ac3_channels(0),         dummy_frame(NULL),
    466467      // DVD
    467468      lastdvdtitle(-1),
    468469      decodeStillFrame(false),
     
    480481    av_log_set_level((debug) ? AV_LOG_DEBUG : AV_LOG_ERROR);
    481482    av_log_set_callback(myth_av_log);
    482483
    483     allow_ac3_passthru = gContext->GetNumSetting("AC3PassThru", false);
    484     allow_dts_passthru = gContext->GetNumSetting("DTSPassThru", false);
    485484    max_channels = (uint) gContext->GetNumSetting("MaxChannels", 2);
     485    allow_ac3_passthru = (max_channels > 2) ? gContext->GetNumSetting("AC3PassThru", false) : false;
     486    allow_dts_passthru = (max_channels > 2) ? gContext->GetNumSetting("DTSPassThru", false) : false;
     487    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    486488
    487489    audioIn.sample_size = -32; // force SetupAudioStream to run once
    488490    itv = GetNVP()->GetInteractiveTV();
     
    20242026    // waiting on audio.
    20252027    if (GetNVP()->HasAudioIn() && tracks[kTrackTypeAudio].empty())
    20262028    {
    2027         GetNVP()->SetAudioParams(-1, -1, -1, false /* AC3/DTS pass-through */);
     2029        GetNVP()->SetAudioParams(-1, -1, CODEC_ID_NONE, -1, false /* AC3/DTS pass-through */);
    20282030        GetNVP()->ReinitAudio();
    20292031        if (ringBuffer && ringBuffer->isDVD())
    20302032            audioIn = AudioInfo();
     
    30593061    {
    30603062        int idx = atracks[i].av_stream_index;
    30613063        AVCodecContext *codec_ctx = ic->streams[idx]->codec;
    3062         bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    3063                                 !disable_passthru &&
    3064                                 (codec_ctx->codec_id == CODEC_ID_AC3));
    3065         bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    3066                                 !disable_passthru &&
    3067                                 (codec_ctx->codec_id == CODEC_ID_DTS));
    30683064        AudioInfo item(codec_ctx->codec_id,
    30693065                       codec_ctx->sample_rate, codec_ctx->channels,
    3070                        do_ac3_passthru || do_dts_passthru);
     3066                       DoPassThrough(codec_ctx));
    30713067        VERBOSE(VB_AUDIO, LOC + " * " + item.toString());
    30723068    }
    30733069#endif
     
    32013197bool AvFormatDecoder::GetFrame(int onlyvideo)
    32023198{
    32033199    AVPacket *pkt = NULL;
     3200    AC3HeaderInfo hdr;
    32043201    int len;
    32053202    unsigned char *ptr;
    32063203    int data_size = 0;
     
    36313628                        reselectAudioTrack = true;
    36323629                    }
    36333630
    3634                     bool do_ac3_passthru =
    3635                         (allow_ac3_passthru && !transcoding &&
    3636                          (curstream->codec->codec_id == CODEC_ID_AC3));
    3637                     bool do_dts_passthru =
    3638                         (allow_dts_passthru && !transcoding &&
    3639                          (curstream->codec->codec_id == CODEC_ID_DTS));
    3640                     bool using_passthru = do_ac3_passthru || do_dts_passthru;
    3641 
    36423631                    // detect channels on streams that need
    36433632                    // to be decoded before we can know this
    36443633                    bool already_decoded = false;
     
    36493638                                QString("Setting channels to %1")
    36503639                                .arg(audioOut.channels));
    36513640
    3652                         if (using_passthru)
     3641                        if (DoPassThrough(curstream->codec))
    36533642                        {
    36543643                            // for passthru let it select the max number
    36553644                            // of channels
     
    36713660                        reselectAudioTrack |= curstream->codec->channels;
    36723661                    }
    36733662
     3663                    if (curstream->codec->codec_id == CODEC_ID_AC3)
     3664                    {
     3665                        GetBitContext gbc;
     3666                        init_get_bits(&gbc, ptr, len * 8);
     3667                        if (!ff_ac3_parse_header(&gbc, &hdr))
     3668                        {
     3669                            if (hdr.channels != last_ac3_channels)
     3670                            {
     3671                                last_ac3_channels = curstream->codec->channels = hdr.channels;
     3672                                SetupAudioStream();
     3673                            }
     3674                        }
     3675                    }
     3676
    36743677                    if (reselectAudioTrack)
    36753678                    {
    36763679                        QMutexLocker locker(&avcodeclock);
     
    41964199    }
    41974200}
    41984201
     4202bool AvFormatDecoder::DoPassThrough(const AVCodecContext *ctx)
     4203{
     4204    bool passthru = false;
     4205
     4206    if (ctx->codec_id == CODEC_ID_AC3)
     4207        passthru = allow_ac3_passthru &&
     4208                   ctx->channels >= (int)max_channels &&
     4209                   !internal_vol;
     4210    else if (ctx->codec_id == CODEC_ID_DTS)
     4211        passthru = allow_dts_passthru && !internal_vol;
     4212
     4213    passthru &= !transcoding && !disable_passthru;
     4214    // Don't know any cards that support spdif clocked at < 44100
     4215    // Some US cable transmissions have 2ch 32k AC-3 streams
     4216    passthru &= ctx->sample_rate >= 44100;
     4217
     4218    return passthru;
     4219}
     4220
    41994221/** \fn AvFormatDecoder::SetupAudioStream(void)
    42004222 *  \brief Reinitializes audio if it needs to be reinitialized.
    42014223 *
     
    42094231    AVStream *curstream = NULL;
    42104232    AVCodecContext *codec_ctx = NULL;
    42114233    AudioInfo old_in  = audioIn;
    4212     AudioInfo old_out = audioOut;
    42134234    bool using_passthru = false;
    42144235
    42154236    if ((currentTrack[kTrackTypeAudio] >= 0) &&
     
    42234244        codec_ctx = curstream->codec;
    42244245        if (codec_ctx)
    42254246        {
    4226             bool do_ac3_passthru = (allow_ac3_passthru && !transcoding &&
    4227                                     (codec_ctx->codec_id == CODEC_ID_AC3));
    4228             bool do_dts_passthru = (allow_dts_passthru && !transcoding &&
    4229                                     (codec_ctx->codec_id == CODEC_ID_DTS));
    4230             using_passthru = do_ac3_passthru || do_dts_passthru;
    4231             info = AudioInfo(codec_ctx->codec_id,
    4232                              codec_ctx->sample_rate, codec_ctx->channels,
    4233                              using_passthru && !disable_passthru);
     4247            using_passthru = DoPassThrough(codec_ctx);
     4248            info = AudioInfo(codec_ctx->codec_id, codec_ctx->sample_rate,
     4249                            codec_ctx->channels, using_passthru);
    42344250        }
    42354251    }
    42364252
     
    42474263            QString("audio track #%1").arg(currentTrack[kTrackTypeAudio]+1));
    42484264
    42494265    audioOut = audioIn = info;
    4250     AudioInfo tmpAudioOut = audioOut;
    42514266
    4252     // A passthru stream looks like a 48KHz 2ch (@ 16bit) to the sound card
    4253     if (using_passthru && !disable_passthru)
     4267    if (!using_passthru && audioOut.channels > (int)max_channels)
    42544268    {
    4255         tmpAudioOut.channels    = 2;
    4256         tmpAudioOut.sample_rate = 48000;
    4257         tmpAudioOut.sample_size = 4;
    4258     }
    4259 
    4260     if (audioOut.channels > (int) max_channels)
    4261     {
    4262         audioOut.channels    = (int) max_channels;
     4269        audioOut.channels = (int)max_channels;
    42634270        audioOut.sample_size = audioOut.channels * 2;
    4264         codec_ctx->channels  = audioOut.channels;
     4271        codec_ctx->channels = audioOut.channels;
    42654272    }
    42664273
    4267     if (!using_passthru)
    4268         tmpAudioOut = audioOut;
    4269 
    42704274    VERBOSE(VB_AUDIO, LOC + "Audio format changed " +
    4271             QString("%1%2\n\t\t\tfrom %3 ; %4\n\t\t\tto   %5 ; %6")
    4272             .arg((using_passthru) ? "digital passthrough " : "")
    4273             .arg((using_passthru) ? tmpAudioOut.toString() : QString(""))
    4274             .arg(old_in.toString()).arg(old_out.toString())
    4275             .arg(audioIn.toString()).arg(audioOut.toString()));
     4275            QString("\n\t\t\tfrom %1 to %2")
     4276            .arg(old_in.toString()).arg(audioOut.toString()));
    42764277
    4277     if (tmpAudioOut.sample_rate > 0)
    4278         GetNVP()->SetEffDsp(tmpAudioOut.sample_rate * 100);
     4278    if (audioOut.sample_rate > 0)
     4279        GetNVP()->SetEffDsp(audioOut.sample_rate * 100);
    42794280
    4280     GetNVP()->SetAudioParams(tmpAudioOut.bps(), tmpAudioOut.channels,
    4281                              tmpAudioOut.sample_rate, audioIn.do_passthru);
     4281    GetNVP()->SetAudioParams(audioOut.bps(), audioOut.channels,
     4282                             audioOut.codec_id, audioOut.sample_rate,
     4283                             audioOut.do_passthru);
    42824284
    4283     // allow the audio stuff to reencode
    4284     GetNVP()->SetAudioCodec((using_passthru) ? codec_ctx : NULL);
    42854285    GetNVP()->ReinitAudio();
    42864286
    42874287    return true;
  • mythtv/libs/libmythtv/tv_play.h

     
    429429    bool TimeStretchHandleAction(PlayerContext*,
    430430                                 const QStringList &actions);
    431431
     432    void ToggleUpmix(PlayerContext*);
    432433    void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true);
    433434    bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions);
    434435
  • mythtv/libs/libmythtv/NuppelVideoPlayer.h

     
    125125    void SetAudioStretchFactor(float factor)  { audio_stretchfactor = factor; }
    126126    void SetAudioOutput(AudioOutput *ao)      { audioOutput = ao; }
    127127    void SetAudioInfo(const QString &main, const QString &passthru, uint rate);
    128     void SetAudioParams(int bits, int channels, int samplerate, bool passthru);
     128    void SetAudioParams(int bits, int channels, int codec, int samplerate, bool passthru);
    129129    void SetEffDsp(int dsprate);
    130130    uint AdjustVolume(int change);
    131131    bool SetMuted(bool mute);
     
    179179    // Toggle Sets
    180180    void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle);
    181181    void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
     182    bool ToggleUpmix(void);
    182183
    183184    // Gets
    184185    QSize   GetVideoBufferSize(void) const    { return video_dim; }
     
    714715    QString  audio_main_device;
    715716    QString  audio_passthru_device;
    716717    int      audio_channels;
     718    int      audio_codec;
    717719    int      audio_bits;
    718720    int      audio_samplerate;
    719721    float    audio_stretchfactor;
    720     void    *audio_codec;
    721722    bool     audio_passthru;
    722723    QMutex   audio_lock;
    723724
  • mythtv/libs/libmythtv/tv_play.cpp

     
    489489    REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10,Volume Down");
    490490    REG_KEY("TV Playback", "VOLUMEUP",   "Volume up",   "],},F11,Volume Up");
    491491    REG_KEY("TV Playback", "MUTE",       "Mute",        "|,\\,F9,Volume Mute");
     492    REG_KEY("TV Playback", "TOGGLEUPMIX", "Toggle audio upmixer", "Ctrl+U");
    492493    REG_KEY("TV Playback", "TOGGLEPIPMODE", "Toggle Picture-in-Picture view",
    493494            "V");
    494495    REG_KEY("TV Playback", "TOGGLEPBPMODE", "Toggle Picture-by-Picture view",
     
    626627  Teletext     F2,F3,F4,F5,F6,F7,F8
    627628  ITV          F2,F3,F4,F5,F6,F7,F12
    628629
    629   Playback: Ctrl-B,Ctrl-G,Ctrl-Y
     630  Playback: Ctrl-B,Ctrl-G,Ctrl-Y,Ctrl-U
    630631*/
    631632}
    632633
     
    43404341        DoTogglePictureAttribute(ctx, kAdjustingPicture_Playback);
    43414342    else if (has_action("TOGGLESTRETCH", actions))
    43424343        ToggleTimeStretch(ctx);
     4344    else if (has_action("TOGGLEUPMIX", actions))
     4345        ToggleUpmix(ctx);
    43434346    else if (has_action("TOGGLESLEEP", actions))
    43444347        ToggleSleepTimer(ctx);
    43454348    else if (has_action("TOGGLERECORD", actions) && islivetv)
     
    80238026    SetSpeedChangeTimer(0, __LINE__);
    80248027}
    80258028
     8029void TV::ToggleUpmix(PlayerContext *ctx)
     8030{
     8031    if (!ctx->nvp || !ctx->nvp->HasAudioOut())
     8032        return;
     8033    QString text;
     8034    if (ctx->nvp->ToggleUpmix())
     8035        text = tr("Upmixer On");
     8036    else
     8037        text = tr("Upmixer Off");
     8038   
     8039    if (ctx->nvp->GetOSD() && !browsemode)
     8040        ctx->nvp->GetOSD()->SetSettingsText(text, 5);
     8041}
     8042   
    80268043// dir in 10ms jumps
    80278044void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit)
    80288045{
     
    96529669        SetManualZoom(actx, true, tr("Zoom Mode ON"));
    96539670    else if (action == "TOGGLESTRETCH")
    96549671        ToggleTimeStretch(actx);
     9672    else if (action == "TOGGLEUPMIX")
     9673        ToggleUpmix(actx);
    96559674    else if (action.left(13) == "ADJUSTSTRETCH")
    96569675    {
    96579676        bool floatRead;
     
    1001710036
    1001810037    if (category == "AUDIOSYNC")
    1001910038        new OSDGenericTree(treeMenu, tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC");
     10039    else if (category == "TOGGLEUPMIX")
     10040        new OSDGenericTree(treeMenu, tr("Toggle Audio Upmixer"), "TOGGLEUPMIX");
    1002010041    else if (category == "TIMESTRETCH")
    1002110042        FillMenuTimeStretch(ctx, treeMenu);
    1002210043    else if (category == "VIDEOSCAN")
  • mythtv/libs/libmythtv/tvosdmenuentry.cpp

     
    232232    curMenuEntries.append(
    233233        new TVOSDMenuEntry("AUDIOSYNC",           1, 1, 1, 1 , "Audio Sync"));
    234234    curMenuEntries.append(
     235        new TVOSDMenuEntry("TOGGLEUPMIX",        1, 1, 1, 1, "Toggle Upmixer"));
     236    curMenuEntries.append(
    235237        new TVOSDMenuEntry("TIMESTRETCH",        1, 1, 1, 1, "Time Stretch"));
    236238    curMenuEntries.append(
    237239        new TVOSDMenuEntry("VIDEOSCAN",            1, 1, 1, 1, "Video Scan"));
  • mythtv/libs/libmythtv/avformatdecoder.h

     
    188188
    189189    void SeekReset(long long, uint skipFrames, bool doFlush, bool discardFrames);
    190190
     191    bool DoPassThrough(const AVCodecContext *ctx);
    191192    bool SetupAudioStream(void);
    192193    void SetupAudioStreamSubIndexes(int streamIndex);
    193194    void RemoveAudioStreams();
     
    258259    short int        *audioSamples;
    259260    bool              allow_ac3_passthru;
    260261    bool              allow_dts_passthru;
     262    bool              internal_vol;
    261263    bool              disable_passthru;
    262264    uint              max_channels;
     265    uint              last_ac3_channels;
    263266
    264267    VideoFrame       *dummy_frame;
    265268
  • mythtv/libs/libavcodec/aac.c

     
    9898static VLC vlc_scalefactors;
    9999static VLC vlc_spectral[11];
    100100
     101#define CHAN_MAP_MAX 6
    101102
     103static int chan_map[CHAN_MAP_MAX] = { 2, 0, 6, 4, 3, 2 };
     104
     105
    102106static ChannelElement* get_che(AACContext *ac, int type, int elem_id) {
    103107    static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
    104108    if (ac->tag_che_map[type][elem_id]) {
     
    167171    /* Allocate or free elements depending on if they are in the
    168172     * current program configuration.
    169173     *
    170      * Set up default 1:1 output mapping.
     174     * Set up default SMPTE output mapping.
    171175     *
    172      * For a 5.1 stream the output order will be:
    173      *    [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ]
    174176     */
    175177
    176178    for(i = 0; i < MAX_ELEM_ID; i++) {
     
    179181                if(!ac->che[type][i] && !(ac->che[type][i] = av_mallocz(sizeof(ChannelElement))))
    180182                    return AVERROR(ENOMEM);
    181183                if(type != TYPE_CCE) {
    182                     ac->output_data[channels++] = ac->che[type][i]->ch[0].ret;
    183                     if(type == TYPE_CPE) {
    184                         ac->output_data[channels++] = ac->che[type][i]->ch[1].ret;
     184                    /* Convert to SMPTE channel order */
     185                    int ch = 0;
     186                    if (che_pos[type][i] < CHAN_MAP_MAX) {
     187                        if (che_pos[type][i] == AAC_CHANNEL_FRONT)
     188                            ch == TYPE_SCE ? /* center */ 2 : /* FL */ 0;
     189                        else
     190                            ch = chan_map[che_pos[type][i]];
     191                        ac->output_data[ch] = ac->che[type][i]->ch[0].ret;
     192                        channels++;
     193                        if(type == TYPE_CPE) {
     194                            ac->output_data[ch + 1] = ac->che[type][i]->ch[1].ret;
     195                            channels++;
     196                        }
    185197                    }
     198                    else {
     199                        ac->output_data[channels++] = ac->che[type][i]->ch[0].ret;
     200                        if(type == TYPE_CPE) {
     201                            ac->output_data[channels++] = ac->che[type][i]->ch[1].ret;
     202                        }
     203                    }
    186204                }
    187205            } else
    188206                av_freep(&ac->che[type][i]);
  • mythtv/libs/libmyth/audiooutputjack.h

     
    2323    virtual void WriteAudio(unsigned char *aubuf, int size);
    2424    virtual int  GetSpaceOnSoundcard(void) const;
    2525    virtual int  GetBufferedOnSoundcard(void) const;
     26    vector<int> GetSupportedRates(void);
    2627
    2728  private:
    2829
  • mythtv/libs/libmyth/audiosettings.cpp

     
    77
    88#include "audiosettings.h"
    99
     10// startup_upmixer
    1011AudioSettings::AudioSettings() :
    1112    main_device(QString::null),
    1213    passthru_device(QString::null),
    1314    bits(-1),
    1415    channels(-1),
     16    codec(0),
    1517    samplerate(-1),
    1618    set_initial_vol(false),
    1719    use_passthru(false),
    18     codec(NULL),
    19     source(AUDIOOUTPUT_UNKNOWN)
     20    source(AUDIOOUTPUT_UNKNOWN),
     21    upmixer(0)
    2022{
    2123}
    2224
     
    2527    passthru_device(other.passthru_device),
    2628    bits(other.bits),
    2729    channels(other.channels),
     30    codec(other.codec),
    2831    samplerate(other.samplerate),
    2932    set_initial_vol(other.set_initial_vol),
    3033    use_passthru(other.use_passthru),
    31     codec(other.codec),
    32     source(other.source)
     34    source(other.source),
     35    upmixer(other.upmixer)
    3336{
    3437}
    3538
     
    3841    const QString &audio_passthru_device,
    3942    int audio_bits,
    4043    int audio_channels,
     44    int audio_codec,
    4145    int audio_samplerate,
    4246    AudioOutputSource audio_source,
    4347    bool audio_set_initial_vol,
    4448    bool audio_use_passthru,
    45     void *audio_codec) :
     49    int upmixer_startup) :
    4650    main_device(audio_main_device),
    4751    passthru_device(audio_passthru_device),
    4852    bits(audio_bits),
    4953    channels(audio_channels),
     54    codec(audio_codec),
    5055    samplerate(audio_samplerate),
    5156    set_initial_vol(audio_set_initial_vol),
    5257    use_passthru(audio_use_passthru),
    53     codec(audio_codec),
    54     source(audio_source)
     58    source(audio_source),
     59    upmixer(upmixer_startup)
    5560{
    5661}
    5762
    5863AudioSettings::AudioSettings(
    5964    int   audio_bits,
    6065    int   audio_channels,
     66    int   audio_codec,
    6167    int   audio_samplerate,
    6268    bool  audio_use_passthru,
    63     void *audio_codec) :
     69    int   upmixer_startup) :
    6470    main_device(QString::null),
    6571    passthru_device(QString::null),
    6672    bits(audio_bits),
    6773    channels(audio_channels),
     74    codec(audio_codec),
    6875    samplerate(audio_samplerate),
    6976    set_initial_vol(false),
    7077    use_passthru(audio_use_passthru),
    71     codec(audio_codec),
    72     source(AUDIOOUTPUT_UNKNOWN)
     78    source(AUDIOOUTPUT_UNKNOWN),
     79    upmixer(upmixer_startup)
    7380{
    7481}
    7582
  • mythtv/libs/libmyth/audiooutputbase.h

     
    4343
    4444    virtual void SetStretchFactor(float factor);
    4545    virtual float GetStretchFactor(void) const;
     46    virtual bool ToggleUpmix(void);
    4647
    4748    virtual void Reset(void);
    4849
     50    void SetSWVolume(int new_volume, bool save);
     51    int GetSWVolume(void);
     52
    4953    // timecode is in milliseconds.
    5054    virtual bool AddSamples(char *buffer, int samples, long long timecode);
    5155    virtual bool AddSamples(char *buffers[], int samples, long long timecode);
     
    8589    virtual void WriteAudio(unsigned char *aubuf, int size) = 0;
    8690    virtual int  GetSpaceOnSoundcard(void) const = 0;
    8791    virtual int  GetBufferedOnSoundcard(void) const = 0;
     92    virtual vector<int> GetSupportedRates(void)
     93        { vector<int> rates; return rates; }
    8894    /// You need to call this from any implementation in the dtor.
    8995    void KillAudio(void);
    9096
     
    122128
    123129    // Basic details about the audio stream
    124130    int audio_channels;
     131    int audio_codec;
    125132    int audio_bytes_per_sample;
    126133    int audio_bits;
    127134    int audio_samplerate;
     
    132139    QString audio_passthru_device;
    133140
    134141    bool audio_passthru;
     142    bool audio_enc;
     143    bool audio_reenc;
    135144
    136145    float audio_stretchfactor;
    137     AVCodecContext *audio_codec;
    138146    AudioOutputSource source;
    139147
    140148    bool killaudio;
     
    144152    bool buffer_output_data_for_use; //  used by AudioOutputNULL
    145153
    146154    int configured_audio_channels;
     155    int orig_config_channels;
     156    int src_quality;
    147157
    148158 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
    149164    // resampler
    150165    bool need_resampler;
    151166    SRC_STATE *src_ctx;
     
    156171    FreeSurround              *upmixer;
    157172
    158173    int source_audio_channels;
     174    int source_audio_samplerate;
    159175    int source_audio_bytes_per_sample;
    160176    bool needs_upmix;
    161177    int surround_mode;
     178    bool allow_ac3_passthru;
     179    float old_audio_stretchfactor;
     180    int volume;
    162181
    163182    bool blocking; // do AddSamples calls block?
    164183
  • mythtv/libs/libmyth/audiooutputalsa.cpp

     
    3232AudioOutputALSA::~AudioOutputALSA()
    3333{
    3434    KillAudio();
     35    SetIECStatus(true);
    3536}
    3637
     38void AudioOutputALSA::SetIECStatus(bool audio)
     39{
     40    snd_ctl_t *ctl;
     41    const char *spdif_str = SND_CTL_NAME_IEC958("", PLAYBACK, DEFAULT);
     42    int spdif_index = -1;
     43    snd_ctl_elem_list_t *clist;
     44    snd_ctl_elem_id_t *cid;
     45    snd_ctl_elem_value_t *cval;
     46    snd_aes_iec958_t iec958;
     47    int cidx, controls;
     48
     49    VERBOSE(VB_AUDIO, QString("Setting IEC958 status: %1")
     50                      .arg(audio ? "audio" : "non-audio"));
     51
     52    int err;
     53    if ((err = snd_ctl_open(&ctl, "default", 0)) < 0)
     54    {
     55        Error(QString("AudioOutputALSA::SetIECStatus: snd_ctl_open(default): %1")
     56              .arg(snd_strerror(err)));
     57        return;
     58    }
     59    snd_ctl_elem_list_alloca(&clist);
     60    snd_ctl_elem_list(ctl, clist);
     61    snd_ctl_elem_list_alloc_space(clist, snd_ctl_elem_list_get_count(clist));
     62    snd_ctl_elem_list(ctl, clist);
     63    controls = snd_ctl_elem_list_get_used(clist);
     64    for (cidx = 0; cidx < controls; cidx++)
     65    {
     66        if (!strcmp(snd_ctl_elem_list_get_name(clist, cidx), spdif_str))
     67            if (spdif_index < 0 ||
     68                snd_ctl_elem_list_get_index(clist, cidx) == (uint)spdif_index)
     69                    break;
     70    }
     71
     72    if (cidx >= controls)
     73        return;
     74
     75    snd_ctl_elem_id_alloca(&cid);
     76    snd_ctl_elem_list_get_id(clist, cidx, cid);
     77    snd_ctl_elem_value_alloca(&cval);
     78    snd_ctl_elem_value_set_id(cval, cid);
     79    snd_ctl_elem_read(ctl,cval);
     80    snd_ctl_elem_value_get_iec958(cval, &iec958);
     81
     82    if (!audio)
     83        iec958.status[0] |= IEC958_AES0_NONAUDIO;
     84    else
     85        iec958.status[0] &= ~IEC958_AES0_NONAUDIO;
     86
     87    snd_ctl_elem_value_set_iec958(cval, &iec958);
     88    snd_ctl_elem_write(ctl, cval);
     89}
     90
     91vector<int> AudioOutputALSA::GetSupportedRates()
     92{
     93    snd_pcm_hw_params_t *params;
     94    int err;
     95    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     96    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     97    QString real_device;
     98   
     99    if (audio_passthru || audio_enc)
     100        real_device = audio_passthru_device;
     101    else
     102        real_device = audio_main_device;
     103
     104    if((err = snd_pcm_open(&pcm_handle, real_device.toAscii(),
     105                           SND_PCM_STREAM_PLAYBACK,
     106                           SND_PCM_NONBLOCK|SND_PCM_NO_AUTO_RESAMPLE)) < 0)
     107    {
     108        Error(QString("snd_pcm_open(%1): %2")
     109              .arg(real_device).arg(snd_strerror(err)));
     110
     111        if (pcm_handle)
     112        {
     113            snd_pcm_close(pcm_handle);
     114            pcm_handle = NULL;
     115        }
     116        rates.clear();
     117        return rates;
     118    }
     119   
     120    snd_pcm_hw_params_alloca(&params);
     121
     122    if ((err = snd_pcm_hw_params_any(pcm_handle, params)) < 0)
     123    {
     124        Error(QString("Broken configuration for playback; no configurations"
     125              " available: %1").arg(snd_strerror(err)));
     126        snd_pcm_close(pcm_handle);
     127        pcm_handle = NULL;
     128        rates.clear();
     129        return rates;
     130    }
     131   
     132    vector<int>::iterator it = rates.begin();
     133
     134    while (it != rates.end())
     135    {
     136        if(snd_pcm_hw_params_test_rate(pcm_handle, params, *it, 0) < 0)
     137            it = rates.erase(it);
     138        else
     139            it++;
     140    }
     141   
     142    snd_pcm_close(pcm_handle);
     143    pcm_handle = NULL;
     144
     145    return rates;
     146}
     147
    37148bool AudioOutputALSA::OpenDevice()
    38149{
    39150    snd_pcm_format_t format;
    40151    unsigned int buffer_time, period_time;
    41152    int err;
     153    QString real_device;
    42154
    43155    if (pcm_handle != NULL)
    44156        CloseDevice();
     
    46158    pcm_handle = NULL;
    47159    numbadioctls = 0;
    48160
    49     QString real_device = (audio_passthru) ?
    50         audio_passthru_device : audio_main_device;
     161    if (audio_passthru || audio_enc)
     162    {
     163        real_device = audio_passthru_device;
     164        SetIECStatus(false);
     165    }
     166    else
     167    {
     168        real_device = audio_main_device;
     169        SetIECStatus(true);
     170    }
    51171
    52172    VERBOSE(VB_GENERAL, QString("Opening ALSA audio device '%1'.")
    53173            .arg(real_device));
     
    146266    }
    147267}
    148268
     269void AudioOutputALSA::ReorderSmpteToAlsa6ch(unsigned char *buf, int size)
     270{
     271    if (audio_bits == 8)
     272        _ReorderSmpteToAlsa6ch(buf, size);
     273    else if (audio_bits == 16)
     274        _ReorderSmpteToAlsa6ch((short *)buf, size / sizeof(short));
     275}
    149276
     277template <class AudioDataType>
     278void AudioOutputALSA::_ReorderSmpteToAlsa6ch(AudioDataType *buf, int size)
     279{
     280    AudioDataType tmpC, tmpLFE;
     281
     282    for (int i = 0; i < size; i+= 6) {
     283        tmpC = buf[i+2];
     284        tmpLFE = buf[i+3];
     285        buf[i+2] = buf[i+4];
     286        buf[i+3] = buf[i+5];
     287        buf[i+4] = tmpC;
     288        buf[i+5] = tmpLFE;
     289    }
     290
     291}
    150292void AudioOutputALSA::WriteAudio(unsigned char *aubuf, int size)
    151293{
    152294    unsigned char *tmpbuf;
     
    158300        VERBOSE(VB_IMPORTANT, QString("WriteAudio() called with pcm_handle == NULL!"));
    159301        return;
    160302    }
     303
     304    if (!(audio_passthru || audio_enc) && audio_channels == 6)
     305        ReorderSmpteToAlsa6ch(aubuf, size);
    161306   
    162307    tmpbuf = aubuf;
    163308
     
    634779    if (mixer_handle != NULL)
    635780        CloseMixer();
    636781
     782    if (alsadevice.toLower() == "software")
     783        return;
     784
    637785    VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device));
    638786
    639787    // TODO: This is opening card 0. Fix for case of multiple soundcards
  • mythtv/libs/libmyth/volumebase.cpp

     
    1010    internal_vol(false), volume(80),
    1111    current_mute_state(kMuteOff)
    1212{
     13    swvol = swvol_setting =
     14        (gContext->GetSetting("MixerDevice", "default").toLower() == "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
    1529uint VolumeBase::GetCurrentVolume(void) const
    1630{
    1731    return volume;
     
    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;
    8298    }
     99
     100    if (swvol)
     101    {
     102        SetSWVolume(new_volume, save);
     103        return;
     104    }
    83105   
    84106    // TODO: Avoid assumption that there are 2 channels!
    85107    for (int i = 0; i < 2; i++)
     
    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
  • mythtv/libs/libmyth/audiooutputjack.cpp

     
    3030    Reconfigure(settings);
    3131}
    3232
     33vector<int> AudioOutputJACK::GetSupportedRates()
     34{
     35    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     36    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     37    unsigned long jack_port_flags = 0;
     38    unsigned int jack_port_name_count = 1;
     39    const char *jack_port_name = audio_main_device.toAscii();
     40    int err = -1;
     41    audioid = -1;
     42    vector<int>::iterator it = rates.begin();
     43
     44    while (it != rates.end())
     45    {
     46        unsigned long lrate = (unsigned long) *it;
     47        err = JACK_OpenEx(&audioid, 16, &lrate,
     48                          2, 2, &jack_port_name, jack_port_name_count,
     49                          jack_port_flags);
     50
     51        if (err == ERR_OPENING_JACK)
     52        {
     53            Error(QString("Error connecting to jackd: %1. Is it running?")
     54                  .arg(audio_main_device));
     55            rates.clear();
     56            return rates;
     57        }
     58        else
     59            if (err == ERR_RATE_MISMATCH)
     60                it = rates.erase(it);
     61            else
     62                it++;
     63
     64        JACK_Close(audioid);
     65        audioid = -1;
     66    }
     67    return rates;
     68}
     69
     70
    3371AudioOutputJACK::~AudioOutputJACK()
    3472{
    3573    // Close down all audio stuff
  • mythtv/libs/libmyth/audiooutputoss.h

     
    2323    virtual void WriteAudio(unsigned char *aubuf, int size);
    2424    virtual int  GetSpaceOnSoundcard(void) const;
    2525    virtual int  GetBufferedOnSoundcard(void) const;
     26    vector<int> GetSupportedRates(void);
    2627
    2728  private:
    2829    void VolumeInit(void);
  • mythtv/libs/libmyth/audiooutputbase.cpp

     
    11// Std C headers
    22#include <cmath>
     3#include <limits>
    34
    45// POSIX headers
    56#include <unistd.h>
     
    2122AudioOutputBase::AudioOutputBase(const AudioSettings &settings) :
    2223    // protected
    2324    effdsp(0),                  effdspstretched(0),
    24     audio_channels(-1),         audio_bytes_per_sample(0),
    25     audio_bits(-1),             audio_samplerate(-1),
    26     audio_buffer_unused(0),
     25    audio_channels(-1),         audio_codec(CODEC_ID_NONE),
     26    audio_bytes_per_sample(0),  audio_bits(-1),
     27    audio_samplerate(-1),       audio_buffer_unused(0),
    2728    fragment_size(0),           soundcard_buffer_size(0),
    2829
    2930    audio_main_device(settings.GetMainDevice()),
    3031    audio_passthru_device(settings.GetPassthruDevice()),
    31     audio_passthru(false),      audio_stretchfactor(1.0f),
     32    audio_passthru(false),      audio_enc(false),
     33    audio_reenc(false),         audio_stretchfactor(1.0f),
    3234
    33     audio_codec(NULL),
    3435    source(settings.source),    killaudio(false),
    3536
    3637    pauseaudio(false),          audio_actually_paused(false),
     
    4849    encoder(NULL),
    4950    upmixer(NULL),
    5051    source_audio_channels(-1),
     52    source_audio_samplerate(0),
    5153    source_audio_bytes_per_sample(0),
    5254    needs_upmix(false),
    5355    surround_mode(FreeSurround::SurroundModePassive),
     56    old_audio_stretchfactor(1.0),
     57    volume(80),
    5458
    5559    blocking(false),
    5660
     
    6266    raud(0),                    waud(0),
    6367    audbuf_timecode(0),
    6468
    65     numlowbuffer(0),            killAudioLock(QMutex::NonRecursive),
     69    killAudioLock(QMutex::NonRecursive),
    6670    current_seconds(-1),        source_bitrate(-1),
    6771
    6872    memory_corruption_test0(0xdeadbeef),
     
    7882    memset(tmp_buff,           0, sizeof(short) * kAudioTempBufSize);
    7983    memset(&audiotime_updated, 0, sizeof(audiotime_updated));
    8084    memset(audiobuffer,        0, sizeof(char)  * kAudioRingBufferSize);
    81     configured_audio_channels = gContext->GetNumSetting("MaxChannels", 2);
     85    orig_config_channels = gContext->GetNumSetting("MaxChannels", 2);
     86    src_quality = gContext->GetNumSetting("AudioUpmixType", 2);
     87    if (!settings.upmixer)
     88        configured_audio_channels = gContext->GetNumSetting("AudioDefaultUpmix", false) ? orig_config_channels : 2;
     89    else
     90        if (settings.upmixer == 1)
     91            configured_audio_channels = 2;
     92        else
     93            configured_audio_channels = 6;
    8294
     95    allow_ac3_passthru = (orig_config_channels > 2) ? gContext->GetNumSetting("AC3PassThru", false) : false;
     96
    8397    // You need to call Reconfigure from your concrete class.
    8498    // Reconfigure(laudio_bits,       laudio_channels,
    8599    //             laudio_samplerate, laudio_passthru);
     
    124138            VERBOSE(VB_GENERAL, LOC + QString("Using time stretch %1")
    125139                                        .arg(audio_stretchfactor));
    126140            pSoundStretch = new soundtouch::SoundTouch();
    127             if (audio_codec)
    128             {
    129                 if (!encoder)
    130                 {
    131                     VERBOSE(VB_AUDIO, LOC +
    132                             QString("Creating Encoder for codec %1 origfs %2")
    133                             .arg(audio_codec->codec_id)
    134                             .arg(audio_codec->frame_size));
     141            pSoundStretch->setSampleRate(audio_samplerate);
     142            pSoundStretch->setChannels(upmixer ?
     143                configured_audio_channels : source_audio_channels);
    135144
    136                     encoder = new AudioOutputDigitalEncoder();
    137                     if (!encoder->Init(audio_codec->codec_id,
    138                                 audio_codec->bit_rate,
    139                                 audio_codec->sample_rate,
    140                                 audio_codec->channels
    141                                 ))
    142                     {
    143                         // eeks
    144                         delete encoder;
    145                         encoder = NULL;
    146                         VERBOSE(VB_AUDIO, LOC +
    147                                 QString("Failed to Create Encoder"));
    148                     }
    149                 }
    150             }
    151             if (audio_codec && encoder)
    152             {
    153                 pSoundStretch->setSampleRate(audio_codec->sample_rate);
    154                 pSoundStretch->setChannels(audio_codec->channels);
    155             }
    156             else
    157             {
    158                 pSoundStretch->setSampleRate(audio_samplerate);
    159                 pSoundStretch->setChannels(audio_channels);
    160             }
    161 
    162145            pSoundStretch->setTempo(audio_stretchfactor);
    163146            pSoundStretch->setSetting(SETTING_SEQUENCE_MS, 35);
    164147
    165148            // dont need these with only tempo change
    166149            //pSoundStretch->setPitch(1.0);
    167150            //pSoundStretch->setRate(1.0);
    168 
    169151            //pSoundStretch->setSetting(SETTING_USE_QUICKSEEK, true);
    170152            //pSoundStretch->setSetting(SETTING_USE_AA_FILTER, false);
    171153        }
     
    183165    return audio_stretchfactor;
    184166}
    185167
     168bool AudioOutputBase::ToggleUpmix(void)
     169{
     170    if (orig_config_channels == 2 || source_audio_channels > 2 ||
     171        audio_passthru)
     172        return false;
     173    if (configured_audio_channels == 6)
     174        configured_audio_channels = 2;
     175    else
     176        configured_audio_channels = 6;
     177
     178    const AudioSettings settings(audio_bits, source_audio_channels,
     179                                 audio_codec, source_audio_samplerate,
     180                                 audio_passthru);
     181    Reconfigure(settings);
     182    return (configured_audio_channels == 6);
     183}
     184
     185
    186186void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
    187187{
    188188    AudioSettings settings = orig_settings;
    189189
    190     int codec_id = CODEC_ID_NONE;
    191     int lcodec_id = CODEC_ID_NONE;
    192     int lcchannels = 0;
    193     int cchannels = 0;
    194190    int lsource_audio_channels = settings.channels;
    195191    bool lneeds_upmix = false;
     192    bool laudio_reenc = false;
    196193
    197     if (settings.codec)
     194    // Are we reencoding a (previously) timestretched bitstream?
     195    if ((settings.codec == CODEC_ID_AC3 || settings.codec == CODEC_ID_DTS) &&
     196        !settings.use_passthru && allow_ac3_passthru)
    198197    {
    199         lcodec_id = ((AVCodecContext*)settings.codec)->codec_id;
    200         settings.bits = 16;
    201         settings.channels = 2;
    202         lsource_audio_channels = settings.channels;
    203         settings.samplerate = 48000;
    204         lcchannels = ((AVCodecContext*)settings.codec)->channels;
     198        laudio_reenc = true;
     199        VERBOSE(VB_AUDIO, LOC + "Reencoding decoded AC3/DTS to AC3");
    205200    }
    206201
    207     if (audio_codec)
     202    // Enough channels? Upmix if not
     203    if (settings.channels < configured_audio_channels &&
     204        !settings.use_passthru)
    208205    {
    209         codec_id = audio_codec->codec_id;
    210         cchannels = ((AVCodecContext*)audio_codec)->channels;
    211     }
    212 
    213     if ((configured_audio_channels == 6) &&
    214         !(settings.codec || audio_codec))
    215     {
    216206        settings.channels = configured_audio_channels;
    217207        lneeds_upmix = true;
    218208        VERBOSE(VB_AUDIO,LOC + "Needs upmix");
     
    224214        settings.samplerate == audio_samplerate && !need_resampler &&
    225215        settings.use_passthru == audio_passthru &&
    226216        lneeds_upmix == needs_upmix &&
    227         lcodec_id == codec_id && lcchannels == cchannels);
     217        laudio_reenc == audio_reenc);
    228218    bool upmix_deps =
    229219        (lsource_audio_channels == source_audio_channels);
    230220    if (general_deps && upmix_deps)
     
    251241    waud = raud = 0;
    252242    audio_actually_paused = false;
    253243
    254     bool redo_stretch = (pSoundStretch && audio_channels != settings.channels);
    255244    audio_channels = settings.channels;
    256245    source_audio_channels = lsource_audio_channels;
    257246    audio_bits = settings.bits;
    258     audio_samplerate = settings.samplerate;
    259     audio_codec = (AVCodecContext*)settings.codec;
     247    source_audio_samplerate = audio_samplerate = settings.samplerate;
     248    audio_reenc = laudio_reenc;
     249    audio_codec = settings.codec;
    260250    audio_passthru = settings.use_passthru;
    261251    needs_upmix = lneeds_upmix;
    262252
     
    265255        Error("AudioOutput only supports 8 or 16bit audio.");
    266256        return;
    267257    }
    268     audio_bytes_per_sample = audio_channels * audio_bits / 8;
    269     source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
     258   
     259    VERBOSE(VB_AUDIO, LOC + QString("Original audio codec was %1")
     260                            .arg(codec_id_string((CodecID)audio_codec)));
    270261
    271262    need_resampler = false;
    272263    killaudio = false;
     
    274265    was_paused = true;
    275266    internal_vol = gContext->GetNumSetting("MythControlsVolume", 0);
    276267
    277     numlowbuffer = 0;
     268    // Find out what sample rates we can output (if output layer supports it)
     269    vector<int> rates = GetSupportedRates();
     270    vector<int>::iterator it;
     271    bool resample = true;
    278272
    279     VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4")
     273    for (it = rates.begin(); it < rates.end(); it++)
     274    {
     275        VERBOSE(VB_AUDIO, LOC + QString("Sample rate %1 is supported")
     276                                .arg(*it));
     277        if (*it == audio_samplerate)
     278            resample = false;
     279    }
     280
     281    // Assume 48k if we can't get supported rates
     282    if (rates.empty())
     283        rates.push_back(48000);
     284
     285    if (resample)
     286    {
     287        int error;
     288        audio_samplerate = *(rates.end());
     289        VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
     290            .arg(settings.samplerate).arg(audio_samplerate));
     291        src_ctx = src_new(2-src_quality, source_audio_channels, &error);
     292        if (error)
     293        {
     294            Error(QString("Error creating resampler, the error was: %1")
     295                  .arg(src_strerror(error)) );
     296            src_ctx = NULL;
     297            return;
     298        }
     299        src_data.src_ratio = (double) audio_samplerate / settings.samplerate;
     300        src_data.data_in = src_in;
     301        src_data.data_out = src_out;
     302        src_data.output_frames = 16384*6;
     303        need_resampler = true;
     304    }
     305   
     306    // Encode to AC-3 if not passing thru , there's > 2 channels
     307    // and a passthru device is defined
     308    if (!audio_passthru && allow_ac3_passthru &&
     309        (audio_channels > 2 || audio_reenc))
     310    {
     311        VERBOSE(VB_AUDIO, LOC + "Creating AC-3 Encoder");
     312        encoder = new AudioOutputDigitalEncoder();
     313        if (!encoder->Init(CODEC_ID_AC3, 448000, audio_samplerate, audio_channels))
     314        {
     315            VERBOSE(VB_AUDIO, LOC + "Can't create AC-3 encoder");
     316            delete encoder;
     317            encoder = NULL;
     318        }
     319
     320        audio_enc = true;
     321    }
     322
     323    if(audio_passthru || audio_enc)
     324        // AC-3 output - soundcard expects a 2ch 48k stream
     325        audio_channels = 2;
     326
     327    audio_bytes_per_sample = audio_channels * audio_bits / 8;
     328    source_audio_bytes_per_sample = source_audio_channels * audio_bits / 8;
     329
     330    VERBOSE(VB_GENERAL, QString("Opening audio device '%1'. ch %2(%3) sr %4 (reenc %5)")
    280331            .arg(audio_main_device).arg(audio_channels)
    281             .arg(source_audio_channels).arg(audio_samplerate));
     332            .arg(source_audio_channels).arg(audio_samplerate).arg(audio_reenc));
    282333
    283334    // Actually do the device specific open call
    284335    if (!OpenDevice())
     
    290341        return;
    291342    }
    292343
     344    // Only used for software volume
     345    if (set_initial_vol && internal_vol)
     346        volume = gContext->GetNumSetting("PCMMixerVolume", 80);
     347    {
     348        QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
     349        controlLabel += "MixerVolume";
     350        volume = gContext->GetNumSetting(controlLabel, 80);
     351    }
     352
    293353    SyncVolume();
    294354
    295355    VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1")
    296356            .arg(fragment_size));
    297357
    298     if (audio_buffer_unused < 0)
    299         audio_buffer_unused = 0;
     358    audio_buffer_unused = 0;
    300359
    301     if (!gContext->GetNumSetting("AggressiveSoundcardBuffer", 0))
    302         audio_buffer_unused = 0;
    303 
    304360    audbuf_timecode = 0;
    305361    audiotime = 0;
    306362    samples_buffered = 0;
     
    309365    current_seconds = -1;
    310366    source_bitrate = -1;
    311367
    312     // NOTE: this won't do anything as above samplerate vars are set equal
    313     // Check if we need the resampler
    314     if (audio_samplerate != settings.samplerate)
    315     {
    316         int error;
    317         VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
    318                                .arg(settings.samplerate).arg(audio_samplerate));
    319         src_ctx = src_new (SRC_SINC_BEST_QUALITY, audio_channels, &error);
    320         if (error)
    321         {
    322             Error(QString("Error creating resampler, the error was: %1")
    323                   .arg(src_strerror(error)) );
    324             return;
    325         }
    326         src_data.src_ratio = (double) audio_samplerate / settings.samplerate;
    327         src_data.data_in = src_in;
    328         src_data.data_out = src_out;
    329         src_data.output_frames = 16384*6;
    330         need_resampler = true;
    331     }
    332 
    333368    if (needs_upmix)
    334369    {
    335370        VERBOSE(VB_AUDIO, LOC + QString("create upmixer"));
     
    344379            (FreeSurround::SurroundMode)surround_mode);
    345380
    346381        VERBOSE(VB_AUDIO, LOC +
    347                 QString("create upmixer done with surround mode %1")
     382                QString("Create upmixer done with surround mode %1")
    348383                .arg(surround_mode));
    349384    }
    350385
    351386    VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1")
    352387            .arg(audio_stretchfactor));
    353     VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1")
    354             .arg((audio_codec) ?
    355                  codec_id_string(audio_codec->codec_id) : "not set"));
    356388
    357     if (redo_stretch)
    358     {
    359         delete pSoundStretch;
    360         pSoundStretch = NULL;
    361         SetStretchFactorLocked(audio_stretchfactor);
    362     }
    363     else
    364     {
    365         SetStretchFactorLocked(audio_stretchfactor);
    366         if (pSoundStretch)
    367         {
    368             // if its passthru then we need to reencode
    369             if (audio_codec)
    370             {
    371                 if (!encoder)
    372                 {
    373                     VERBOSE(VB_AUDIO, LOC +
    374                             QString("Creating Encoder for codec %1")
    375                             .arg(audio_codec->codec_id));
    376 
    377                     encoder = new AudioOutputDigitalEncoder();
    378                     if (!encoder->Init(audio_codec->codec_id,
    379                                 audio_codec->bit_rate,
    380                                 audio_codec->sample_rate,
    381                                 audio_codec->channels
    382                                 ))
    383                     {
    384                         // eeks
    385                         delete encoder;
    386                         encoder = NULL;
    387                         VERBOSE(VB_AUDIO, LOC + "Failed to Create Encoder");
    388                     }
    389                 }
    390             }
    391             if (audio_codec && encoder)
    392             {
    393                 pSoundStretch->setSampleRate(audio_codec->sample_rate);
    394                 pSoundStretch->setChannels(audio_codec->channels);
    395             }
    396             else
    397             {
    398                 pSoundStretch->setSampleRate(audio_samplerate);
    399                 pSoundStretch->setChannels(audio_channels);
    400             }
    401         }
    402     }
    403 
     389    SetStretchFactorLocked(old_audio_stretchfactor);
     390   
    404391    // Setup visualisations, zero the visualisations buffers
    405392    prepareVisuals();
    406393
     
    436423    VERBOSE(VB_AUDIO, LOC + "Killing AudioOutputDSP");
    437424    killaudio = true;
    438425    StopOutputThread();
     426    QMutexLocker lock1(&audio_buflock);
    439427
    440428    // Close resampler?
    441429    if (src_ctx)
     430    {
    442431        src_delete(src_ctx);
     432        src_ctx = NULL;
     433    }
     434
    443435    need_resampler = false;
    444436
    445437    // close sound stretcher
     
    447439    {
    448440        delete pSoundStretch;
    449441        pSoundStretch = NULL;
     442        old_audio_stretchfactor = audio_stretchfactor;
     443        audio_stretchfactor = 1.0;
    450444    }
    451445
    452446    if (encoder)
     
    461455        upmixer = NULL;
    462456    }
    463457    needs_upmix = false;
     458    audio_enc = false;
    464459
    465460    CloseDevice();
    466461
     
    611606
    612607    // include algorithmic latencies
    613608    if (pSoundStretch)
    614     {
    615         // add the effect of any unused but processed samples,
    616         // AC3 reencode does this
    617         totalbuffer += (int)(pSoundStretch->numSamples() *
    618                              audio_bytes_per_sample);
    619         // add the effect of unprocessed samples in time stretch algo
    620609        totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() *
    621610                              audio_bytes_per_sample) / audio_stretchfactor);
    622     }
    623611
    624612    if (upmixer && needs_upmix)
    625     {
    626613        totalbuffer += upmixer->sampleLatency() * audio_bytes_per_sample;
    627     }
    628614
     615    if (encoder)
     616         totalbuffer += encoder->Buffered();
     617
    629618    audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 /
    630619                                   (audio_bytes_per_sample * effdspstretched));
    631620
     
    650639     return audbuf_timecode - GetAudiotime();
    651640}
    652641
     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
    653699bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    654700                                 long long timecode)
    655701{
     
    681727        return false; // would overflow
    682728    }
    683729
     730    QMutexLocker lock1(&audio_buflock);
     731
    684732    // resample input if necessary
    685733    if (need_resampler && src_ctx)
    686734    {
     
    725773    int abps = (encoder) ?
    726774        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    727775    int len = samples * abps;
     776   
     777    // Give original samples to mythmusic visualisation
     778    dispatchVisual((unsigned char *)buffer, len, timecode,
     779                   source_audio_channels, audio_bits);
    728780
    729781    // Check we have enough space to write the data
    730782    if (need_resampler && src_ctx)
     
    749801        return false; // would overflow
    750802    }
    751803
     804    QMutexLocker lock1(&audio_buflock);
     805
    752806    // resample input if necessary
    753807    if (need_resampler && src_ctx)
    754808    {
     
    809863            {
    810864                int error = src_reset(src_ctx);
    811865                if (error)
     866                {
    812867                    VERBOSE(VB_IMPORTANT, LOC_ERR + QString(
    813868                            "Error occured while resetting resampler: %1")
    814869                            .arg(src_strerror(error)));
     870                    src_ctx = NULL;
     871                }
    815872            }
    816873        }
    817874    }
     
    821878void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples,
    822879                                  long long timecode)
    823880{
    824     audio_buflock.lock();
    825 
    826881    int len; // = samples * audio_bytes_per_sample;
    827882    int audio_bytes = audio_bits / 8;
    828883    int org_waud = waud;
     
    839894            .arg(samples * abps)
    840895            .arg(kAudioRingBufferSize-afree).arg(afree).arg(timecode)
    841896            .arg(needs_upmix));
    842 
     897   
     898    len = WaitForFreeSpace(samples);
     899       
    843900    if (upmixer && needs_upmix)
    844901    {
    845902        int out_samples = 0;
     903        org_waud = waud;
    846904        int step = (interleaved)?source_audio_channels:1;
    847         len = WaitForFreeSpace(samples);    // test
     905       
    848906        for (int itemp = 0; itemp < samples; )
    849907        {
    850             // just in case it does a processing cycle, release the lock
    851             // to allow the output loop to do output
    852             audio_buflock.unlock();
    853908            if (audio_bytes == 2)
    854909            {
    855910                itemp += upmixer->putSamples(
     
    866921                    source_audio_channels,
    867922                    (interleaved) ? 0 : samples);
    868923            }
    869             audio_buflock.lock();
    870924
    871925            int copy_samples = upmixer->numSamples();
    872926            if (copy_samples)
     
    900954    }
    901955    else
    902956    {
    903         len = WaitForFreeSpace(samples);
    904 
    905957        if (interleaved)
    906958        {
    907959            char *mybuf = (char*)buffer;
     
    936988        }
    937989    }
    938990
    939     if (samples > 0)
     991    if (samples <= 0)
     992        return;
     993       
     994    if (pSoundStretch)
    940995    {
    941         if (pSoundStretch)
     996        // does not change the timecode, only the number of samples
     997        // back to orig pos
     998        org_waud = waud;
     999        int bdiff = kAudioRingBufferSize - org_waud;
     1000        int nSamplesToEnd = bdiff/abps;
     1001        if (bdiff < len)
    9421002        {
     1003            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     1004                                      (audiobuffer +
     1005                                       org_waud), nSamplesToEnd);
     1006            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
     1007                                      (len - bdiff) / abps);
     1008        }
     1009        else
     1010        {
     1011            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     1012                                      (audiobuffer + org_waud),
     1013                                      len / abps);
     1014        }
    9431015
    944             // does not change the timecode, only the number of samples
    945             // back to orig pos
    946             org_waud = waud;
    947             int bdiff = kAudioRingBufferSize - org_waud;
    948             int nSamplesToEnd = bdiff/abps;
    949             if (bdiff < len)
    950             {
    951                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    952                                           (audiobuffer +
    953                                            org_waud), nSamplesToEnd);
    954                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
    955                                           (len - bdiff) / abps);
     1016        int nSamples = pSoundStretch->numSamples();
     1017        len = WaitForFreeSpace(nSamples);
     1018       
     1019        while ((nSamples = pSoundStretch->numSamples()))
     1020        {
     1021            if (nSamples > nSamplesToEnd)
     1022                nSamples = nSamplesToEnd;
     1023           
     1024            nSamples = pSoundStretch->receiveSamples(
     1025                (soundtouch::SAMPLETYPE*)
     1026                (audiobuffer + org_waud), nSamples
     1027            );
     1028           
     1029            if (nSamples == nSamplesToEnd) {
     1030                org_waud = 0;
     1031                nSamplesToEnd = kAudioRingBufferSize/abps;
    9561032            }
    957             else
    958             {
    959                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    960                                           (audiobuffer + org_waud),
    961                                           len / abps);
     1033            else {
     1034                org_waud += nSamples * abps;
     1035                nSamplesToEnd -= nSamples;
    9621036            }
     1037        }
     1038    }
    9631039
    964             if (encoder)
    965             {
    966                 // pull out a packet's worth and reencode it until we
    967                 // don't have enough for any more packets
    968                 soundtouch::SAMPLETYPE *temp_buff =
    969                     (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer();
    970                 size_t frameSize = encoder->FrameSize()/abps;
     1040    if (internal_vol && SWVolume())
     1041    {
     1042        int bdiff = kAudioRingBufferSize - waud;
     1043        bool music = (timecode < 1);
    9711044
    972                 VERBOSE(VB_AUDIO+VB_TIMESTAMP,
    973                         QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3")
    974                         .arg(frameSize)
    975                         .arg(encoder->FrameSize())
    976                         .arg(pSoundStretch->numSamples()));
    977 
    978                 // process the same number of samples as it creates
    979                 // a full encoded buffer just like before
    980                 while (pSoundStretch->numSamples() >= frameSize)
    981                 {
    982                     int got = pSoundStretch->receiveSamples(
    983                         temp_buff, frameSize);
    984                     int amount = encoder->Encode(temp_buff);
    985 
    986                     VERBOSE(VB_AUDIO+VB_TIMESTAMP,
    987                             QString("_AddSamples Enc bytes=%1 got=%2 left=%3")
    988                             .arg(amount)
    989                             .arg(got)
    990                             .arg(pSoundStretch->numSamples()));
    991 
    992                     if (!amount)
    993                         continue;
    994 
    995                     //len = WaitForFreeSpace(amount);
    996                     char *ob = encoder->GetOutBuff();
    997                     if (amount >= bdiff)
    998                     {
    999                         memcpy(audiobuffer + org_waud, ob, bdiff);
    1000                         ob += bdiff;
    1001                         amount -= bdiff;
    1002                         org_waud = 0;
    1003                     }
    1004                     if (amount > 0)
    1005                         memcpy(audiobuffer + org_waud, ob, amount);
    1006 
    1007                     bdiff = kAudioRingBufferSize - amount;
    1008                     org_waud = (org_waud + amount) % kAudioRingBufferSize;
    1009                 }
    1010             }
    1011             else
    1012             {
    1013                 int newLen = 0;
    1014                 int nSamples;
    1015                 len = WaitForFreeSpace(pSoundStretch->numSamples() *
    1016                                        audio_bytes_per_sample);
    1017                 do
    1018                 {
    1019                     int samplesToGet = len/audio_bytes_per_sample;
    1020                     if (samplesToGet > nSamplesToEnd)
    1021                     {
    1022                         samplesToGet = nSamplesToEnd;
    1023                     }
    1024 
    1025                     nSamples = pSoundStretch->receiveSamples(
    1026                         (soundtouch::SAMPLETYPE*)
    1027                         (audiobuffer + org_waud), samplesToGet);
    1028                     if (nSamples == nSamplesToEnd)
    1029                     {
    1030                         org_waud = 0;
    1031                         nSamplesToEnd = kAudioRingBufferSize/audio_bytes_per_sample;
    1032                     }
    1033                     else
    1034                     {
    1035                         int bufsz = nSamples * audio_bytes_per_sample;
    1036                         org_waud = (org_waud + bufsz) % kAudioRingBufferSize;
    1037                         nSamplesToEnd -= nSamples;
    1038                     }
    1039 
    1040                     newLen += nSamples * audio_bytes_per_sample;
    1041                     len -= nSamples * audio_bytes_per_sample;
    1042                 } while (nSamples > 0);
    1043             }
     1045        if (bdiff < len)
     1046        {
     1047            AdjustVolume(audiobuffer + waud, bdiff, music);
     1048            AdjustVolume(audiobuffer, len - bdiff, music);
    10441049        }
     1050        else
     1051            AdjustVolume(audiobuffer + waud, len, music);
     1052    }
    10451053
    1046         waud = org_waud;
    1047         lastaudiolen = audiolen(false);
     1054    // Encode to AC-3?
     1055    if (encoder)
     1056    {
     1057        org_waud = waud;
     1058        int bdiff = kAudioRingBufferSize - org_waud;
     1059        int to_get = 0;
    10481060
    1049         if (timecode < 0)
     1061        if (bdiff < len)
    10501062        {
    1051             // mythmusic doesn't give timestamps..
    1052             timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1063            encoder->Encode(audiobuffer + org_waud, bdiff);
     1064            to_get = encoder->Encode(audiobuffer, len - bdiff);
    10531065        }
    1054  
    1055         samples_buffered += samples;
    1056  
    1057         /* we want the time at the end -- but the file format stores
    1058            time at the start of the chunk. */
    1059         // even with timestretch, timecode is still calculated from original
    1060         // sample count
    1061         audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
     1066        else
     1067            to_get = encoder->Encode(audiobuffer + org_waud, len);
    10621068
    1063         if (interleaved)
     1069        if (to_get > 0)
    10641070        {
    1065             dispatchVisual((unsigned char *)buffer, len, timecode,
    1066                            source_audio_channels, audio_bits);
     1071            if (to_get >= bdiff)
     1072            {
     1073                encoder->GetFrames(audiobuffer + org_waud, bdiff);
     1074                to_get -= bdiff;
     1075                org_waud = 0;
     1076            }
     1077            if (to_get > 0)
     1078                encoder->GetFrames(audiobuffer + org_waud, to_get);
     1079
     1080            org_waud += to_get;
    10671081        }
    10681082    }
    10691083
    1070     audio_buflock.unlock();
     1084    waud = org_waud;
     1085    lastaudiolen = audiolen(false);
     1086
     1087    if (timecode < 0)
     1088        // mythmusic doesn't give timestamps..
     1089        timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1090
     1091    samples_buffered += samples;
     1092
     1093    /* we want the time at the end -- but the file format stores
     1094       time at the start of the chunk. */
     1095    // even with timestretch, timecode is still calculated from original
     1096    // sample count
     1097    audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
    10711098}
    10721099
    10731100void AudioOutputBase::Status()
     
    12081235                last_space_on_soundcard = space_on_soundcard;
    12091236            }
    12101237
    1211             numlowbuffer++;
    1212             if (numlowbuffer > 5 && audio_buffer_unused)
    1213             {
    1214                 VERBOSE(VB_IMPORTANT, LOC + "dropping back audio_buffer_unused");
    1215                 audio_buffer_unused /= 2;
    1216             }
    1217 
    12181238            usleep(5000);
    12191239            continue;
    12201240        }
    1221         else
    1222             numlowbuffer = 0;
    12231241
    12241242        Status();
    12251243
  • mythtv/libs/libmyth/audiooutput.cpp

     
    3333AudioOutput *AudioOutput::OpenAudio(
    3434    const QString &main_device,
    3535    const QString &passthru_device,
    36     int audio_bits, int audio_channels, int audio_samplerate,
     36    int audio_bits, int audio_channels,
     37    int audio_codec, int audio_samplerate,
    3738    AudioOutputSource source,
    38     bool set_initial_vol, bool audio_passthru)
     39    bool set_initial_vol, bool audio_passthru,
     40    int upmixer_startup)
    3941{
    4042    AudioSettings settings(
    4143        main_device, passthru_device, audio_bits,
    42         audio_channels, audio_samplerate, source,
    43         set_initial_vol, audio_passthru);
     44        audio_channels, audio_codec, audio_samplerate, source,
     45        set_initial_vol, audio_passthru, upmixer_startup);
    4446
    4547    settings.FixPassThrough();
    4648
  • mythtv/libs/libmyth/audiosettings.h

     
    2929        const QString    &audio_passthru_device,
    3030        int               audio_bits,
    3131        int               audio_channels,
     32        int               audio_codec,
    3233        int               audio_samplerate,
    3334        AudioOutputSource audio_source,
    3435        bool              audio_set_initial_vol,
    3536        bool              audio_use_passthru,
    36         void             *audio_codec = NULL);
     37        int               upmixer_startup = 0);
    3738
    3839    AudioSettings(int   audio_bits,
    3940                  int   audio_channels,
     41                  int   audio_codec,
    4042                  int   audio_samplerate,
    4143                  bool  audio_use_passthru,
    42                   void *audio_codec = NULL);
     44                  int   upmixer_startup = 0);
    4345
    4446    void FixPassThrough(void);
    4547    void TrimDeviceType(void);
     
    5456  public:
    5557    int     bits;
    5658    int     channels;
     59    int     codec;
    5760    int     samplerate;
    5861    bool    set_initial_vol;
    5962    bool    use_passthru;
    60     void   *codec;
    6163    AudioOutputSource source;
     64    int     upmixer;
    6265};
    6366
    6467#endif // _AUDIO_SETTINGS_H_
  • mythtv/libs/libmyth/audiooutputoss.cpp

     
    4242    KillAudio();
    4343}
    4444
     45vector<int> AudioOutputOSS::GetSupportedRates()
     46{
     47    const int srates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000 };
     48    vector<int> rates(srates, srates + sizeof(srates) / sizeof(int) );
     49    audiofd = open(audio_main_device.toAscii(), O_WRONLY | O_NONBLOCK);
     50
     51    if (audiofd < 0)
     52    {
     53        VERBOSE(VB_IMPORTANT, QString("Error opening audio device (%1), the"
     54                " error was: %2").arg(audio_main_device).arg(strerror(errno)));
     55        rates.clear();
     56        return rates;
     57    }
     58
     59    vector<int>::iterator it = rates.begin();
     60
     61    while (it != rates.end())
     62    {
     63        if(ioctl(audiofd, SNDCTL_DSP_SPEED, &audio_samplerate) < 0)
     64            it = rates.erase(it);
     65        else
     66            it++;
     67    }
     68
     69    close(audiofd);
     70    audiofd = -1;
     71
     72    return rates;
     73}
     74
    4575bool AudioOutputOSS::OpenDevice()
    4676{
    4777    numbadioctls = 0;
     
    287317    int volume = 0;
    288318
    289319    QString device = gContext->GetSetting("MixerDevice", "/dev/mixer");
     320    if (device.toLower() == "software")
     321        return;
     322
    290323    QByteArray dev = device.toAscii();
    291324    mixerfd = open(dev.constData(), O_RDONLY);
    292325
  • mythtv/libs/libmyth/volumebase.h

     
    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
  • mythtv/libs/libmyth/audiooutputdigitalencoder.cpp

     
    3232AudioOutputDigitalEncoder::AudioOutputDigitalEncoder(void) :
    3333    audio_bytes_per_sample(0),
    3434    av_context(NULL),
    35     outbuf(NULL),
    36     outbuf_size(0),
    37     frame_buffer(NULL),
     35    outbuflen(0),
     36    inbuflen(0),
    3837    one_frame_bytes(0)
    3938{
    4039}
     
    5251        av_free(av_context);
    5352        av_context = NULL;
    5453    }
    55 
    56     if (outbuf)
    57     {
    58         delete [] outbuf;
    59         outbuf = NULL;
    60         outbuf_size = 0;
    61     }
    62 
    63     if (frame_buffer)
    64     {
    65         delete [] frame_buffer;
    66         frame_buffer = NULL;
    67         one_frame_bytes = 0;
    68     }
    6954}
    7055
    7156//CODEC_ID_AC3
     
    8166            .arg(samplerate)
    8267            .arg(channels));
    8368
    84     //codec = avcodec_find_encoder(codec_id);
     69    // We need to do this when called from mythmusic
     70    avcodec_init();
     71    avcodec_register_all();
    8572    // always AC3 as there is no DTS encoder at the moment 2005/1/9
    8673    codec = avcodec_find_encoder(CODEC_ID_AC3);
    8774    if (!codec)
     
    11097    audio_bytes_per_sample = bytes_per_frame;
    11198    one_frame_bytes = bytes_per_frame * av_context->frame_size;
    11299
    113     outbuf_size = 16384;    // ok for AC3 but DTS?
    114     outbuf = new char [outbuf_size];
    115100    VERBOSE(VB_AUDIO, QString("DigitalEncoder::Init fs=%1, bpf=%2 ofb=%3")
    116101            .arg(av_context->frame_size)
    117102            .arg(bytes_per_frame)
     
    259244static int encode_frame(
    260245        bool dts,
    261246        unsigned char *data,
    262         size_t &len)
     247        size_t enc_len)
    263248{
    264249    unsigned char *payload = data + 8;  // skip header, currently 52 or 54bits
    265     size_t         enc_len;
    266250    int            flags, sample_rate, bit_rate;
    267251
    268252    // we don't do any length/crc validation of the AC3 frame here; presumably
     
    273257    // ignore, and if so, may as well just assume that it will ignore
    274258    // anything with a bad CRC...
    275259
    276     uint nr_samples = 0, block_len;
     260    uint nr_samples = 0, block_len = 0;
     261
    277262    if (dts)
    278263    {
    279264        enc_len = dts_syncinfo(payload, &flags, &sample_rate, &bit_rate);
     
    302287        }
    303288    }
    304289
    305     if (enc_len == 0 || enc_len > len)
    306     {
    307         int l = len;
    308         len = 0;
    309         return l;
    310     }
    311 
    312290    enc_len = std::min((uint)enc_len, block_len - 8);
    313291
    314292    //uint32_t x = *(uint32_t*)payload;
     
    361339    data[6] = (enc_len << 3) & 0xFF;
    362340    data[7] = (enc_len >> 5) & 0xFF;
    363341    memset(payload + enc_len, 0, block_len - 8 - enc_len);
    364     len = block_len;
    365342
    366343    return enc_len;
    367344}
    368345
    369 // must have exactly 1 frames worth of data
    370 size_t AudioOutputDigitalEncoder::Encode(short *buff)
     346size_t AudioOutputDigitalEncoder::Encode(void *buf, int len)
    371347{
    372     int encsize = 0;
    373348    size_t outsize = 0;
    374  
    375     // put data in the correct spot for encode frame
    376     outsize = avcodec_encode_audio(
    377         av_context, ((uchar*)outbuf) + 8, outbuf_size - 8, buff);
    378349
    379     size_t tmpsize = outsize;
     350    int fs = FrameSize();
     351    memcpy(inbuf+inbuflen, buf, len);
     352    inbuflen += len;
     353    int frames = inbuflen / fs;
    380354
    381     outsize = MAX_AC3_FRAME_SIZE;
    382     encsize = encode_frame(
    383         /*av_context->codec_id==CODEC_ID_DTS*/ false,
    384         (unsigned char*)outbuf, outsize);
     355    while (frames--)
     356    {
     357        // put data in the correct spot for encode frame
     358        outsize = avcodec_encode_audio(
     359            av_context, ((uchar*)outbuf) + outbuflen + 8, OUTBUFSIZE - 8, (short int *)inbuf);
    385360
    386     VERBOSE(VB_AUDIO+VB_TIMESTAMP,
    387             QString("DigitalEncoder::Encode len1=%1 len2=%2 finallen=%3")
    388                 .arg(tmpsize).arg(encsize).arg(outsize));
     361        encode_frame(
     362            /*av_context->codec_id==CODEC_ID_DTS*/ false,
     363            (unsigned char*)outbuf + outbuflen, outsize
     364        );
    389365
    390     return outsize;
     366        outbuflen += MAX_AC3_FRAME_SIZE;
     367        inbuflen -= fs;
     368        memmove(inbuf, inbuf+fs, inbuflen);
     369    }
     370
     371    return outbuflen;
    391372}
     373
     374void AudioOutputDigitalEncoder::GetFrames(void *ptr, int maxlen)
     375{
     376    int len = (maxlen < outbuflen ? maxlen : outbuflen);
     377    memcpy(ptr, outbuf, len);
     378    outbuflen -= len;
     379    memmove(outbuf, outbuf+len, outbuflen);
     380}
  • mythtv/libs/libmyth/audiooutput.h

     
    1515    static AudioOutput *OpenAudio(
    1616        const QString &audiodevice,
    1717        const QString &passthrudevice,
    18         int audio_bits, int audio_channels, int audio_samplerate,
     18        int audio_bits, int audio_channels,
     19        int audio_codec, int audio_samplerate,
    1920        AudioOutputSource source,
    20         bool set_initial_vol, bool audio_passthru);
     21        bool set_initial_vol, bool audio_passthru,
     22        int upmixer_startup = 0);
    2123
    2224    AudioOutput() :
    2325        VolumeBase(),             OutputListeners(),
     
    6870   
    6971    virtual void bufferOutputData(bool y) = 0;
    7072    virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0;
     73    virtual bool ToggleUpmix(void) = 0;
    7174
    7275  protected:
    7376    void Error(const QString &msg);
  • mythtv/libs/libmyth/audiooutputdigitalencoder.h

     
    55#include "libavcodec/avcodec.h"
    66};
    77
     8#define INBUFSIZE 131072
     9#define OUTBUFSIZE 98304
     10
    811class AudioOutputDigitalEncoder
    912{
    1013  public:
     
    1316
    1417    bool   Init(CodecID codec_id, int bitrate, int samplerate, int channels);
    1518    void   Dispose(void);
    16     size_t Encode(short * buff);
    17 
    18     inline char *GetFrameBuffer(void);
     19    size_t Encode(void *buf, int len);
     20    void   GetFrames(void *ptr, int maxlen);
    1921    size_t FrameSize(void)  const { return one_frame_bytes; }
    20     char  *GetOutBuff(void) const { return outbuf;          }
     22    int    Buffered(void) const { return inbuflen; }
    2123
    2224  public:
    2325    size_t audio_bytes_per_sample;
    2426
    2527  private:
    2628    AVCodecContext *av_context;
    27     char           *outbuf;
    28     int             outbuf_size;
    29     char           *frame_buffer;
     29    char            outbuf[OUTBUFSIZE];
     30    char            inbuf[INBUFSIZE];
     31    int             outbuflen;
     32    int             inbuflen;
    3033    size_t          one_frame_bytes;
    3134};
    3235
    33 inline char *AudioOutputDigitalEncoder::GetFrameBuffer(void)
    34 {
    35     if (!frame_buffer && av_context)
    36         frame_buffer = new char [one_frame_bytes];
    37 
    38     return frame_buffer;
    39 }
    40 
    4136#endif
  • mythtv/libs/libmyth/audiooutputalsa.h

     
    6565    virtual void WriteAudio(unsigned char *aubuf, int size);
    6666    virtual int  GetSpaceOnSoundcard(void) const;
    6767    virtual int  GetBufferedOnSoundcard(void) const;
     68    vector<int> GetSupportedRates(void);
    6869
    6970  private:
     71    void SetIECStatus(bool audio);
    7072    inline int SetParameters(snd_pcm_t *handle,
    7173                             snd_pcm_format_t format, unsigned int channels,
    7274                             unsigned int rate, unsigned int buffer_time,
    7375                             unsigned int period_time);
    7476
    75 
     77    void ReorderSmpteToAlsa6ch(unsigned char *buf, int size);
     78    template <class AudioDataType>
     79        void _ReorderSmpteToAlsa6ch(AudioDataType *buf, int size);
    7680    // Volume related
    7781    void SetCurrentVolume(QString control, int channel, int volume);
    7882    void OpenMixer(bool setstartingvolume);
  • mythtv/libs/libmythfreesurround/el_processor.cpp

     
    2626#include "fftw3.h"
    2727#else
    2828extern "C" {
    29 #include "libavutil/declare_aligned.h"
    3029#include "dsputil.h"
    3130};
    3231typedef FFTSample FFTComplexArray[2];
     
    4140
    4241const float PI = 3.141592654;
    4342const float epsilon = 0.000001;
    44 //const float center_level = 0.5*sqrt(0.5);   // gain of the center channel
    45 //const float center_level = sqrt(0.5);   // gain of the center channel
    46 const float center_level = 1.0;   // gain of the center channel
    47 //const float center_level = 0.5;   // gain of the center channel
     43const float center_level = 0.5*sqrt(0.5);
    4844
    49 // should be .6-.7
    50 // but with centerlevel 2x what its supposed to be, we halve 0.68
    51 // to keep center from clipping
    52 //const float window_gain = 0.34;     
    53 //const float window_gain = 0.68;     
    54 const float window_gain = 0.95;     // to prive a bit of margin
    55 
    5645// private implementation of the surround decoder
    5746class decoder_impl {
    5847public:
     
    9988            outbuf[c].resize(N);
    10089            filter[c].resize(N);
    10190        }
    102         // DC component of filters is always 0
    103         for (unsigned c=0;c<5;c++)
    104         {
    105             filter[c][0] = 0.0;
    106             filter[c][1] = 0.0;
    107             filter[c][halfN] = 0.0;
    108         }
    10991        sample_rate(48000);
    11092        // generate the window function (square root of hann, b/c it is applied before and after the transform)
    11193        wnd.resize(N);
    112         // dft normalization included in the window for zero cost scaling
    113         // also add a gain factor of *2 due to processing gain in algo (see center_level)
    114         surround_gain(1.0);
     94        for (unsigned k=0;k<N;k++)
     95            wnd[k] = sqrt(0.5*(1-cos(2*PI*k/N))/N);
    11596        current_buf = 0;
    11697        // set the default coefficients
    11798        surround_coefficients(0.8165,0.5774);
     
    193174    // set lfe filter params
    194175    void sample_rate(unsigned int srate) {
    195176        // lfe filter is just straight through band limited
    196         unsigned int cutoff = (250*N)/srate;
     177        unsigned int cutoff = (30*N)/srate;
    197178        for (unsigned f=0;f<=halfN;f++) {           
    198             if ((f>=2) && (f<cutoff))
    199                 filter[5][f] = 1.0;
     179            if (f<cutoff)
     180                filter[5][f] = 0.5*sqrt(0.5);
    200181            else
    201182                filter[5][f] = 0.0;
    202183        }
     
    215196        E = (o+v)*n; F = (o+u)*n; G = (o-v)*n;  H = (o-u)*n;
    216197    }
    217198
    218     void surround_gain(float gain) {
    219         master_gain = gain * window_gain * 0.5 * 0.25;
    220         for (unsigned k=0;k<N;k++)
    221             wnd[k] = sqrt(master_gain*(1-cos(2*PI*k/N))/N);
    222     }
    223 
    224199    // set the phase shifting mode
    225200    void phase_mode(unsigned mode) {
    226201        const float modes[4][2] = {{0,0},{0,PI},{PI,0},{-PI/2,PI/2}};
     
    291266
    292267        // 2. compare amplitude and phase of each DFT bin and produce the X/Y coordinates in the sound field
    293268        //    but dont do DC or N/2 component
    294         for (unsigned f=2;f<halfN;f++) {           
     269        for (unsigned f=0;f<halfN;f++) {           
    295270            // get left/right amplitudes/phases
    296271            float ampL = amplitude(dftL[f]), ampR = amplitude(dftR[f]);
    297272            float phaseL = phase(dftL[f]), phaseR = phase(dftR[f]);
     
    306281            phaseDiff = abs(phaseDiff);
    307282
    308283            if (linear_steering) {
    309 /*              cfloat w = polar(sqrt(ampL*ampL+ampR*ampR), (phaseL+phaseR)/2);
    310                 cfloat lt = cfloat(dftL[f][0],dftL[f][1])/w, rt = cfloat(dftR[f][0],dftR[f][1])/w;              */
    311 //              xfs[f] = -(C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E).real();
    312 //              yfs[f] = (rt - (xfs[f]*E+H))/(F+xfs[f]*G);
    313 
    314                 /*
    315                 Problem:
    316                 This assumes that the values are interpolated linearly between the cardinal points.
    317                 But this way we have no chance of knowing the average volume...
    318                 - Can we solve that computing everything under the assumption of normalized volume?
    319                   No. Seemingly not.
    320                 - Maybe we should add w explitcitly into the equation and see if we can solve it...
    321                 */
    322 
    323 
    324                 //cfloat lt(0.5,0),rt(0.5,0);
    325                 //cfloat x(0,0), y(1,0);
    326                 /*cfloat p = (C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E);
    327                 cfloat q = B*(rt+H) + F*(D-lt) / (G*A - C*E);
    328                 cfloat s = sqrt(p*p/4.0f - q);
    329                 cfloat x = -p;
    330                 cfloat x1 = -p/2.0f + s;
    331                 cfloat x2 = -p/2.0f - s;
    332                 float x = 0;
    333                 if (x1.real() >= -1 && x1.real() <= 1)
    334                     x = x1.real();
    335                 else if (x2.real() >= -1 && x2.real() <= 1)
    336                     x = x2.real();*/
    337 
    338                 //cfloat yp = (rt - (x*E+H))/(F+x*G);
    339                 //cfloat xp = (lt - (y*B+D))/(A+y*C);
    340 
    341                 /*xfs[f] = x;
    342                 yfs[f] = y.real();*/
    343 
    344284                // --- this is the fancy new linear mode ---
    345285
    346286                // get sound field x/y position
     
    598538    float surround_high,surround_low;  // high and low surround mixing coefficient (e.g. 0.8165/0.5774)
    599539    float surround_balance;            // the xfs balance that follows from the coeffs
    600540    float surround_level;              // gain for the surround channels (follows from the coeffs
    601     float master_gain;                 // gain for all channels
    602541    float phase_offsetL, phase_offsetR;// phase shifts to be applied to the rear channels
    603542    float front_separation;            // front stereo separation
    604543    float rear_separation;             // rear stereo separation
     
    626565
    627566void fsurround_decoder::surround_coefficients(float a, float b) { impl->surround_coefficients(a,b); }
    628567
    629 void fsurround_decoder::gain(float gain) { impl->surround_gain(gain); }
    630 
    631568void fsurround_decoder::phase_mode(unsigned mode) { impl->phase_mode(mode); }
    632569
    633570void fsurround_decoder::steering_mode(bool mode) { impl->steering_mode(mode); }
  • mythtv/libs/libmythfreesurround/freesurround.cpp

     
    6363const unsigned default_block_size = 8192;
    6464// there will be a slider for this in the future
    6565//const float master_gain = 1.0;
    66 //#define MASTER_GAIN * master_gain
     66//#define MASTER_GAIN * master_gain 
    6767#define MASTER_GAIN
    68 //const float master_gain = 1.0/(1<<15);
    69 //const float inv_master_gain = (1<<15);
     68//const float inv_master_gain = 1.0;
    7069//#define INV_MASTER_GAIN * inv_master_gain
    7170#define INV_MASTER_GAIN
    7271
     
    192191    if (moviemode)
    193192    {
    194193        params.phasemode = 1;
    195         params.center_width = 0;
    196         params.gain = 1.0;
     194        params.center_width = 25;
     195        params.dimension = 0.5;
    197196    }
    198197    else
    199198    {
    200         params.center_width = 70;
    201         // for 50, gain should be about 1.9, c/lr about 2.7
    202         // for 70, gain should be about 3.1, c/lr about 1.5
    203         params.gain = 3.1;
     199        params.center_width = 65;
     200        params.dimension = 0.3;
    204201    }
    205202    switch (surround_mode)
    206203    {
     
    236233        decoder->phase_mode(params.phasemode);
    237234        decoder->surround_coefficients(params.coeff_a, params.coeff_b);                         
    238235        decoder->separation(params.front_sep/100.0,params.rear_sep/100.0);
    239         decoder->gain(params.gain);
    240236    }
    241237}
    242238
     
    250246    phasemode(0),
    251247    steering(1),
    252248    front_sep(100),
    253     rear_sep(100),
    254     gain(1.0)
     249    rear_sep(100)
    255250{
    256251}
    257252
     
    329324                    for (i=0;(i<numSamples) && (ic < bs);i++,ic++)
    330325                    {
    331326                        int16bufs->l[ic] = *samples++ >> 1;
    332                         int16bufs->c[ic] = *samples++ >> 1;
    333327                        int16bufs->r[ic] = *samples++ >> 1;
     328                        int16bufs->c[ic] = *samples++ >> 1;
     329                        int16bufs->lfe[ic] = *samples++ >> 1;
    334330                        int16bufs->ls[ic] = *samples++ >> 1;
    335331                        int16bufs->rs[ic] = *samples++ >> 1;
    336                         int16bufs->lfe[ic] = *samples++ >> 1;
    337332                    }
    338333                    break;
    339334            }
     
    391386                        for (i=0;i<numSamples;i++)
    392387                        {
    393388                            *l++ = *samples++ >> 1;
    394                             *c++ = *samples++ >> 1;
    395389                            *r++ = *samples++ >> 1;
     390                            *c++ = *samples++ >> 1;
     391                            *lfe++ = *samples++ >> 1;
    396392                            *ls++ = *samples++ >> 1;
    397393                            *rs++ = *samples++ >> 1;
    398                             *lfe++ = *samples++ >> 1;
    399394                        }
    400395                        } break;
    401396                }
     
    479474                    for (i=0;(i<numSamples) && (ic < bs);i++,ic++)
    480475                    {
    481476                        int16bufs->l[ic] = *samples++ << 7;
    482                         int16bufs->c[ic] = *samples++ << 7;
    483477                        int16bufs->r[ic] = *samples++ << 7;
     478                        int16bufs->c[ic] = *samples++ << 7;
     479                        int16bufs->lfe[ic] = *samples++ << 7;
    484480                        int16bufs->ls[ic] = *samples++ << 7;
    485481                        int16bufs->rs[ic] = *samples++ << 7;
    486                         int16bufs->lfe[ic] = *samples++ << 7;
    487482                    }
    488483                    break;
    489484            }
     
    541536                        for (i=0;i<numSamples;i++)
    542537                        {
    543538                            *l++ = *samples++ << 7;
    544                             *c++ = *samples++ << 7;
    545539                            *r++ = *samples++ << 7;
     540                            *c++ = *samples++ << 7;
     541                            *lfe++ = *samples++ << 7;
    546542                            *ls++ = *samples++ << 7;
    547543                            *rs++ = *samples++ << 7;
    548                             *lfe++ = *samples++ << 7;
    549544                        }
    550545                        } break;
    551546                }
     
    588583            {
    589584                *output++ = int16bufs->l[outindex];
    590585                *output++ = int16bufs->r[outindex];
    591                 *output++ = int16bufs->ls[outindex];
    592                 *output++ = int16bufs->rs[outindex];
    593586                *output++ = int16bufs->c[outindex];
    594587                *output++ = int16bufs->lfe[outindex];
     588                *output++ = int16bufs->ls[outindex];
     589                *output++ = int16bufs->rs[outindex];
    595590                oc--;
    596591                outindex++;
    597592            }
     
    611606                {
    612607                    *output++ = lrintf(*l++ INV_MASTER_GAIN);
    613608                    *output++ = lrintf(*r++ INV_MASTER_GAIN);
    614                     *output++ = lrintf(*ls++ INV_MASTER_GAIN);
    615                     *output++ = lrintf(*rs++ INV_MASTER_GAIN);
    616609                    *output++ = lrintf(*c++ INV_MASTER_GAIN);
    617610                    *output++ = lrintf(*lfe++ INV_MASTER_GAIN);
     611                    *output++ = lrintf(*ls++ INV_MASTER_GAIN);
     612                    *output++ = lrintf(*rs++ INV_MASTER_GAIN);
    618613                }
    619614                oc -= maxSamples;
    620615                outindex += maxSamples;
     
    631626                {
    632627                    *output++ = *l++;
    633628                    *output++ = *r++;
    634                     *output++ = *ls++;
    635                     *output++ = *rs++;
    636629                    *output++ = *c++;
    637630                    *output++ = *lfe++;
     631                    *output++ = *ls++;
     632                    *output++ = *rs++;
    638633                }
    639634                oc -= maxSamples;
    640635                outindex += maxSamples;
     
    655650    {
    656651        if (decoder)
    657652        {
    658             // actually these params need only be set when they change... but it doesn't hurt
    659 #if 0
    660             decoder->steering_mode(params.steering);
    661             decoder->phase_mode(params.phasemode);
    662             decoder->surround_coefficients(params.coeff_a, params.coeff_b);                             
    663             decoder->separation(params.front_sep/100.0,params.rear_sep/100.0);
    664 #endif
    665             // decode the bufs->block
    666             //decoder->decode(input,output,params.center_width/100.0,params.dimension/100.0);
    667             //decoder->decode(output,params.center_width/100.0,params.dimension/100.0);
    668653            decoder->decode(params.center_width/100.0,params.dimension/100.0);
    669654        }
    670655    }
  • mythtv/libs/libmythfreesurround/el_processor.h

     
    4747        //  a is the coefficient of left rear in left total, b is the coefficient of left rear in right total; the same is true for right.
    4848        void surround_coefficients(float a, float b);
    4949
    50         // override for master surround gain
    51         void gain(float gain);
    52 
    5350        // set the phase shifting mode for decoding
    54         // 0 = (+0°,+0°)   - music mode
    55         // 1 = (+0°,+180°) - PowerDVD compatibility
    56         // 2 = (+180°,+0°) - BeSweet compatibility
    57         // 3 = (-90°,+90°) - This seems to work. I just don't know why.
     51        // 0 = (+0,+0)   - music mode
     52        // 1 = (+0,+180) - PowerDVD compatibility
     53        // 2 = (+180,+0) - BeSweet compatibility
     54        // 3 = (-90,+90) - This seems to work. I just don't know why.
    5855        void phase_mode(unsigned mode);
    5956
    6057        // override the steering mode
  • mythtv/programs/mythfrontend/globalsettings.cpp

     
    9494static HostComboBox *MaxAudioChannels()
    9595{
    9696    HostComboBox *gc = new HostComboBox("MaxChannels",false);
    97     gc->setLabel(QObject::tr("Max Audio Channels"));
     97    gc->setLabel(QObject::tr("Speakers configuration"));
    9898    gc->addSelection(QObject::tr("Stereo"), "2", true); // default
    9999    gc->addSelection(QObject::tr("5.1"), "6");
    100100    gc->setHelpText(
    101101            QObject::tr(
    102                 "Set the maximum number of audio channels to be decoded. "
    103                 "This is for multi-channel/surround audio playback."));
     102                "Set your audio configuration: Stereo or Surround."));
    104103    return gc;
    105104}
    106105
     106static HostCheckBox *AudioUpmix()
     107{
     108    HostCheckBox *gc = new HostCheckBox("AudioDefaultUpmix");
     109    gc->setLabel(QObject::tr("Upconvert stereo to 5.1 surround"));
     110    gc->setValue(true);
     111    gc->setHelpText(QObject::tr("MythTV can upconvert stereo to 5.1 audio. "
     112                                "Set this option to enable it by default. "
     113                                "You can enable or disable the upconversion during playback at anytime."));
     114    return gc;
     115}
     116
    107117static HostComboBox *AudioUpmixType()
    108118{
    109119    HostComboBox *gc = new HostComboBox("AudioUpmixType",false);
    110120    gc->setLabel(QObject::tr("Upmix"));
    111     gc->addSelection(QObject::tr("Passive"), "0", true); // default
    112     gc->addSelection(QObject::tr("Active Simple"), "1");
    113     gc->addSelection(QObject::tr("Active Linear"), "2");
     121    gc->addSelection(QObject::tr("Fastest"), "0", true); // default
     122    gc->addSelection(QObject::tr("Good"), "1");
     123    gc->addSelection(QObject::tr("Best"), "2");
    114124    gc->setHelpText(
    115125            QObject::tr(
    116                 "Set the audio upmix type for 2ch to 6ch conversion. "
    117                 "This is for multi-channel/surround audio playback. "
    118                 "'Passive' is the least demanding on the CPU. "
    119                 "'Active Simple' is more demanding and 'Active Linear' "
    120                 "is the most demanding (but highest quality)."));
     126                "Set the audio surround upconversion quality. "
     127                "'Fastest' is the least demanding on the CPU at the expense of quality."));
    121128    return gc;
    122129}
    123130
     
    125132{
    126133    HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true);
    127134
    128     gc->setLabel(QObject::tr("Passthrough output device"));
     135    gc->setLabel(QObject::tr("Digital output device"));
    129136    gc->addSelection(QObject::tr("Default"), "Default");
    130137#ifndef USING_MINGW
    131138    gc->addSelection("ALSA:iec958:{ AES0 0x02 }", "ALSA:iec958:{ AES0 0x02 }");
     
    133140    gc->addSelection("ALSA:plughw:0,3", "ALSA:plughw:0,3");
    134141#endif
    135142
    136     gc->setHelpText(QObject::tr("Audio output device to use for AC3 and "
    137                     "DTS passthrough. Default is the same as Audio output "
     143    gc->setHelpText(QObject::tr("Audio output device to use for digital audio. Default is the same as Audio output "
    138144                    "device. This value is currently only used with ALSA "
    139145                    "sound output."));
    140146    return gc;
     
    146152    gc->setLabel(QObject::tr("Use internal volume controls"));
    147153    gc->setValue(true);
    148154    gc->setHelpText(QObject::tr("MythTV can control the PCM and master "
    149                     "mixer volume.  If you prefer to use an external mixer "
    150                     "program, then disable this option."));
     155                    "mixer volume.  If you prefer to control the volume externally "
     156                    "(like your amplifier) or use an external mixer "
     157                    "program, disable this option."));
    151158    return gc;
    152159}
    153160
     
    175182#ifdef USING_WINAUDIO
    176183    gc->addSelection("Windows:", "Windows:");
    177184#endif
     185#if !(defined(USING_DIRECTX) || defined(USING_WINAUDIO))
     186    gc->addSelection("software", "software");
     187    gc->setHelpText(QObject::tr("Setting the mixer device to \"software\" lets MythTV control "
     188                                "the volume of all audio at the expense of a slight quality loss."));
     189#endif
    178190
    179191    return gc;
    180192}
     
    235247static HostCheckBox *AC3PassThrough()
    236248{
    237249    HostCheckBox *gc = new HostCheckBox("AC3PassThru");
    238     gc->setLabel(QObject::tr("Enable AC3 to SPDIF passthrough"));
     250    gc->setLabel(QObject::tr("Dolby Digital"));
    239251    gc->setValue(false);
    240     gc->setHelpText(QObject::tr("Enable sending AC3 audio directly to your "
    241                     "sound card's SPDIF output, on sources which contain "
    242                     "AC3 soundtracks (usually digital TV).  Requires that "
    243                     "the audio output device be set to something suitable."));
     252    gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports AC3/Dolby Digital. "
     253                                "You must use a digital connection. Uncheck if using an analog connection."));
    244254    return gc;
    245255}
    246256
    247257static HostCheckBox *DTSPassThrough()
    248258{
    249259    HostCheckBox *gc = new HostCheckBox("DTSPassThru");
    250     gc->setLabel(QObject::tr("Enable DTS to SPDIF passthrough"));
     260    gc->setLabel(QObject::tr("DTS"));
    251261    gc->setValue(false);
    252     gc->setHelpText(QObject::tr("Enable sending DTS audio directly to your "
    253                     "sound card's SPDIF output, on sources which contain "
    254                     "DTS soundtracks (usually DVDs).  Requires that the "
    255                     "audio output device be set to something suitable."));
     262    gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports DTS. "
     263                                "You must use a digital connection. Uncheck if using an analog connection"));
    256264    return gc;
    257265}
    258266
     
    19901998    return gc;
    19911999}
    19922000
    1993 static HostCheckBox *AggressiveBuffer()
    1994 {
    1995     HostCheckBox *gc = new HostCheckBox("AggressiveSoundcardBuffer");
    1996     gc->setLabel(QObject::tr("Aggressive Sound card Buffering"));
    1997     gc->setValue(false);
    1998     gc->setHelpText(QObject::tr("If enabled, MythTV will pretend to have "
    1999                    "a smaller sound card buffer than is really present.  This "
    2000                    "may speed up seeking, but can also cause playback "
    2001                    "problems."));
    2002     return gc;
    2003 }
    2004 
    20052001static HostCheckBox *ClearSavedPosition()
    20062002{
    20072003    HostCheckBox *gc = new HostCheckBox("ClearSavedPosition");
     
    35103506    return gs;
    35113507}
    35123508
    3513 class AudioSystemSettingsGroup : public VerticalConfigurationGroup
     3509class AudioSystemSettingsGroup : public TriggeredConfigurationGroup
    35143510{
    35153511  public:
    35163512    AudioSystemSettingsGroup() :
    3517         VerticalConfigurationGroup(false, true, false, false)
     3513        TriggeredConfigurationGroup(false, true, false, false)
    35183514    {
    35193515        setLabel(QObject::tr("Audio System"));
    35203516        setUseLabel(false);
    35213517
    35223518        addChild(AudioOutputDevice());
    3523         addChild(PassThroughOutputDevice());
    35243519
    3525         addChild(MaxAudioChannels());
    3526         addChild(AudioUpmixType());
     3520        Setting *numchannels = MaxAudioChannels();
     3521        addChild(numchannels);
    35273522
    3528         // General boolean settings
    3529         addChild(AC3PassThrough());
    3530         addChild(DTSPassThrough());
    3531         addChild(AggressiveBuffer());
     3523        ConfigurationGroup *dummy =
     3524        new VerticalConfigurationGroup(false, true, false, false);
     3525
     3526        ConfigurationGroup *settings =
     3527        new VerticalConfigurationGroup(false, true, false, false);
     3528
     3529        settings->addChild(AudioUpmix());
     3530        settings->addChild(AudioUpmixType());
     3531        settings->addChild(PassThroughOutputDevice());
     3532
     3533        ConfigurationGroup *settings2 =
     3534        new HorizontalConfigurationGroup();
     3535        settings2->setLabel(QObject::tr("Audio Processing Capabilities"));
     3536        settings2->addChild(AC3PassThrough());
     3537        settings2->addChild(DTSPassThrough());
     3538
     3539        settings->addChild(settings2);
     3540
     3541        // Show surround/upmixer config only if 5.1 Audio is selected
     3542        setTrigger(numchannels);
     3543        addTarget("2", dummy);
     3544        addTarget("6", settings);
     3545       
    35323546    }
    35333547};
    35343548
  • mythtv/programs/mythtranscode/transcode.cpp

     
    4949    AudioReencodeBuffer(int audio_bits, int audio_channels)
    5050    {
    5151        Reset();
    52         const AudioSettings settings(audio_bits, audio_channels, 0, false);
     52        const AudioSettings settings(audio_bits, audio_channels, 0, 0, false);
    5353        Reconfigure(settings);
    5454        bufsize = 512000;
    5555        audiobuffer = new unsigned char[bufsize];
     
    222222        // Do nothing
    223223        return kMuteOff;
    224224    }
     225    virtual bool ToggleUpmix(void)
     226    {
     227        // Do nothing
     228        return false;
     229    }
    225230
     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
    226242    //  These are pure virtual in AudioOutput, but we don't need them here
    227243    virtual void bufferOutputData(bool){ return; }
    228244    virtual int readOutputData(unsigned char*, int ){ return 0; }