Ticket #6975: new_audio-22054.diff

File new_audio-22054.diff, 106.4 KB (added by JYA, 16 years ago)

Updated to build against SVN #22054

  • 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

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

     
    212212      audioOutput(NULL),
    213213      audio_main_device(QString::null),
    214214      audio_passthru_device(QString::null),
    215       audio_channels(2),            audio_bits(-1),
    216       audio_samplerate(44100),      audio_stretchfactor(1.0f),
    217       audio_codec(NULL),            audio_lock(QMutex::Recursive),
     215      audio_channels(2),            audio_codec(0),
     216      audio_bits(-1),               audio_samplerate(44100),
     217      audio_stretchfactor(1.0f),    audio_lock(QMutex::Recursive),
    218218      audio_muted_on_creation(muted),
    219219      // Picture-in-Picture stuff
    220220      pip_active(false),            pip_visible(true),
     
    911911        audioOutput = AudioOutput::OpenAudio(audio_main_device,
    912912                                             audio_passthru_device,
    913913                                             audio_bits, audio_channels,
    914                                              audio_samplerate,
     914                                             audio_codec, audio_samplerate,
    915915                                             AUDIOOUTPUT_VIDEO,
    916916                                             setVolume, audio_passthru);
    917917        if (!audioOutput)
     
    944944
    945945    if (audioOutput)
    946946    {
    947         const AudioSettings settings(
    948             audio_bits, audio_channels, audio_samplerate,
    949             audio_passthru, audio_codec);
     947        const AudioSettings settings(audio_bits, audio_channels, audio_codec,
     948                                     audio_samplerate, audio_passthru);
    950949        audioOutput->Reconfigure(settings);
     950        if (audio_passthru)
     951            audio_channels = 2;
    951952        errMsg = audioOutput->GetError();
    952953        if (!errMsg.isEmpty())
    953954            audioOutput->SetStretchFactor(audio_stretchfactor);
     
    39103911    return !IsErrored();
    39113912}
    39123913
    3913 void NuppelVideoPlayer::SetAudioParams(int bps, int channels,
     3914void NuppelVideoPlayer::SetAudioParams(int bps, int channels, int codec,
    39143915                                       int samplerate, bool passthru)
    39153916{
    39163917    audio_bits = bps;
    39173918    audio_channels = channels;
     3919    audio_codec = codec;
    39183920    audio_samplerate = samplerate;
    39193921    audio_passthru = passthru;
    39203922}
    39213923
    3922 void NuppelVideoPlayer::SetAudioCodec(void *ac)
    3923 {
    3924     audio_codec = ac;
    3925 }
    3926 
    39273924void NuppelVideoPlayer::SetEffDsp(int dsprate)
    39283925{
    39293926    if (audioOutput)
     
    53475344    }
    53485345}
    53495346
     5347bool NuppelVideoPlayer::ToggleUpmix()
     5348{
     5349    if (audioOutput)
     5350        return audioOutput->ToggleUpmix();
     5351    return false;
     5352}
     5353
    53505354void NuppelVideoPlayer::Zoom(ZoomDirection direction)
    53515355{
    53525356    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

     
    430430    bool TimeStretchHandleAction(PlayerContext*,
    431431                                 const QStringList &actions);
    432432
     433    void ToggleUpmix(PlayerContext*);
    433434    void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true);
    434435    bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions);
    435436
  • 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    bool     audio_muted_on_creation;
  • mythtv/libs/libmythtv/tv_play.cpp

     
    496496    REG_KEY("TV Playback", "VOLUMEDOWN", "Volume down", "[,{,F10,Volume Down");
    497497    REG_KEY("TV Playback", "VOLUMEUP",   "Volume up",   "],},F11,Volume Up");
    498498    REG_KEY("TV Playback", "MUTE",       "Mute",        "|,\\,F9,Volume Mute");
     499    REG_KEY("TV Playback", "TOGGLEUPMIX", "Toggle audio upmixer", "Ctrl+U");
    499500    REG_KEY("TV Playback", "TOGGLEPIPMODE", "Toggle Picture-in-Picture view",
    500501            "V");
    501502    REG_KEY("TV Playback", "TOGGLEPBPMODE", "Toggle Picture-by-Picture view",
     
    633634  Teletext     F2,F3,F4,F5,F6,F7,F8
    634635  ITV          F2,F3,F4,F5,F6,F7,F12
    635636
    636   Playback: Ctrl-B,Ctrl-G,Ctrl-Y
     637  Playback: Ctrl-B,Ctrl-G,Ctrl-Y,Ctrl-U
    637638*/
    638639}
    639640
     
    43484349        DoTogglePictureAttribute(ctx, kAdjustingPicture_Playback);
    43494350    else if (has_action("TOGGLESTRETCH", actions))
    43504351        ToggleTimeStretch(ctx);
     4352    else if (has_action("TOGGLEUPMIX", actions))
     4353        ToggleUpmix(ctx);
    43514354    else if (has_action("TOGGLESLEEP", actions))
    43524355        ToggleSleepTimer(ctx);
    43534356    else if (has_action("TOGGLERECORD", actions) && islivetv)
     
    79817984    SetSpeedChangeTimer(0, __LINE__);
    79827985}
    79837986
     7987void TV::ToggleUpmix(PlayerContext *ctx)
     7988{
     7989    if (!ctx->nvp || !ctx->nvp->HasAudioOut())
     7990        return;
     7991    QString text;
     7992    if (ctx->nvp->ToggleUpmix())
     7993        text = tr("Upmixer On");
     7994    else
     7995        text = tr("Upmixer Off");
     7996   
     7997    if (ctx->nvp->GetOSD() && !browsemode)
     7998        ctx->nvp->GetOSD()->SetSettingsText(text, 5);
     7999}
     8000   
    79848001// dir in 10ms jumps
    79858002void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit)
    79868003{
     
    96249641        SetManualZoom(actx, true, tr("Zoom Mode ON"));
    96259642    else if (action == "TOGGLESTRETCH")
    96269643        ToggleTimeStretch(actx);
     9644    else if (action == "TOGGLEUPMIX")
     9645        ToggleUpmix(actx);
    96279646    else if (action.left(13) == "ADJUSTSTRETCH")
    96289647    {
    96299648        bool floatRead;
     
    998910008
    999010009    if (category == "AUDIOSYNC")
    999110010        new OSDGenericTree(treeMenu, tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC");
     10011    else if (category == "TOGGLEUPMIX")
     10012        new OSDGenericTree(treeMenu, tr("Toggle Audio Upmixer"), "TOGGLEUPMIX");
    999210013    else if (category == "TIMESTRETCH")
    999310014        FillMenuTimeStretch(ctx, treeMenu);
    999410015    else if (category == "VIDEOSCAN")
  • mythtv/libs/libmythtv/tvosdmenuentry.cpp

     
    232232    curMenuEntries.append(new TVOSDMenuEntry(
    233233        "AUDIOSYNC",          1,  1,  1,  1, "Audio Sync"));
    234234    curMenuEntries.append(new TVOSDMenuEntry(
     235        "TOGGLEUPMIX",        1,  1,  1,  1, "Toggle Upmixer"));
     236    curMenuEntries.append(new TVOSDMenuEntry(
    235237        "TIMESTRETCH",        1,  1,  1,  1, "Time Stretch"));
    236238    curMenuEntries.append(new TVOSDMenuEntry(
    237239        "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
     101static int SMPTE_chanmap[6] = { 2, 0, 1, 3, 4, 5 };
    101102
     103
    102104static ChannelElement* get_che(AACContext *ac, int type, int elem_id) {
    103105    static const int8_t tags_per_config[16] = { 0, 1, 1, 2, 3, 3, 4, 5, 0, 0, 0, 0, 0, 0, 0, 0 };
    104106    if (ac->tag_che_map[type][elem_id]) {
     
    167169    /* Allocate or free elements depending on if they are in the
    168170     * current program configuration.
    169171     *
    170      * Set up default 1:1 output mapping.
     172     * Set up default SMPTE output mapping.
    171173     *
    172174     * For a 5.1 stream the output order will be:
    173      *    [ Center ] [ Front Left ] [ Front Right ] [ LFE ] [ Surround Left ] [ Surround Right ]
     175     *    [ Front Left ] [ Front Right ] [ Center ] [ 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;
     184                    /* Convert to SMPTE channel order if 5.1 */
     185                    int ch = channel_config != 6 ? channels : SMPTE_chanmap[channels];
     186                    channels++;
     187                    ac->output_data[ch] = ac->che[type][i]->ch[0].ret;
    183188                    if(type == TYPE_CPE) {
    184                         ac->output_data[channels++] = ac->che[type][i]->ch[1].ret;
     189                        channels++;
     190                        ac->output_data[ch+1] = ac->che[type][i]->ch[1].ret;
    185191                    }
    186192                }
    187193            } else
  • 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;
     
    155170    AudioOutputDigitalEncoder *encoder;
    156171    FreeSurround              *upmixer;
    157172
     173    void *MonoToStereo(void *s1, void *s2, int samples);
     174    template <class AudioDataType>
     175        void *_MonoToStereo(AudioDataType *s1, AudioDataType *s2, int samples);
     176
    158177    int source_audio_channels;
     178    int source_audio_samplerate;
    159179    int source_audio_bytes_per_sample;
    160180    bool needs_upmix;
    161181    int surround_mode;
     182    bool allow_ac3_passthru;
     183    float old_audio_stretchfactor;
     184    int volume;
    162185
    163186    bool blocking; // do AddSamples calls block?
    164187
  • 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(void *buf, int frames)
     270{
     271    if (audio_bits == 8)
     272        _ReorderSmpteToAlsa6ch((unsigned char *)buf, frames);
     273    else if (audio_bits == 16)
     274        _ReorderSmpteToAlsa6ch((short *)buf, frames);
     275}
    149276
     277template <class AudioDataType>
     278void AudioOutputALSA::_ReorderSmpteToAlsa6ch(AudioDataType *buf, int frames)
     279{
     280    AudioDataType tmpC, tmpLFE, *buf2;
     281
     282    for (int i = 0; i < frames; i++)
     283    {
     284        buf = buf2 = buf + 2;
     285
     286        tmpC = *buf++;
     287        tmpLFE = *buf++;
     288        *buf2++ = *buf++;
     289        *buf2++ = *buf++;
     290        *buf2++ = tmpC;
     291        *buf2++ = tmpLFE;
     292    }
     293}
     294
    150295void AudioOutputALSA::WriteAudio(unsigned char *aubuf, int size)
    151296{
    152297    unsigned char *tmpbuf;
     
    158303        VERBOSE(VB_IMPORTANT, QString("WriteAudio() called with pcm_handle == NULL!"));
    159304        return;
    160305    }
     306
     307    if (!(audio_passthru || audio_enc) && audio_channels == 6)
     308        ReorderSmpteToAlsa6ch(aubuf, frames);
    161309   
    162310    tmpbuf = aubuf;
    163311
     
    634782    if (mixer_handle != NULL)
    635783        CloseMixer();
    636784
     785    if (alsadevice.toLower() == "software")
     786        return;
     787
    637788    VERBOSE(VB_AUDIO, QString("Opening mixer %1").arg(device));
    638789
    639790    // 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            // don't 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    VolumeBase::UpdateVolume();
    295355
    296356    VERBOSE(VB_AUDIO, LOC + QString("Audio fragment size: %1")
    297357            .arg(fragment_size));
    298358
    299     if (audio_buffer_unused < 0)
    300         audio_buffer_unused = 0;
     359    audio_buffer_unused = 0;
    301360
    302     if (!gContext->GetNumSetting("AggressiveSoundcardBuffer", 0))
    303         audio_buffer_unused = 0;
    304 
    305361    audbuf_timecode = 0;
    306362    audiotime = 0;
    307363    samples_buffered = 0;
     
    310366    current_seconds = -1;
    311367    source_bitrate = -1;
    312368
    313     // NOTE: this won't do anything as above samplerate vars are set equal
    314     // Check if we need the resampler
    315     if (audio_samplerate != settings.samplerate)
    316     {
    317         int error;
    318         VERBOSE(VB_GENERAL, LOC + QString("Using resampler. From: %1 to %2")
    319                                .arg(settings.samplerate).arg(audio_samplerate));
    320         src_ctx = src_new (SRC_SINC_BEST_QUALITY, audio_channels, &error);
    321         if (error)
    322         {
    323             Error(QString("Error creating resampler, the error was: %1")
    324                   .arg(src_strerror(error)) );
    325             return;
    326         }
    327         src_data.src_ratio = (double) audio_samplerate / settings.samplerate;
    328         src_data.data_in = src_in;
    329         src_data.data_out = src_out;
    330         src_data.output_frames = 16384*6;
    331         need_resampler = true;
    332     }
    333 
    334369    if (needs_upmix)
    335370    {
    336371        VERBOSE(VB_AUDIO, LOC + QString("create upmixer"));
     
    345380            (FreeSurround::SurroundMode)surround_mode);
    346381
    347382        VERBOSE(VB_AUDIO, LOC +
    348                 QString("create upmixer done with surround mode %1")
     383                QString("Create upmixer done with surround mode %1")
    349384                .arg(surround_mode));
    350385    }
    351386
    352387    VERBOSE(VB_AUDIO, LOC + QString("Audio Stretch Factor: %1")
    353388            .arg(audio_stretchfactor));
    354     VERBOSE(VB_AUDIO, QString("Audio Codec Used: %1")
    355             .arg((audio_codec) ?
    356                  codec_id_string(audio_codec->codec_id) : "not set"));
    357389
    358     if (redo_stretch)
    359     {
    360         delete pSoundStretch;
    361         pSoundStretch = NULL;
    362         SetStretchFactorLocked(audio_stretchfactor);
    363     }
    364     else
    365     {
    366         SetStretchFactorLocked(audio_stretchfactor);
    367         if (pSoundStretch)
    368         {
    369             // if its passthru then we need to reencode
    370             if (audio_codec)
    371             {
    372                 if (!encoder)
    373                 {
    374                     VERBOSE(VB_AUDIO, LOC +
    375                             QString("Creating Encoder for codec %1")
    376                             .arg(audio_codec->codec_id));
    377 
    378                     encoder = new AudioOutputDigitalEncoder();
    379                     if (!encoder->Init(audio_codec->codec_id,
    380                                 audio_codec->bit_rate,
    381                                 audio_codec->sample_rate,
    382                                 audio_codec->channels
    383                                 ))
    384                     {
    385                         // eeks
    386                         delete encoder;
    387                         encoder = NULL;
    388                         VERBOSE(VB_AUDIO, LOC + "Failed to Create Encoder");
    389                     }
    390                 }
    391             }
    392             if (audio_codec && encoder)
    393             {
    394                 pSoundStretch->setSampleRate(audio_codec->sample_rate);
    395                 pSoundStretch->setChannels(audio_codec->channels);
    396             }
    397             else
    398             {
    399                 pSoundStretch->setSampleRate(audio_samplerate);
    400                 pSoundStretch->setChannels(audio_channels);
    401             }
    402         }
    403     }
    404 
     390    SetStretchFactorLocked(old_audio_stretchfactor);
     391   
    405392    // Setup visualisations, zero the visualisations buffers
    406393    prepareVisuals();
    407394
     
    437424    VERBOSE(VB_AUDIO, LOC + "Killing AudioOutputDSP");
    438425    killaudio = true;
    439426    StopOutputThread();
     427    QMutexLocker lock1(&audio_buflock);
    440428
    441429    // Close resampler?
    442430    if (src_ctx)
     431    {
    443432        src_delete(src_ctx);
     433        src_ctx = NULL;
     434    }
     435
    444436    need_resampler = false;
    445437
    446438    // close sound stretcher
     
    448440    {
    449441        delete pSoundStretch;
    450442        pSoundStretch = NULL;
     443        old_audio_stretchfactor = audio_stretchfactor;
     444        audio_stretchfactor = 1.0;
    451445    }
    452446
    453447    if (encoder)
     
    462456        upmixer = NULL;
    463457    }
    464458    needs_upmix = false;
     459    audio_enc = false;
    465460
    466461    CloseDevice();
    467462
     
    612607
    613608    // include algorithmic latencies
    614609    if (pSoundStretch)
    615     {
    616         // add the effect of any unused but processed samples,
    617         // AC3 reencode does this
    618         totalbuffer += (int)(pSoundStretch->numSamples() *
    619                              audio_bytes_per_sample);
    620         // add the effect of unprocessed samples in time stretch algo
    621610        totalbuffer += (int)((pSoundStretch->numUnprocessedSamples() *
    622611                              audio_bytes_per_sample) / audio_stretchfactor);
    623     }
    624612
    625613    if (upmixer && needs_upmix)
    626     {
    627614        totalbuffer += upmixer->sampleLatency() * audio_bytes_per_sample;
    628     }
    629615
     616    if (encoder)
     617         totalbuffer += encoder->Buffered();
     618
    630619    audiotime = audbuf_timecode - (int)(totalbuffer * 100000.0 /
    631620                                   (audio_bytes_per_sample * effdspstretched));
    632621
     
    651640     return audbuf_timecode - GetAudiotime();
    652641}
    653642
     643void AudioOutputBase::SetSWVolume(int new_volume, bool save)
     644{
     645    volume = new_volume;
     646    if (save)
     647    {
     648        QString controlLabel = gContext->GetSetting("MixerControl", "PCM");
     649        controlLabel += "MixerVolume";
     650        gContext->SaveSetting(controlLabel, volume);
     651    }
     652}
     653
     654int AudioOutputBase::GetSWVolume()
     655{
     656    return volume;
     657}
     658
     659void AudioOutputBase::AdjustVolume(void *buffer, int len, bool music)
     660{
     661    if (audio_bits == 8)
     662        _AdjustVolume<char>((char *)buffer, len, music);
     663    else if (audio_bits == 16)
     664        _AdjustVolume<short>((short *)buffer, len, music);
     665}
     666
     667template <class AudioDataType>
     668void AudioOutputBase::_AdjustVolume(AudioDataType *buffer, int len, bool music)
     669{
     670    float g = volume / 100.0;
     671
     672    // Should probably be exponential - this'll do
     673    g *= g;
     674   
     675    // Add gain to AC-3 - try to ~ match PCM volume
     676    if (audio_enc && audio_reenc)
     677        g *= 1.8;
     678
     679    // Music is relatively loud - ditto
     680    else if (music)
     681        g *= 0.4;
     682
     683    if (g == 1.0)
     684        return;
     685
     686    for (int i = 0; i < (int)(len / sizeof(AudioDataType)); i++)
     687    {
     688        float s = static_cast<float>(buffer[i]) * g /
     689                  static_cast<float>(numeric_limits<AudioDataType>::max());
     690        if (s >= 1.0)
     691            buffer[i] = numeric_limits<AudioDataType>::max();
     692        else if (s <= -1.0)
     693            buffer[i] = numeric_limits<AudioDataType>::min();
     694        else
     695            buffer[i] = static_cast<AudioDataType>
     696                        (s * numeric_limits<AudioDataType>::max());
     697    }
     698}
     699
    654700bool AudioOutputBase::AddSamples(char *buffers[], int samples,
    655701                                 long long timecode)
    656702{
     
    682728        return false; // would overflow
    683729    }
    684730
     731    QMutexLocker lock1(&audio_buflock);
     732
    685733    // resample input if necessary
    686734    if (need_resampler && src_ctx)
    687735    {
     
    726774    int abps = (encoder) ?
    727775        encoder->audio_bytes_per_sample : audio_bytes_per_sample;
    728776    int len = samples * abps;
     777   
     778    // Give original samples to mythmusic visualisation
     779    dispatchVisual((unsigned char *)buffer, len, timecode,
     780                   source_audio_channels, audio_bits);
    729781
    730782    // Check we have enough space to write the data
    731783    if (need_resampler && src_ctx)
     
    750802        return false; // would overflow
    751803    }
    752804
     805    QMutexLocker lock1(&audio_buflock);
     806
    753807    // resample input if necessary
    754808    if (need_resampler && src_ctx)
    755809    {
     
    810864            {
    811865                int error = src_reset(src_ctx);
    812866                if (error)
     867                {
    813868                    VERBOSE(VB_IMPORTANT, LOC_ERR + QString(
    814869                            "Error occurred while resetting resampler: %1")
    815870                            .arg(src_strerror(error)));
     871                    src_ctx = NULL;
     872                }
    816873            }
    817874        }
    818875    }
    819876    return len;
    820877}
    821878
     879void *AudioOutputBase::MonoToStereo(void *s1, void *s2, int samples)
     880{
     881    if (audio_bits == 8)
     882        return _MonoToStereo((unsigned char *)s1, (unsigned char *)s2, samples);
     883    else if (audio_bits == 16)
     884        return _MonoToStereo((short *)s1, (short *)s2, samples);
     885    else
     886        return NULL; // 0
     887}
     888
     889template <class AudioDataType>
     890void *AudioOutputBase::_MonoToStereo(AudioDataType *s1, AudioDataType *s2, int samples)
     891{
     892    for (int i = 0; i < samples; i++)
     893    {
     894        *s1++ = *s2;
     895        *s1++ = *s2++;
     896    }
     897    return s2;
     898}
     899
    822900void AudioOutputBase::_AddSamples(void *buffer, bool interleaved, int samples,
    823901                                  long long timecode)
    824902{
    825     audio_buflock.lock();
    826 
    827903    int len; // = samples * audio_bytes_per_sample;
    828904    int audio_bytes = audio_bits / 8;
    829905    int org_waud = waud;
     
    840916            .arg(samples * abps)
    841917            .arg(kAudioRingBufferSize-afree).arg(afree).arg(timecode)
    842918            .arg(needs_upmix));
     919   
     920    len = WaitForFreeSpace(samples);
     921       
     922    if (needs_upmix &&
     923        configured_audio_channels == 2 &&
     924        source_audio_channels == 1)
     925    {
     926            // We're converting mono to stereo
     927        int bdiff = kAudioRingBufferSize - org_waud;
     928        if (bdiff < len)
     929        {
     930            int bdiff_samples = bdiff / abps;
     931            void *buffer2 = MonoToStereo(audiobuffer + org_waud, buffer, bdiff_samples);
     932            MonoToStereo(audiobuffer, buffer2, samples - bdiff_samples);
     933        }
     934        else
     935            MonoToStereo(audiobuffer + org_waud, buffer, samples);
    843936
    844     if (upmixer && needs_upmix)
     937        org_waud = (org_waud + len) % kAudioRingBufferSize;
     938    }
     939    else if (upmixer && needs_upmix)
    845940    {
    846941        int out_samples = 0;
     942        org_waud = waud;
    847943        int step = (interleaved)?source_audio_channels:1;
    848         len = WaitForFreeSpace(samples);    // test
     944       
    849945        for (int itemp = 0; itemp < samples; )
    850946        {
    851             // just in case it does a processing cycle, release the lock
    852             // to allow the output loop to do output
    853             audio_buflock.unlock();
    854947            if (audio_bytes == 2)
    855948            {
    856949                itemp += upmixer->putSamples(
     
    867960                    source_audio_channels,
    868961                    (interleaved) ? 0 : samples);
    869962            }
    870             audio_buflock.lock();
    871963
    872964            int copy_samples = upmixer->numSamples();
    873965            if (copy_samples)
     
    893985                org_waud = (org_waud + copy_len) % kAudioRingBufferSize;
    894986            }
    895987        }
    896 
    897988        if (samples > 0)
    898989            len = WaitForFreeSpace(out_samples);
    899990
     
    901992    }
    902993    else
    903994    {
    904         len = WaitForFreeSpace(samples);
    905 
    906995        if (interleaved)
    907996        {
    908997            char *mybuf = (char*)buffer;
     
    9371026        }
    9381027    }
    9391028
    940     if (samples > 0)
     1029    if (samples <= 0)
     1030        return;
     1031       
     1032    if (pSoundStretch)
    9411033    {
    942         if (pSoundStretch)
     1034        // does not change the timecode, only the number of samples
     1035        // back to orig pos
     1036        org_waud = waud;
     1037        int bdiff = kAudioRingBufferSize - org_waud;
     1038        int nSamplesToEnd = bdiff/abps;
     1039        if (bdiff < len)
    9431040        {
     1041            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     1042                                      (audiobuffer +
     1043                                       org_waud), nSamplesToEnd);
     1044            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
     1045                                      (len - bdiff) / abps);
     1046        }
     1047        else
     1048        {
     1049            pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
     1050                                      (audiobuffer + org_waud),
     1051                                      len / abps);
     1052        }
    9441053
    945             // does not change the timecode, only the number of samples
    946             // back to orig pos
    947             org_waud = waud;
    948             int bdiff = kAudioRingBufferSize - org_waud;
    949             int nSamplesToEnd = bdiff/abps;
    950             if (bdiff < len)
    951             {
    952                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    953                                           (audiobuffer +
    954                                            org_waud), nSamplesToEnd);
    955                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)audiobuffer,
    956                                           (len - bdiff) / abps);
     1054        int nSamples = pSoundStretch->numSamples();
     1055        len = WaitForFreeSpace(nSamples);
     1056       
     1057        while ((nSamples = pSoundStretch->numSamples()))
     1058        {
     1059            if (nSamples > nSamplesToEnd)
     1060                nSamples = nSamplesToEnd;
     1061           
     1062            nSamples = pSoundStretch->receiveSamples(
     1063                (soundtouch::SAMPLETYPE*)
     1064                (audiobuffer + org_waud), nSamples
     1065            );
     1066           
     1067            if (nSamples == nSamplesToEnd) {
     1068                org_waud = 0;
     1069                nSamplesToEnd = kAudioRingBufferSize/abps;
    9571070            }
    958             else
    959             {
    960                 pSoundStretch->putSamples((soundtouch::SAMPLETYPE*)
    961                                           (audiobuffer + org_waud),
    962                                           len / abps);
     1071            else {
     1072                org_waud += nSamples * abps;
     1073                nSamplesToEnd -= nSamples;
    9631074            }
     1075        }
     1076    }
    9641077
    965             if (encoder)
    966             {
    967                 // pull out a packet's worth and reencode it until we
    968                 // don't have enough for any more packets
    969                 soundtouch::SAMPLETYPE *temp_buff =
    970                     (soundtouch::SAMPLETYPE*)encoder->GetFrameBuffer();
    971                 size_t frameSize = encoder->FrameSize()/abps;
     1078    if (internal_vol && SWVolume())
     1079    {
     1080        int bdiff = kAudioRingBufferSize - waud;
     1081        bool music = (timecode < 1);
    9721082
    973                 VERBOSE(VB_AUDIO+VB_TIMESTAMP,
    974                         QString("_AddSamples Enc sfs=%1 bfs=%2 sss=%3")
    975                         .arg(frameSize)
    976                         .arg(encoder->FrameSize())
    977                         .arg(pSoundStretch->numSamples()));
    978 
    979                 // process the same number of samples as it creates
    980                 // a full encoded buffer just like before
    981                 while (pSoundStretch->numSamples() >= frameSize)
    982                 {
    983                     int got = pSoundStretch->receiveSamples(
    984                         temp_buff, frameSize);
    985                     int amount = encoder->Encode(temp_buff);
    986 
    987                     VERBOSE(VB_AUDIO+VB_TIMESTAMP,
    988                             QString("_AddSamples Enc bytes=%1 got=%2 left=%3")
    989                             .arg(amount)
    990                             .arg(got)
    991                             .arg(pSoundStretch->numSamples()));
    992 
    993                     if (!amount)
    994                         continue;
    995 
    996                     //len = WaitForFreeSpace(amount);
    997                     char *ob = encoder->GetOutBuff();
    998                     if (amount >= bdiff)
    999                     {
    1000                         memcpy(audiobuffer + org_waud, ob, bdiff);
    1001                         ob += bdiff;
    1002                         amount -= bdiff;
    1003                         org_waud = 0;
    1004                     }
    1005                     if (amount > 0)
    1006                         memcpy(audiobuffer + org_waud, ob, amount);
    1007 
    1008                     bdiff = kAudioRingBufferSize - amount;
    1009                     org_waud = (org_waud + amount) % kAudioRingBufferSize;
    1010                 }
    1011             }
    1012             else
    1013             {
    1014                 int newLen = 0;
    1015                 int nSamples;
    1016                 len = WaitForFreeSpace(pSoundStretch->numSamples() *
    1017                                        audio_bytes_per_sample);
    1018                 do
    1019                 {
    1020                     int samplesToGet = len/audio_bytes_per_sample;
    1021                     if (samplesToGet > nSamplesToEnd)
    1022                     {
    1023                         samplesToGet = nSamplesToEnd;
    1024                     }
    1025 
    1026                     nSamples = pSoundStretch->receiveSamples(
    1027                         (soundtouch::SAMPLETYPE*)
    1028                         (audiobuffer + org_waud), samplesToGet);
    1029                     if (nSamples == nSamplesToEnd)
    1030                     {
    1031                         org_waud = 0;
    1032                         nSamplesToEnd = kAudioRingBufferSize/audio_bytes_per_sample;
    1033                     }
    1034                     else
    1035                     {
    1036                         int bufsz = nSamples * audio_bytes_per_sample;
    1037                         org_waud = (org_waud + bufsz) % kAudioRingBufferSize;
    1038                         nSamplesToEnd -= nSamples;
    1039                     }
    1040 
    1041                     newLen += nSamples * audio_bytes_per_sample;
    1042                     len -= nSamples * audio_bytes_per_sample;
    1043                 } while (nSamples > 0);
    1044             }
     1083        if (bdiff < len)
     1084        {
     1085            AdjustVolume(audiobuffer + waud, bdiff, music);
     1086            AdjustVolume(audiobuffer, len - bdiff, music);
    10451087        }
     1088        else
     1089            AdjustVolume(audiobuffer + waud, len, music);
     1090    }
    10461091
    1047         waud = org_waud;
    1048         lastaudiolen = audiolen(false);
     1092    // Encode to AC-3?
     1093    if (encoder)
     1094    {
     1095        org_waud = waud;
     1096        int bdiff = kAudioRingBufferSize - org_waud;
     1097        int to_get = 0;
    10491098
    1050         if (timecode < 0)
     1099        if (bdiff < len)
    10511100        {
    1052             // mythmusic doesn't give timestamps..
    1053             timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1101            encoder->Encode(audiobuffer + org_waud, bdiff);
     1102            to_get = encoder->Encode(audiobuffer, len - bdiff);
    10541103        }
    1055  
    1056         samples_buffered += samples;
    1057  
    1058         /* we want the time at the end -- but the file format stores
    1059            time at the start of the chunk. */
    1060         // even with timestretch, timecode is still calculated from original
    1061         // sample count
    1062         audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
     1104        else
     1105            to_get = encoder->Encode(audiobuffer + org_waud, len);
    10631106
    1064         if (interleaved)
     1107        if (to_get > 0)
    10651108        {
    1066             dispatchVisual((unsigned char *)buffer, len, timecode,
    1067                            source_audio_channels, audio_bits);
     1109            if (to_get >= bdiff)
     1110            {
     1111                encoder->GetFrames(audiobuffer + org_waud, bdiff);
     1112                to_get -= bdiff;
     1113                org_waud = 0;
     1114            }
     1115            if (to_get > 0)
     1116                encoder->GetFrames(audiobuffer + org_waud, to_get);
     1117
     1118            org_waud += to_get;
    10681119        }
    10691120    }
    10701121
    1071     audio_buflock.unlock();
     1122    waud = org_waud;
     1123    lastaudiolen = audiolen(false);
     1124
     1125    if (timecode < 0)
     1126        // mythmusic doesn't give timestamps..
     1127        timecode = (int)((samples_buffered * 100000.0) / effdsp);
     1128
     1129    samples_buffered += samples;
     1130
     1131    /* we want the time at the end -- but the file format stores
     1132       time at the start of the chunk. */
     1133    // even with timestretch, timecode is still calculated from original
     1134    // sample count
     1135    audbuf_timecode = timecode + (int)((samples * 100000.0) / effdsp);
    10721136}
    10731137
    10741138void AudioOutputBase::Status()
     
    12091273                last_space_on_soundcard = space_on_soundcard;
    12101274            }
    12111275
    1212             numlowbuffer++;
    1213             if (numlowbuffer > 5 && audio_buffer_unused)
    1214             {
    1215                 VERBOSE(VB_IMPORTANT, LOC + "dropping back audio_buffer_unused");
    1216                 audio_buffer_unused /= 2;
    1217             }
    1218 
    12191276            usleep(5000);
    12201277            continue;
    12211278        }
    1222         else
    1223             numlowbuffer = 0;
    12241279
    12251280        Status();
    12261281
  • mythtv/libs/libmyth/audiooutput.cpp

     
    3131AudioOutput *AudioOutput::OpenAudio(
    3232    const QString &main_device,
    3333    const QString &passthru_device,
    34     int audio_bits, int audio_channels, int audio_samplerate,
     34    int audio_bits, int audio_channels,
     35    int audio_codec, int audio_samplerate,
    3536    AudioOutputSource source,
    36     bool set_initial_vol, bool audio_passthru)
     37    bool set_initial_vol, bool audio_passthru,
     38    int upmixer_startup)
    3739{
    3840    AudioSettings settings(
    3941        main_device, passthru_device, audio_bits,
    40         audio_channels, audio_samplerate, source,
    41         set_initial_vol, audio_passthru);
     42        audio_channels, audio_codec, audio_samplerate, source,
     43        set_initial_vol, audio_passthru, upmixer_startup);
    4244
    4345    settings.FixPassThrough();
    4446
  • 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/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/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/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(void *buf, int frames);
     78    template <class AudioDataType>
     79        void _ReorderSmpteToAlsa6ch(AudioDataType *buf, int frames);
    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        memset(inbufs, 0, sizeof(inbufs));
    11798        memset(outbufs, 0, sizeof(outbufs));
     
    195176    // set lfe filter params
    196177    void sample_rate(unsigned int srate) {
    197178        // lfe filter is just straight through band limited
    198         unsigned int cutoff = (250*N)/srate;
     179        unsigned int cutoff = (30*N)/srate;
    199180        for (unsigned f=0;f<=halfN;f++) {           
    200             if ((f>=2) && (f<cutoff))
    201                 filter[5][f] = 1.0;
     181            if (f<cutoff)
     182                filter[5][f] = 0.5*sqrt(0.5);
    202183            else
    203184                filter[5][f] = 0.0;
    204185        }
     
    217198        E = (o+v)*n; F = (o+u)*n; G = (o-v)*n;  H = (o-u)*n;
    218199    }
    219200
    220     void surround_gain(float gain) {
    221         master_gain = gain * window_gain * 0.5 * 0.25;
    222         for (unsigned k=0;k<N;k++)
    223             wnd[k] = sqrt(master_gain*(1-cos(2*PI*k/N))/N);
    224     }
    225 
    226201    // set the phase shifting mode
    227202    void phase_mode(unsigned mode) {
    228203        const float modes[4][2] = {{0,0},{0,PI},{PI,0},{-PI/2,PI/2}};
     
    293268
    294269        // 2. compare amplitude and phase of each DFT bin and produce the X/Y coordinates in the sound field
    295270        //    but dont do DC or N/2 component
    296         for (unsigned f=2;f<halfN;f++) {           
     271        for (unsigned f=0;f<halfN;f++) {           
    297272            // get left/right amplitudes/phases
    298273            float ampL = amplitude(dftL[f]), ampR = amplitude(dftR[f]);
    299274            float phaseL = phase(dftL[f]), phaseR = phase(dftR[f]);
     
    308283            phaseDiff = abs(phaseDiff);
    309284
    310285            if (linear_steering) {
    311 /*              cfloat w = polar(sqrt(ampL*ampL+ampR*ampR), (phaseL+phaseR)/2);
    312                 cfloat lt = cfloat(dftL[f][0],dftL[f][1])/w, rt = cfloat(dftR[f][0],dftR[f][1])/w;              */
    313 //              xfs[f] = -(C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E).real();
    314 //              yfs[f] = (rt - (xfs[f]*E+H))/(F+xfs[f]*G);
    315 
    316                 /*
    317                 Problem:
    318                 This assumes that the values are interpolated linearly between the cardinal points.
    319                 But this way we have no chance of knowing the average volume...
    320                 - Can we solve that computing everything under the assumption of normalized volume?
    321                   No. Seemingly not.
    322                 - Maybe we should add w explitcitly into the equation and see if we can solve it...
    323                 */
    324 
    325 
    326                 //cfloat lt(0.5,0),rt(0.5,0);
    327                 //cfloat x(0,0), y(1,0);
    328                 /*cfloat p = (C*(rt-H) - B*E + F*A + G*(D-lt)) / (G*A - C*E);
    329                 cfloat q = B*(rt+H) + F*(D-lt) / (G*A - C*E);
    330                 cfloat s = sqrt(p*p/4.0f - q);
    331                 cfloat x = -p;
    332                 cfloat x1 = -p/2.0f + s;
    333                 cfloat x2 = -p/2.0f - s;
    334                 float x = 0;
    335                 if (x1.real() >= -1 && x1.real() <= 1)
    336                     x = x1.real();
    337                 else if (x2.real() >= -1 && x2.real() <= 1)
    338                     x = x2.real();*/
    339 
    340                 //cfloat yp = (rt - (x*E+H))/(F+x*G);
    341                 //cfloat xp = (lt - (y*B+D))/(A+y*C);
    342 
    343                 /*xfs[f] = x;
    344                 yfs[f] = y.real();*/
    345 
    346286                // --- this is the fancy new linear mode ---
    347287
    348288                // get sound field x/y position
     
    600540    float surround_high,surround_low;  // high and low surround mixing coefficient (e.g. 0.8165/0.5774)
    601541    float surround_balance;            // the xfs balance that follows from the coeffs
    602542    float surround_level;              // gain for the surround channels (follows from the coeffs
    603     float master_gain;                 // gain for all channels
    604543    float phase_offsetL, phase_offsetR;// phase shifts to be applied to the rear channels
    605544    float front_separation;            // front stereo separation
    606545    float rear_separation;             // rear stereo separation
     
    628567
    629568void fsurround_decoder::surround_coefficients(float a, float b) { impl->surround_coefficients(a,b); }
    630569
    631 void fsurround_decoder::gain(float gain) { impl->surround_gain(gain); }
    632 
    633570void fsurround_decoder::phase_mode(unsigned mode) { impl->phase_mode(mode); }
    634571
    635572void 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                }
     
    581576    uint oc = out_count;
    582577    if (maxSamples>oc) maxSamples = oc;
    583578    uint outindex = processed_size - oc;
     579
    584580    switch (surround_mode)
    585581    {
    586582        case SurroundModePassive:
     
    588584            {
    589585                *output++ = int16bufs->l[outindex];
    590586                *output++ = int16bufs->r[outindex];
    591                 *output++ = int16bufs->ls[outindex];
    592                 *output++ = int16bufs->rs[outindex];
    593587                *output++ = int16bufs->c[outindex];
    594588                *output++ = int16bufs->lfe[outindex];
     589                *output++ = int16bufs->ls[outindex];
     590                *output++ = int16bufs->rs[outindex];
    595591                oc--;
    596592                outindex++;
    597593            }
     
    611607                {
    612608                    *output++ = lrintf(*l++ INV_MASTER_GAIN);
    613609                    *output++ = lrintf(*r++ INV_MASTER_GAIN);
    614                     *output++ = lrintf(*ls++ INV_MASTER_GAIN);
    615                     *output++ = lrintf(*rs++ INV_MASTER_GAIN);
    616610                    *output++ = lrintf(*c++ INV_MASTER_GAIN);
    617611                    *output++ = lrintf(*lfe++ INV_MASTER_GAIN);
     612                    *output++ = lrintf(*ls++ INV_MASTER_GAIN);
     613                    *output++ = lrintf(*rs++ INV_MASTER_GAIN);
    618614                }
    619615                oc -= maxSamples;
    620616                outindex += maxSamples;
     
    631627                {
    632628                    *output++ = *l++;
    633629                    *output++ = *r++;
    634                     *output++ = *ls++;
    635                     *output++ = *rs++;
    636630                    *output++ = *c++;
    637631                    *output++ = *lfe++;
     632                    *output++ = *ls++;
     633                    *output++ = *rs++;
    638634                }
    639635                oc -= maxSamples;
    640636                outindex += maxSamples;
     
    655651    {
    656652        if (decoder)
    657653        {
    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);
    668654            decoder->decode(params.center_width/100.0,params.dimension/100.0);
    669655        }
    670656    }
  • 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

     
    9191static HostComboBox *MaxAudioChannels()
    9292{
    9393    HostComboBox *gc = new HostComboBox("MaxChannels",false);
    94     gc->setLabel(QObject::tr("Max Audio Channels"));
     94    gc->setLabel(QObject::tr("Speakers configuration"));
    9595    gc->addSelection(QObject::tr("Stereo"), "2", true); // default
    9696    gc->addSelection(QObject::tr("5.1"), "6");
    9797    gc->setHelpText(
    9898            QObject::tr(
    99                 "Set the maximum number of audio channels to be decoded. "
    100                 "This is for multi-channel/surround audio playback."));
     99                "Set your audio configuration: Stereo or Surround."));
    101100    return gc;
    102101}
    103102
     103static HostCheckBox *AudioUpmix()
     104{
     105    HostCheckBox *gc = new HostCheckBox("AudioDefaultUpmix");
     106    gc->setLabel(QObject::tr("Upconvert stereo to 5.1 surround"));
     107    gc->setValue(true);
     108    gc->setHelpText(QObject::tr("MythTV can upconvert stereo to 5.1 audio. "
     109                                "Set this option to enable it by default. "
     110                                "You can enable or disable the upconversion during playback at anytime."));
     111    return gc;
     112}
     113
    104114static HostComboBox *AudioUpmixType()
    105115{
    106116    HostComboBox *gc = new HostComboBox("AudioUpmixType",false);
    107117    gc->setLabel(QObject::tr("Upmix"));
    108     gc->addSelection(QObject::tr("Passive"), "0", true); // default
    109     gc->addSelection(QObject::tr("Active Simple"), "1");
    110     gc->addSelection(QObject::tr("Active Linear"), "2");
     118    gc->addSelection(QObject::tr("Fastest"), "0", true); // default
     119    gc->addSelection(QObject::tr("Good"), "1");
     120    gc->addSelection(QObject::tr("Best"), "2");
    111121    gc->setHelpText(
    112122            QObject::tr(
    113                 "Set the audio upmix type for 2ch to 6ch conversion. "
    114                 "This is for multi-channel/surround audio playback. "
    115                 "'Passive' is the least demanding on the CPU. "
    116                 "'Active Simple' is more demanding and 'Active Linear' "
    117                 "is the most demanding (but highest quality)."));
     123                "Set the audio surround upconversion quality. "
     124                "'Fastest' is the least demanding on the CPU at the expense of quality."));
    118125    return gc;
    119126}
    120127
     
    122129{
    123130    HostComboBox *gc = new HostComboBox("PassThruOutputDevice", true);
    124131
    125     gc->setLabel(QObject::tr("Passthrough output device"));
     132    gc->setLabel(QObject::tr("Digital output device"));
    126133    gc->addSelection(QObject::tr("Default"), "Default");
    127134#ifndef USING_MINGW
    128135    gc->addSelection("ALSA:iec958:{ AES0 0x02 }", "ALSA:iec958:{ AES0 0x02 }");
     
    130137    gc->addSelection("ALSA:plughw:0,3", "ALSA:plughw:0,3");
    131138#endif
    132139
    133     gc->setHelpText(QObject::tr("Audio output device to use for AC3 and "
    134                     "DTS passthrough. Default is the same as Audio output "
     140    gc->setHelpText(QObject::tr("Audio output device to use for digital audio. Default is the same as Audio output "
    135141                    "device. This value is currently only used with ALSA "
    136142                    "sound output."));
    137143    return gc;
     
    143149    gc->setLabel(QObject::tr("Use internal volume controls"));
    144150    gc->setValue(true);
    145151    gc->setHelpText(QObject::tr("MythTV can control the PCM and master "
    146                     "mixer volume.  If you prefer to use an external mixer "
    147                     "program, then disable this option."));
     152                    "mixer volume.  If you prefer to control the volume externally "
     153                    "(like your amplifier) or use an external mixer "
     154                    "program, disable this option."));
    148155    return gc;
    149156}
    150157
     
    170177    gc->addSelection("DirectX:", "DirectX:");
    171178    gc->addSelection("Windows:", "Windows:");
    172179#endif
     180#if !defined(USING_MINGW)
     181    gc->addSelection("software", "software");
     182    gc->setHelpText(QObject::tr("Setting the mixer device to \"software\" lets MythTV control "
     183                                "the volume of all audio at the expense of a slight quality loss."));
     184#endif
    173185
    174186    return gc;
    175187}
     
    230242static HostCheckBox *AC3PassThrough()
    231243{
    232244    HostCheckBox *gc = new HostCheckBox("AC3PassThru");
    233     gc->setLabel(QObject::tr("Enable AC3 to SPDIF passthrough"));
     245    gc->setLabel(QObject::tr("Dolby Digital"));
    234246    gc->setValue(false);
    235     gc->setHelpText(QObject::tr("Enable sending AC3 audio directly to your "
    236                     "sound card's SPDIF output, on sources which contain "
    237                     "AC3 soundtracks (usually digital TV).  Requires that "
    238                     "the audio output device be set to something suitable."));
     247    gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports AC3/Dolby Digital. "
     248                                "You must use a digital connection. Uncheck if using an analog connection."));
    239249    return gc;
    240250}
    241251
    242252static HostCheckBox *DTSPassThrough()
    243253{
    244254    HostCheckBox *gc = new HostCheckBox("DTSPassThru");
    245     gc->setLabel(QObject::tr("Enable DTS to SPDIF passthrough"));
     255    gc->setLabel(QObject::tr("DTS"));
    246256    gc->setValue(false);
    247     gc->setHelpText(QObject::tr("Enable sending DTS audio directly to your "
    248                     "sound card's SPDIF output, on sources which contain "
    249                     "DTS soundtracks (usually DVDs).  Requires that the "
    250                     "audio output device be set to something suitable."));
     257    gc->setHelpText(QObject::tr("Enable if your amplifier or sound decoder supports DTS. "
     258                                "You must use a digital connection. Uncheck if using an analog connection"));
    251259    return gc;
    252260}
    253261
     
    19851993    return gc;
    19861994}
    19871995
    1988 static HostCheckBox *AggressiveBuffer()
    1989 {
    1990     HostCheckBox *gc = new HostCheckBox("AggressiveSoundcardBuffer");
    1991     gc->setLabel(QObject::tr("Aggressive Sound card Buffering"));
    1992     gc->setValue(false);
    1993     gc->setHelpText(QObject::tr("If enabled, MythTV will pretend to have "
    1994                    "a smaller sound card buffer than is really present.  This "
    1995                    "may speed up seeking, but can also cause playback "
    1996                    "problems."));
    1997     return gc;
    1998 }
    1999 
    20001996static HostCheckBox *ClearSavedPosition()
    20011997{
    20021998    HostCheckBox *gc = new HostCheckBox("ClearSavedPosition");
     
    35053501    return gs;
    35063502}
    35073503
    3508 class AudioSystemSettingsGroup : public VerticalConfigurationGroup
     3504class AudioSystemSettingsGroup : public TriggeredConfigurationGroup
    35093505{
    35103506  public:
    35113507    AudioSystemSettingsGroup() :
    3512         VerticalConfigurationGroup(false, true, false, false)
     3508        TriggeredConfigurationGroup(false, true, false, false)
    35133509    {
    35143510        setLabel(QObject::tr("Audio System"));
    35153511        setUseLabel(false);
    35163512
    35173513        addChild(AudioOutputDevice());
    3518         addChild(PassThroughOutputDevice());
    35193514
    3520         addChild(MaxAudioChannels());
    3521         addChild(AudioUpmixType());
     3515        Setting *numchannels = MaxAudioChannels();
     3516        addChild(numchannels);
    35223517
    3523         // General boolean settings
    3524         addChild(AC3PassThrough());
    3525         addChild(DTSPassThrough());
    3526         addChild(AggressiveBuffer());
     3518        ConfigurationGroup *dummy =
     3519        new VerticalConfigurationGroup(false, true, false, false);
     3520
     3521        ConfigurationGroup *settings =
     3522        new VerticalConfigurationGroup(false, true, false, false);
     3523
     3524        settings->addChild(AudioUpmix());
     3525        settings->addChild(AudioUpmixType());
     3526        settings->addChild(PassThroughOutputDevice());
     3527
     3528        ConfigurationGroup *settings2 =
     3529        new HorizontalConfigurationGroup();
     3530        settings2->setLabel(QObject::tr("Audio Processing Capabilities"));
     3531        settings2->addChild(AC3PassThrough());
     3532        settings2->addChild(DTSPassThrough());
     3533
     3534        settings->addChild(settings2);
     3535
     3536        // Show surround/upmixer config only if 5.1 Audio is selected
     3537        setTrigger(numchannels);
     3538        addTarget("2", dummy);
     3539        addTarget("6", settings);
     3540       
    35273541    }
    35283542};
    35293543
  • mythtv/programs/mythtranscode/transcode.cpp

     
    3737    AudioReencodeBuffer(int audio_bits, int audio_channels)
    3838    {
    3939        Reset();
    40         const AudioSettings settings(audio_bits, audio_channels, 0, false);
     40        const AudioSettings settings(audio_bits, audio_channels, 0, 0, false);
    4141        Reconfigure(settings);
    4242        bufsize = 512000;
    4343        audiobuffer = new unsigned char[bufsize];
     
    210210        // Do nothing
    211211        return kMuteOff;
    212212    }
     213    virtual bool ToggleUpmix(void)
     214    {
     215        // Do nothing
     216        return false;
     217    }
    213218
     219    virtual void SetSWVolume(int new_volume, bool save)
     220    {
     221        // Do nothing
     222        return;
     223    }
     224    virtual int GetSWVolume(void)
     225    {
     226        // Do nothing
     227        return 100;
     228    }
     229
    214230    //  These are pure virtual in AudioOutput, but we don't need them here
    215231    virtual void bufferOutputData(bool){ return; }
    216232    virtual int readOutputData(unsigned char*, int ){ return 0; }