Ticket #8568: vuvuzela-trunk25136.patch

File vuvuzela-trunk25136.patch, 19.6 KB (added by JYA, 10 years ago)

Patch for SVN > r25136

  • mythtv/libs/libmythtv/tv_play.h

     
    433433                                 const QStringList &actions);
    434434
    435435    void ToggleUpmix(PlayerContext*);
     436    void ToggleVuvuzela(PlayerContext*);
    436437    void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true);
    437438    bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions);
    438439
  • mythtv/libs/libmythtv/audioplayer.cpp

     
    269269    return toggle;
    270270}
    271271
     272bool AudioPlayer::ToggleVuvuzela(void)
     273{
     274    bool toggle = false;
     275    m_lock.lock();
     276    if (m_audioOutput)
     277        toggle = m_audioOutput->ToggleVuvuzela();
     278    if (m_parent->GetDecoder())
     279        m_parent->GetDecoder()->SetDisablePassThrough(toggle);       
     280    m_lock.unlock();
     281    return toggle;
     282}
     283
    272284void AudioPlayer::SetStretchFactor(float factor)
    273285{
    274286    m_stretchfactor = factor;
  • mythtv/libs/libmythtv/tv_play.cpp

     
    42194219        ToggleTimeStretch(ctx);
    42204220    else if (has_action("TOGGLEUPMIX", actions))
    42214221        ToggleUpmix(ctx);
     4222    else if (has_action("TOGGLEVUVUZELA", actions))
     4223        ToggleVuvuzela(ctx);
    42224224    else if (has_action("TOGGLESLEEP", actions))
    42234225        ToggleSleepTimer(ctx);
    42244226    else if (has_action("TOGGLERECORD", actions) && islivetv)
     
    78747876        SetOSDMessage(ctx, text);
    78757877}
    78767878
     7879void TV::ToggleVuvuzela(PlayerContext *ctx)
     7880{
     7881    if (!ctx->nvp || !ctx->nvp->HasAudioOut())
     7882        return;
     7883    QString text;
     7884    if (ctx->nvp->GetAudio()->ToggleVuvuzela())
     7885        text = tr("Vuvuzela Filter On");
     7886    else
     7887        text = tr("Vuvuzela Filter Off");
     7888
     7889    if (!browsemode)
     7890        SetOSDMessage(ctx, text);
     7891}
     7892
    78777893// dir in 10ms jumps
    78787894void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit)
    78797895{
     
    96399655        ToggleTimeStretch(actx);
    96409656    else if (action == "TOGGLEUPMIX")
    96419657        ToggleUpmix(actx);
     9658    else if (action == "TOGGLEVUVUZELA")
     9659        ToggleVuvuzela(actx);
    96429660    else if (action.left(13) == "ADJUSTSTRETCH")
    96439661    {
    96449662        bool floatRead;
     
    99169934
    99179935    if (category == "DVD" && top && (ctx->GetState() == kState_WatchingDVD))
    99189936    {
    9919         osd->DialogAddButton(tr("DVD Root Menu"),        "JUMPTODVDROOTMENU");
    9920         osd->DialogAddButton(tr("DVD Title Menu"),       "JUMPTODVDTITLEMENU");
    9921         osd->DialogAddButton(tr("DVD Chapter Menu"),     "JUMPTODVDCHAPTERMENU");
     9937        osd->DialogAddButton(tr("DVD Root Menu"),          "JUMPTODVDROOTMENU");
     9938        osd->DialogAddButton(tr("DVD Title Menu"),         "JUMPTODVDTITLEMENU");
     9939        osd->DialogAddButton(tr("DVD Chapter Menu"),       "JUMPTODVDCHAPTERMENU");
    99229940    }
    99239941    else if (category == "GUIDE" && top)
    9924         osd->DialogAddButton(tr("Program Guide"),        "GUIDE");
     9942        osd->DialogAddButton(tr("Program Guide"),          "GUIDE");
    99259943    else if (category == "EDITCHANNEL" && top)
    9926         osd->DialogAddButton(tr("Edit Channel"),         "EDIT");
     9944        osd->DialogAddButton(tr("Edit Channel"),           "EDIT");
    99279945    else if (category == "EDITRECORDING" && top)
    9928         osd->DialogAddButton(tr("Edit Recording"),       "EDIT");
     9946        osd->DialogAddButton(tr("Edit Recording"),         "EDIT");
    99299947    else if (category == "TOGGLEBROWSE" && top && !db_browse_always)
    9930         osd->DialogAddButton(tr("Enable Browse Mode"),   "TOGGLEBROWSE");
     9948        osd->DialogAddButton(tr("Enable Browse Mode"),     "TOGGLEBROWSE");
    99319949    else if ( category == "PREVCHAN" && top)
    9932         osd->DialogAddButton(tr("Previous Channel"),     "PREVCHAN");
     9950        osd->DialogAddButton(tr("Previous Channel"),       "PREVCHAN");
    99339951    else if (category == "AUDIOSYNC" && top)
    9934         osd->DialogAddButton(tr("Adjust Audio Sync"),    "TOGGLEAUDIOSYNC");
     9952        osd->DialogAddButton(tr("Adjust Audio Sync"),      "TOGGLEAUDIOSYNC");
    99359953    else if (category == "TOGGLEUPMIX" && top)
    9936         osd->DialogAddButton(tr("Toggle Audio Upmixer"), "TOGGLEUPMIX");
     9954        osd->DialogAddButton(tr("Toggle Audio Upmixer"),   "TOGGLEUPMIX");
     9955    else if (category == "TOGGLEVUVUZELA" && top)
     9956        osd->DialogAddButton(tr("Toggle Vuvuzela Filter"), "TOGGLEVUVUZELA");
    99379957    else if (category == "MANUALZOOM"  && mainCtx && top)
    9938         osd->DialogAddButton(tr("Manual Zoom Mode"),     "TOGGLEMANUALZOOM");
     9958        osd->DialogAddButton(tr("Manual Zoom Mode"),       "TOGGLEMANUALZOOM");
    99399959    else if (category == "TRANSCODE")
    99409960        title = FillOSDMenuTranscode(ctx, osd, select, level);
    99419961    else if (category == "COMMSKIP")
  • mythtv/libs/libmythtv/tvosdmenuentry.cpp

     
    11#include "tvosdmenuentry.h"
    22#include "mythdb.h"
    33#include "mythverbose.h"
     4#include "mythcorecontext.h"
    45
    56#define LOC QString("OSDMenuEntry:")
    67#define LOC_ERR QString("OSDMenuEntry Error:")
     
    243244        "AUDIOSYNC",          1,  1,  1,  1, "Audio Sync"));
    244245    curMenuEntries.append(new TVOSDMenuEntry(
    245246        "TOGGLEUPMIX",        1,  1,  1,  1, "Toggle Upmixer"));
     247    if (gCoreContext->GetNumSetting("AdvancedAudioSettings", false) &&
     248        gCoreContext->GetNumSetting("VuvuzelaFilter", false))
     249    {
     250        curMenuEntries.append(new TVOSDMenuEntry(
     251            "TOGGLEVUVUZELA",        1,  1,  1,  1, "Toggle Vuvuzela Filter"));
     252    }
    246253    curMenuEntries.append(new TVOSDMenuEntry(
    247254        "TIMESTRETCH",        1,  1,  1,  1, "Time Stretch"));
    248255    curMenuEntries.append(new TVOSDMenuEntry(
  • mythtv/libs/libmythtv/audioplayer.h

     
    3333    float GetStretchFactor(void) { return m_stretchfactor;   }
    3434    void  SetStretchFactor(float factor);
    3535    bool  ToggleUpmix(void);
     36    bool  ToggleVuvuzela(void);
    3637    bool  CanPassthrough(void);
    3738    long long GetAudioTime(void);
    3839
  • mythtv/libs/libmyth/audiooutputbase.h

     
    1717// MythTV headers
    1818#include "audiooutput.h"
    1919#include "audiooutputsettings.h"
     20#include "audiooutpututil.h"
    2021#include "samplerate.h"
    2122#include "mythverbose.h"
    2223
     
    5051
    5152    virtual bool CanPassthrough(bool willreencode=true) const;
    5253    virtual bool ToggleUpmix(void);
     54    virtual bool ToggleVuvuzela(void);
    5355
    5456    virtual void Reset(void);
    5557
     
    211213    /** main audio buffer */
    212214    uchar audiobuffer[kAudioRingBufferSize];
    213215    uint memory_corruption_test3;
     216
     217    //Vuvuzela filter
     218    bool vuvuzela, last_vuvuzela;
     219    AudioOutputUtil::Notch *notch_instance;
    214220};
    215221
    216222#endif
  • mythtv/libs/libmyth/audiooutpututil.h

     
    55#include "mythverbose.h"
    66#include "audiooutputsettings.h"
    77
     8#define IIR_NUM_COEFFICIENTS    (3)     // Assumed biquads
     9
    810class AudioOutputUtil
    911{
    1012 public:
     13 
     14    //Notch Filter / IRR transformation
     15    // Parameters
     16    typedef struct
     17    {
     18        uint N;
     19        uint num_biquads;
     20        float b[IIR_NUM_COEFFICIENTS];
     21        float a[IIR_NUM_COEFFICIENTS];
     22    } IIR_Parameters;
     23   
     24    // State information
     25    typedef struct
     26    {
     27        float a[IIR_NUM_COEFFICIENTS];
     28        float b[IIR_NUM_COEFFICIENTS];
     29        float x_mem[IIR_NUM_COEFFICIENTS];
     30        float y_mem[IIR_NUM_COEFFICIENTS];
     31    } IIR_State;
     32
     33    // Instance
     34    typedef struct
     35    {
     36        IIR_Parameters parameters;
     37        IIR_State state;
     38    } IIR;
     39
     40    // Parameters
     41    typedef struct
     42    {
     43        uint N;
     44        float frequency;        // Notch frequency
     45    } Notch_Parameters;
     46
     47    // State information
     48
     49    typedef struct
     50    {
     51        float pole_position;
     52        float frequency_offset;
     53        float a1s;
     54        float a2;
     55        float depth_factor;
     56    } Notch_State;
     57
     58    // Instance
     59    typedef struct
     60    {
     61        Notch_Parameters parameters;
     62        Notch_State state;
     63        IIR iir;
     64    } Notch;
     65
    1166    static int  toFloat(AudioFormat format, void *out, void *in, int bytes);
    1267    static int  fromFloat(AudioFormat format, void *out, void *in, int bytes);
    1368    static void MonoToStereo(void *dst, void *src, int samples);
     
    1570                             bool music, bool upmix);
    1671    static void MuteChannel(int obits, int channels, int ch,
    1772                            void *buffer, int bytes);
     73    static void notch_update(Notch &instance, float fs);
     74    static void notch_execute(Notch &instance, float *in, float *out);
    1875};
    1976
    2077#endif
  • mythtv/libs/libmyth/audiooutputbase.cpp

     
    9494    memory_corruption_test0(0xdeadbeef),
    9595    memory_corruption_test1(0xdeadbeef),
    9696    memory_corruption_test2(0xdeadbeef),
    97     memory_corruption_test3(0xdeadbeef)
     97    memory_corruption_test3(0xdeadbeef),
     98    vuvuzela(false),            last_vuvuzela(false),
     99    notch_instance(NULL)
    98100{
    99101    src_in = (float *)AOALIGN(src_in_buf);
    100102    // The following are not bzero() because MS Windows doesn't like it.
     
    249251}
    250252
    251253/**
     254 * Toggle Vuvuzela filter
     255 */
     256bool AudioOutputBase::ToggleVuvuzela(void)
     257{
     258    // Reset audiobuffer now to prevent click
     259    audio_buflock.lock();
     260    avsync_lock.lock();
     261    waud = raud = 0;
     262
     263    vuvuzela = !vuvuzela;
     264    const AudioSettings settings(format, source_channels, codec,
     265                                 source_samplerate, passthru);
     266    audio_buflock.unlock();
     267    avsync_lock.unlock();
     268    Reconfigure(settings);
     269
     270    return vuvuzela;
     271}
     272
     273/**
    252274 * (Re)Configure AudioOutputBase
    253275 *
    254276 * Must be called from concrete subclasses
     
    312334                        settings.use_passthru == passthru &&
    313335                        lneeds_upmix == needs_upmix && lreenc == reenc &&
    314336                        lsource_channels == source_channels &&
     337                        last_vuvuzela == vuvuzela &&
    315338                        lneeds_downmix == needs_downmix;
    316339
    317340    if (general_deps)
     
    320343        return;
    321344    }
    322345
     346    last_vuvuzela          = vuvuzela;
     347
    323348    KillAudio();
    324349
    325350    QMutexLocker lock(&audio_buflock);
     
    337362    needs_downmix          = lneeds_downmix;
    338363    format                 = output_format   = settings.format;
    339364    source_samplerate      = samplerate      = settings.samplerate;
     365    vuvuzela               = last_vuvuzela;
    340366
    341367    killaudio = pauseaudio = false;
    342368    was_paused = true;
     
    424450    // Turn on float conversion?
    425451    if (need_resampler || needs_upmix || needs_downmix ||
    426452        stretchfactor != 1.0f || (internal_vol && SWVolume()) ||
    427         (enc && output_format != FORMAT_S16) ||
     453        (enc && output_format != FORMAT_S16) || vuvuzela ||
    428454        !output_settings->IsSupportedFormat(output_format))
    429455    {
    430456        VBAUDIO("Audio processing enabled");
     
    435461            output_format = output_settings->BestSupportedFormat();
    436462    }
    437463
     464    if (vuvuzela)
     465    {
     466        VBAUDIO("Vuvuzela filter enabled. Go Socceroos Go!");
     467        if (!notch_instance)
     468            notch_instance = new AudioOutputUtil::Notch;
     469    }
     470
    438471    if (passthru)
    439472        channels = 2; // IEC958 bitstream - 2 ch
    440473
     
    569602        src_ctx = NULL;
    570603    }
    571604
    572     needs_upmix = need_resampler = enc = false;
     605    if (notch_instance)
     606    {
     607        delete notch_instance;
     608        notch_instance = NULL;
     609    }
    573610
     611    needs_upmix = need_resampler = enc = vuvuzela = false;
     612
    574613    CloseDevice();
    575614
    576615    killAudioLock.unlock();
     
    952991            return false; // would overflow
    953992    }
    954993
     994    if (vuvuzela && notch_instance)
     995    {
     996        notch_instance->parameters.N = frames * channels;
     997
     998            // Notch frequency
     999        notch_instance->parameters.frequency = 235.0f;
     1000        AudioOutputUtil::notch_update (*notch_instance, (float)source_samplerate);
     1001        AudioOutputUtil::notch_execute (*notch_instance, src_in, src_out);
     1002        notch_instance->parameters.frequency = 465.0f;  // 1st harmonic
     1003        AudioOutputUtil::notch_update (*notch_instance, (float)source_samplerate);
     1004        AudioOutputUtil::notch_execute (*notch_instance, src_out, src_in);
     1005    }
     1006
    9551007    // Perform downmix if necessary
    9561008    if (needs_downmix)
    9571009        if(AudioOutputDownmix::DownmixFrames(source_channels, channels,
  • mythtv/libs/libmyth/audiooutput.h

     
    6969    virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0;
    7070
    7171    virtual bool ToggleUpmix(void) = 0;
     72    virtual bool ToggleVuvuzela(void) = 0;
    7273
    7374  protected:
    7475    void Error(const QString &msg);
  • mythtv/libs/libmyth/audiooutpututil.cpp

     
    610610    else
    611611        _MuteChannel((int *)buffer, channels, ch, frames);
    612612}
     613
     614#define IIR_NUM_COEFFICIENTS                            (3)     // Assumed biquads
     615
     616static void iir_update (AudioOutputUtil::IIR &instance)
     617{
     618        // Clear the filter state
     619    bzero(&instance.state.x_mem[0], IIR_NUM_COEFFICIENTS * sizeof(float));
     620    bzero(&instance.state.y_mem[0], IIR_NUM_COEFFICIENTS * sizeof(float));
     621   
     622    memcpy(&instance.state.b[0], &instance.parameters.b[0],
     623           IIR_NUM_COEFFICIENTS * sizeof(float));
     624    memcpy(&instance.state.a[0], &instance.parameters.a[0],
     625           IIR_NUM_COEFFICIENTS * sizeof(float));
     626}
     627
     628/* Notch filter (c) 2010 Hydrix & Jean-Yves Avenard */
     629/* www.hydrix.com */
     630
     631// Processes a single block of samples with a single IIR biquad stage
     632//    N                   M
     633//   SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k)      for 1<=n<=length(x)
     634//   k=0                 k=0
     635// where N=length(a)-1 and M=length(b)-1.
     636// Vector s is the initial state of the system. The final state is also returned
     637// The state vector is a column vector whose length is equal to the
     638//      length of the longest coefficient vector minus one.
     639static void iir_biquad (float* x, float* y,
     640                        float* a, float* b,
     641                        float* x_mem, float* y_mem,
     642                        unsigned int N)
     643{
     644   // Direct Form I
     645   //               N+1               N+1
     646   //           y(n) = - SUM a(k) y(n-k) + SUM b(k) x(n-k)  for 0 <= n <length(x)
     647   //               k=1               k=0
     648    unsigned int n = 0;
     649    unsigned int k = 0;
     650    float y_n_minus_k = 0.0f;
     651    float x_n_minus_k = 0.0f;
     652    for (n = 0; n < N; n++)
     653    {
     654        y[n] = x[n] * b[0];
     655
     656        for (k = 1; k < IIR_NUM_COEFFICIENTS; k++)
     657        {
     658            signed int n_minus_k = n - k;
     659            if (n_minus_k >= 0)
     660            {
     661                x_n_minus_k = x[n_minus_k];
     662                y_n_minus_k = y[n_minus_k];
     663            }
     664            else
     665            {
     666                x_n_minus_k = x_mem[-n_minus_k-1];
     667                y_n_minus_k = y_mem[-n_minus_k-1];
     668            }
     669
     670            y[n] -= a[k] * y_n_minus_k;
     671            y[n] += b[k] * x_n_minus_k;
     672        }
     673    }
     674
     675        // Save input and output state, latest first
     676    unsigned int state_offset = N - 1;
     677    for (n=0; n < (IIR_NUM_COEFFICIENTS-1); n++)
     678    {
     679        x_mem[n] = x[state_offset];
     680        y_mem[n] = y[state_offset];
     681        state_offset--;
     682    }
     683}
     684
     685static void iir_execute(AudioOutputUtil::IIR &instance, float* x, float* y)
     686{
     687    iir_biquad(x, y,
     688               &instance.state.a[0], &instance.state.b[0],
     689               &instance.state.x_mem[0], &instance.state.y_mem[0],
     690               instance.parameters.N);
     691}
     692
     693// Notch filter
     694#define PI_FLOAT                    (3.14159265358979f)
     695
     696void AudioOutputUtil::notch_update (Notch &instance, float fs)
     697{
     698    instance.state.pole_position = 0.99f;
     699    instance.state.frequency_offset = 0.0f; // in normalised frequency (1.0 = fs)
     700    instance.state.a1s = -instance.state.pole_position;
     701    instance.state.a2 = -(instance.state.pole_position * instance.state.pole_position);
     702    instance.state.depth_factor = 1.0f;
     703
     704        // Calculate filter coefficients
     705        // Direct-form IIR
     706        // Ref: http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt and others
     707    float normalised_notch_frequency = (2.0f * instance.parameters.frequency / fs);
     708    normalised_notch_frequency += instance.state.frequency_offset;
     709    float frequency_factor = -2.0f * cosf(PI_FLOAT * normalised_notch_frequency);
     710    float a1 = frequency_factor * instance.state.a1s;
     711    float a2 = instance.state.a2;
     712    float b1 = frequency_factor * instance.state.depth_factor;
     713    float b2 = instance.state.depth_factor * instance.state.depth_factor;
     714    instance.iir.parameters.N = instance.parameters.N;
     715    instance.iir.parameters.a[0] = 1.0f;
     716    instance.iir.parameters.a[1] = -a1;
     717    instance.iir.parameters.a[2] = -a2;
     718    instance.iir.parameters.b[0] = 1.0f;
     719    instance.iir.parameters.b[1] = b1;
     720    instance.iir.parameters.b[2] = b2;
     721
     722        // Initialise the IIR stage
     723    iir_update(instance.iir);
     724}
     725
     726// Processes a single block of samples
     727void AudioOutputUtil::notch_execute (Notch &instance, float *in, float *out)
     728{
     729    // Apply the rejection filter
     730    iir_execute(instance.iir, in, out);
     731}
  • mythtv/programs/mythfrontend/globalsettings.cpp

     
    219219    return gc;
    220220}
    221221
     222static HostCheckBox *VuvuzelaFilter()
     223{
     224    HostCheckBox *gc = new HostCheckBox("VuvuzelaFilter");
     225    gc->setLabel(QObject::tr("Enable vuvuzela filter"));
     226    gc->setValue(false);
     227    gc->setHelpText(QObject::tr("With this option enabled, a dedicated vuvuzela "
     228                                "filter option will be accessible in the playback "
     229                                "menu"));
     230    return gc;
     231}
     232
    222233static HostCheckBox *MythControlsVolume()
    223234{
    224235    HostCheckBox *gc = new HostCheckBox("MythControlsVolume");
     
    33013312    settings4->addChild(srcqualityoverride);
    33023313    settings4->addChild(sub4);
    33033314
     3315    group2->addChild(VuvuzelaFilter());
    33043316    group2->addChild(settings4);
    33053317    group2->addChild(Audio48kOverride());
    33063318    group2->addChild(settings3);
  • mythtv/programs/mythtranscode/transcode.cpp

     
    186186        // Do nothing
    187187        return false;
    188188    }
    189 
     189    virtual bool ToggleVuvuzela(void)
     190    {
     191        // Do nothing
     192        return false;
     193    }
    190194    virtual void SetSWVolume(int new_volume, bool save)
    191195    {
    192196        // Do nothing