Guest
Public paste!

Untitled

By: a guest | Jun 16th, 2010 | Syntax: None | Size: 22.27 KB | Hits: 33 | Expires: Never
Copy text to clipboard
  1. Index: mythtv/libs/libmythtv/NuppelVideoPlayer.cpp
  2. ===================================================================
  3. --- mythtv/libs/libmythtv/NuppelVideoPlayer.cpp (revision 25121)
  4. +++ mythtv/libs/libmythtv/NuppelVideoPlayer.cpp (working copy)
  5. @@ -5134,6 +5134,21 @@
  6.      return false;
  7.  }
  8.  
  9. +bool NuppelVideoPlayer::ToggleVuvuzela()
  10. +{
  11. +    bool ret = false;
  12. +    if (audioOutput)
  13. +        ret = audioOutput->ToggleVuvuzela();
  14. +    if (decoder)
  15. +        decoder->SetDisablePassThrough(ret);
  16. +    return ret;
  17. +}
  18. +
  19. +bool NuppelVideoPlayer::IsVuvuzela()
  20. +{
  21. +    return audioOutput ? audioOutput->IsVuvuzela() : false;
  22. +}
  23. +
  24.  void NuppelVideoPlayer::Zoom(ZoomDirection direction)
  25.  {
  26.      if (videoOutput)
  27. Index: mythtv/libs/libmythtv/avformatdecoder.cpp
  28. ===================================================================
  29. --- mythtv/libs/libmythtv/avformatdecoder.cpp   (revision 25121)
  30. +++ mythtv/libs/libmythtv/avformatdecoder.cpp   (working copy)
  31. @@ -4639,6 +4639,7 @@
  32.      else if (ctx->codec_id == CODEC_ID_DTS)
  33.          passthru = allow_dts_passthru && !internal_vol;
  34.  
  35. +    passthru &= !GetNVP()->IsVuvuzela();
  36.      passthru &= !transcoding && !disable_passthru;
  37.      // Don't know any cards that support spdif clocked at < 44100
  38.      // Some US cable transmissions have 2ch 32k AC-3 streams
  39. Index: mythtv/libs/libmythtv/tv_play.h
  40. ===================================================================
  41. --- mythtv/libs/libmythtv/tv_play.h     (revision 25121)
  42. +++ mythtv/libs/libmythtv/tv_play.h     (working copy)
  43. @@ -436,6 +436,7 @@
  44.                                   const QStringList &actions);
  45.  
  46.      void ToggleUpmix(PlayerContext*);
  47. +    void ToggleVuvuzela(PlayerContext*);
  48.      void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true);
  49.      bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions);
  50.  
  51. Index: mythtv/libs/libmythtv/NuppelVideoPlayer.h
  52. ===================================================================
  53. --- mythtv/libs/libmythtv/NuppelVideoPlayer.h   (revision 25121)
  54. +++ mythtv/libs/libmythtv/NuppelVideoPlayer.h   (working copy)
  55. @@ -165,6 +165,8 @@
  56.      void ToggleAspectOverride(AspectOverrideMode aspectMode = kAspect_Toggle);
  57.      void ToggleAdjustFill(AdjustFillMode adjustfillMode = kAdjustFill_Toggle);
  58.      bool ToggleUpmix(void);
  59. +    bool ToggleVuvuzela(void);
  60. +    bool IsVuvuzela(void);
  61.  
  62.      // Gets
  63.      QSize   GetVideoBufferSize(void) const    { return video_dim; }
  64. Index: mythtv/libs/libmythtv/tv_play.cpp
  65. ===================================================================
  66. --- mythtv/libs/libmythtv/tv_play.cpp   (revision 25121)
  67. +++ mythtv/libs/libmythtv/tv_play.cpp   (working copy)
  68. @@ -4516,6 +4516,8 @@
  69.          ToggleTimeStretch(ctx);
  70.      else if (has_action("TOGGLEUPMIX", actions))
  71.          ToggleUpmix(ctx);
  72. +    else if (has_action("TOGGLEVUVUZELA", actions))
  73. +        ToggleVuvuzela(ctx);
  74.      else if (has_action("TOGGLESLEEP", actions))
  75.          ToggleSleepTimer(ctx);
  76.      else if (has_action("TOGGLERECORD", actions) && islivetv)
  77. @@ -8286,6 +8288,20 @@
  78.          ctx->nvp->GetOSD()->SetSettingsText(text, 5);
  79.  }
  80.  
  81. +void TV::ToggleVuvuzela(PlayerContext *ctx)
  82. +{
  83. +    if (!ctx->nvp || !ctx->nvp->HasAudioOut())
  84. +        return;
  85. +    QString text;
  86. +    if (ctx->nvp->ToggleVuvuzela())
  87. +        text = tr("Vuvuzela Filter On");
  88. +    else
  89. +        text = tr("Vuvuzela Filter Off");
  90. +
  91. +    if (ctx->nvp->GetOSD() && !browsemode)
  92. +        ctx->nvp->GetOSD()->SetSettingsText(text, 5);
  93. +}
  94. +
  95.  // dir in 10ms jumps
  96.  void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit)
  97.  {
  98. @@ -9949,6 +9965,8 @@
  99.          ToggleTimeStretch(actx);
  100.      else if (action == "TOGGLEUPMIX")
  101.          ToggleUpmix(actx);
  102. +    else if (action == "TOGGLEVUVUZELA")
  103. +        ToggleVuvuzela(actx);
  104.      else if (action.left(13) == "ADJUSTSTRETCH")
  105.      {
  106.          bool floatRead;
  107. @@ -10323,6 +10341,8 @@
  108.          new OSDGenericTree(treeMenu, tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC");
  109.      else if (category == "TOGGLEUPMIX")
  110.          new OSDGenericTree(treeMenu, tr("Toggle Audio Upmixer"), "TOGGLEUPMIX");
  111. +    else if (category == "TOGGLEVUVUZELA")
  112. +        new OSDGenericTree(treeMenu, tr("Toggle Vuvuzela Filter"), "TOGGLEVUVUZELA");
  113.      else if (category == "TIMESTRETCH")
  114.          FillMenuTimeStretch(ctx, treeMenu);
  115.      else if (category == "VIDEOSCAN")
  116. Index: mythtv/libs/libmythtv/tvosdmenuentry.cpp
  117. ===================================================================
  118. --- mythtv/libs/libmythtv/tvosdmenuentry.cpp    (revision 25121)
  119. +++ mythtv/libs/libmythtv/tvosdmenuentry.cpp    (working copy)
  120. @@ -236,6 +236,12 @@
  121.          "AUDIOSYNC",          1,  1,  1,  1, "Audio Sync"));
  122.      curMenuEntries.append(new TVOSDMenuEntry(
  123.          "TOGGLEUPMIX",        1,  1,  1,  1, "Toggle Upmixer"));
  124. +    if (gContext->GetNumSetting("AdvancedAudioSettings", false) &&
  125. +        gContext->GetNumSetting("VuvuzelaFilter", false))
  126. +    {
  127. +        curMenuEntries.append(new TVOSDMenuEntry(
  128. +            "TOGGLEVUVUZELA", 1,  1,  1,  1, "Toggle Vuvuzela Filter"));
  129. +    }
  130.      curMenuEntries.append(new TVOSDMenuEntry(
  131.          "TIMESTRETCH",        1,  1,  1,  1, "Time Stretch"));
  132.      curMenuEntries.append(new TVOSDMenuEntry(
  133. Index: mythtv/libs/libmyth/audiooutputbase.h
  134. ===================================================================
  135. --- mythtv/libs/libmyth/audiooutputbase.h       (revision 25121)
  136. +++ mythtv/libs/libmyth/audiooutputbase.h       (working copy)
  137. @@ -16,6 +16,7 @@
  138.  
  139.  // MythTV headers
  140.  #include "audiooutput.h"
  141. +#include "audiooutpututil.h"
  142.  #include "samplerate.h"
  143.  #include "mythverbose.h"
  144.  
  145. @@ -44,6 +45,8 @@
  146.      virtual void SetStretchFactor(float factor);
  147.      virtual float GetStretchFactor(void) const;
  148.      virtual bool ToggleUpmix(void);
  149. +    virtual bool ToggleVuvuzela(void);
  150. +    virtual bool IsVuvuzela(void) { return vuvuzela; }
  151.  
  152.      virtual void Reset(void);
  153.  
  154. @@ -230,6 +233,10 @@
  155.      /** main audio buffer */
  156.      unsigned char audiobuffer[kAudioRingBufferSize];
  157.      uint memory_corruption_test4;
  158. +
  159. +    //Vuvuzela filter
  160. +    bool vuvuzela, last_vuvuzela;
  161. +    AudioOutputUtil::Notch *notch_instance;
  162.  };
  163.  
  164.  #endif
  165. Index: mythtv/libs/libmyth/audiooutpututil.h
  166. ===================================================================
  167. --- mythtv/libs/libmyth/audiooutpututil.h       (revision 0)
  168. +++ mythtv/libs/libmyth/audiooutpututil.h       (revision 0)
  169. @@ -0,0 +1,71 @@
  170. +#ifndef AUDIOOUTPUTUTIL
  171. +#define AUDIOOUTPUTUTIL
  172. +
  173. +using namespace std;
  174. +
  175. +#define IIR_NUM_COEFFICIENTS                           (3)     // Assumed biquads
  176. +
  177. +class AudioOutputUtil
  178. +{
  179. + public:
  180. +    
  181. +    //Notch Filter / IRR transformation
  182. +    // Parameters
  183. +    typedef struct
  184. +    {
  185. +        uint N;
  186. +        uint num_biquads;
  187. +        float b[IIR_NUM_COEFFICIENTS];
  188. +        float a[IIR_NUM_COEFFICIENTS];
  189. +    } IIR_Parameters;
  190. +    
  191. +    // State information
  192. +    typedef struct
  193. +    {
  194. +        float a[IIR_NUM_COEFFICIENTS];
  195. +        float b[IIR_NUM_COEFFICIENTS];
  196. +        float x_mem[IIR_NUM_COEFFICIENTS];
  197. +        float y_mem[IIR_NUM_COEFFICIENTS];
  198. +    } IIR_State;
  199. +    
  200. +    // Instance
  201. +    typedef struct
  202. +    {
  203. +        IIR_Parameters parameters;
  204. +        IIR_State state;
  205. +    } IIR;
  206. +    
  207. +    // Parameters
  208. +    typedef struct
  209. +    {
  210. +        uint N;
  211. +        float frequency;                       // Notch frequency
  212. +        float attenuation_dB;          // Notch attenuation
  213. +    } Notch_Parameters;
  214. +
  215. +    // State information
  216. +
  217. +    typedef struct
  218. +    {
  219. +        float pole_position;
  220. +        float frequency_offset;
  221. +        float a1s;
  222. +        float a2;
  223. +        float depth_factor;
  224. +        float w0;              // Input weight
  225. +        float w1;              // Output weight
  226. +    } Notch_State;
  227. +
  228. +    // Instance
  229. +    typedef struct
  230. +    {
  231. +        Notch_Parameters parameters;
  232. +        Notch_State state;
  233. +        IIR iir;
  234. +    } Notch;
  235. +
  236. +    static void notch_update(Notch &instance, float fs);
  237. +    static void notch_execute(Notch &instance, float *in, float *out);
  238. +};
  239. +
  240. +#endif
  241. Index: mythtv/libs/libmyth/audiooutputbase.cpp
  242. ===================================================================
  243. --- mythtv/libs/libmyth/audiooutputbase.cpp     (revision 25121)
  244. +++ mythtv/libs/libmyth/audiooutputbase.cpp     (working copy)
  245. @@ -13,6 +13,7 @@
  246.  #include "compat.h"
  247.  #include "audiooutputbase.h"
  248.  #include "audiooutputdigitalencoder.h"
  249. +#include "audiooutpututil.h"
  250.  #include "SoundTouch.h"
  251.  #include "freesurround.h"
  252.  
  253. @@ -73,7 +74,9 @@
  254.      memory_corruption_test1(0xdeadbeef),
  255.      memory_corruption_test2(0xdeadbeef),
  256.      memory_corruption_test3(0xdeadbeef),
  257. -    memory_corruption_test4(0xdeadbeef)
  258. +    memory_corruption_test4(0xdeadbeef),
  259. +    vuvuzela(true),            last_vuvuzela(false),
  260. +    notch_instance(NULL)
  261.  {
  262.      // The following are not bzero() because MS Windows doesn't like it.
  263.      memset(&src_data,          0, sizeof(SRC_DATA));
  264. @@ -197,7 +200,17 @@
  265.      return (configured_audio_channels == 6);
  266.  }
  267.  
  268. +bool AudioOutputBase::ToggleVuvuzela(void)
  269. +{
  270. +    vuvuzela = !vuvuzela;
  271. +    const AudioSettings settings(audio_bits, source_audio_channels,
  272. +                                 audio_codec, source_audio_samplerate,
  273. +                                 audio_passthru);
  274. +    Reconfigure(settings);
  275.  
  276. +    return vuvuzela;
  277. +}
  278. +
  279.  void AudioOutputBase::Reconfigure(const AudioSettings &orig_settings)
  280.  {
  281.      AudioSettings settings = orig_settings;
  282. @@ -229,6 +242,7 @@
  283.          settings.samplerate == audio_samplerate && !need_resampler &&
  284.          settings.use_passthru == audio_passthru &&
  285.          lneeds_upmix == needs_upmix &&
  286. +        last_vuvuzela == vuvuzela &&
  287.          laudio_reenc == audio_reenc);
  288.      bool upmix_deps =
  289.          (lsource_audio_channels == source_audio_channels);
  290. @@ -247,6 +261,8 @@
  291.          return;
  292.      }
  293.  
  294. +    last_vuvuzela          = vuvuzela;
  295. +
  296.      KillAudio();
  297.  
  298.      QMutexLocker lock1(&audio_buflock);
  299. @@ -264,6 +280,7 @@
  300.      audio_codec = settings.codec;
  301.      audio_passthru = settings.use_passthru;
  302.      needs_upmix = lneeds_upmix;
  303. +    vuvuzela = last_vuvuzela;
  304.  
  305.      if (audio_bits != 8 && audio_bits != 16)
  306.      {
  307. @@ -341,6 +358,13 @@
  308.          need_resampler = true;
  309.      }
  310.  
  311. +    if (vuvuzela)
  312. +    {
  313. +        VERBOSE(VB_AUDIO, LOC + "Vuvuzela filter enabled. Go Socceroos Go!");
  314. +        if (!notch_instance)
  315. +            notch_instance = new AudioOutputUtil::Notch;
  316. +    }
  317. +
  318.      if (audio_enc)
  319.      {
  320.          VERBOSE(VB_AUDIO, LOC + "Creating AC-3 Encoder");
  321. @@ -497,6 +521,13 @@
  322.      needs_upmix = false;
  323.      audio_enc = false;
  324.  
  325. +    if (notch_instance)
  326. +    {
  327. +        delete notch_instance;
  328. +        notch_instance = NULL;
  329. +    }
  330. +    vuvuzela = false;
  331. +
  332.      CloseDevice();
  333.  
  334.      killAudioLock.unlock();
  335. @@ -790,7 +821,6 @@
  336.              VERBOSE(VB_IMPORTANT, LOC_ERR +
  337.                      QString("Error occurred while resampling audio: %1")
  338.                      .arg(src_strerror(error)));
  339. -
  340.          src_float_to_short_array(src_data.data_out, (short int*)tmp_buff,
  341.                                   src_data.output_frames_gen*audio_channels);
  342.  
  343. @@ -844,7 +874,7 @@
  344.      QMutexLocker lock1(&audio_buflock);
  345.  
  346.      // resample input if necessary
  347. -    if (need_resampler && src_ctx)
  348. +    if ((need_resampler && src_ctx) || (vuvuzela && notch_instance))
  349.      {
  350.          // Convert to floats
  351.          short *buf_ptr = (short*)buffer;
  352. @@ -853,17 +883,47 @@
  353.              src_in[sample] = (float)buf_ptr[sample] / (1.0 * 0x8000);
  354.          }
  355.  
  356. -        src_data.input_frames = samples;
  357. -        src_data.end_of_input = 0;
  358. -        int error = src_process(src_ctx, &src_data);
  359. -        if (error)
  360. -            VERBOSE(VB_IMPORTANT, LOC_ERR +
  361. -                    QString("Error occurred while resampling audio: %1")
  362. -                    .arg(src_strerror(error)));
  363. -        src_float_to_short_array(src_data.data_out, (short int*)tmp_buff,
  364. -                                 src_data.output_frames_gen*audio_channels);
  365. +        if (vuvuzela)
  366. +        {
  367. +            notch_instance->parameters.N = samples * audio_channels;
  368. +            // Notch attenuation
  369. +            notch_instance->parameters.attenuation_dB = 35.0f;
  370. +            
  371. +            // Notch frequency
  372. +            notch_instance->parameters.frequency = 233.0f;
  373. +            AudioOutputUtil::notch_update (*notch_instance, (float)source_audio_samplerate);
  374. +            AudioOutputUtil::notch_execute (*notch_instance, src_in, src_out);
  375. +            notch_instance->parameters.frequency = 466.0f;  // 1st harmonic
  376. +            AudioOutputUtil::notch_update (*notch_instance, (float)source_audio_samplerate);
  377. +            AudioOutputUtil::notch_execute (*notch_instance, src_out, src_in);
  378. +            notch_instance->parameters.frequency = 932.0f;  // 2nd harmonic
  379. +            AudioOutputUtil::notch_update (*notch_instance, (float)source_audio_samplerate);
  380. +            AudioOutputUtil::notch_execute (*notch_instance, src_in, src_out);
  381. +            notch_instance->parameters.frequency = 1864.0f;  // 3rd harmonic
  382. +            AudioOutputUtil::notch_update (*notch_instance, (float)source_audio_samplerate);
  383. +            AudioOutputUtil::notch_execute (*notch_instance, src_out, src_in);
  384. +        }
  385.  
  386. -        _AddSamples(tmp_buff, true, src_data.output_frames_gen, timecode);
  387. +        if (need_resampler)
  388. +        {
  389. +            src_data.input_frames = samples;
  390. +            src_data.end_of_input = 0;
  391. +            int error = src_process(src_ctx, &src_data);
  392. +            if (error)
  393. +                VERBOSE(VB_IMPORTANT, LOC_ERR +
  394. +                        QString("Error occurred while resampling audio: %1")
  395. +                        .arg(src_strerror(error)));
  396. +            src_float_to_short_array(src_data.data_out, (short int*)tmp_buff,
  397. +                                     src_data.output_frames_gen*audio_channels);
  398. +
  399. +            _AddSamples(tmp_buff, true, src_data.output_frames_gen, timecode);
  400. +        }
  401. +        else
  402. +        {
  403. +            src_float_to_short_array(src_in, (short int*)tmp_buff,
  404. +                                     samples * audio_channels);
  405. +            _AddSamples(tmp_buff, true, samples, timecode);
  406. +        }
  407.      }
  408.      else
  409.      {
  410. Index: mythtv/libs/libmyth/libmyth.pro
  411. ===================================================================
  412. --- mythtv/libs/libmyth/libmyth.pro     (revision 25121)
  413. +++ mythtv/libs/libmyth/libmyth.pro     (working copy)
  414. @@ -30,7 +30,7 @@
  415.  HEADERS += audiopulseutil.h
  416.  HEADERS += programinfo.h programlist.h programinfoupdater.h
  417.  HEADERS += recordingtypes.h remoteutil.h
  418. -HEADERS += rawsettingseditor.h
  419. +HEADERS += rawsettingseditor.h audiooutpututil.h
  420.  
  421.  # remove when everything is switched to mythui
  422.  HEADERS += virtualkeyboard_qt.h
  423. @@ -54,7 +54,7 @@
  424.  SOURCES += audiopulseutil.cpp
  425.  SOURCES += programinfo.cpp programlist.cpp programinfoupdater.cpp
  426.  SOURCES += recordingtypes.cpp remoteutil.cpp
  427. -SOURCES += rawsettingseditor.cpp
  428. +SOURCES += rawsettingseditor.cpp audiooutpututil.cpp
  429.  
  430.  # remove when everything is switched to mythui
  431.  SOURCES += virtualkeyboard_qt.cpp
  432. Index: mythtv/libs/libmyth/audiooutput.h
  433. ===================================================================
  434. --- mythtv/libs/libmyth/audiooutput.h   (revision 25121)
  435. +++ mythtv/libs/libmyth/audiooutput.h   (working copy)
  436. @@ -71,6 +71,8 @@
  437.      virtual void bufferOutputData(bool y) = 0;
  438.      virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0;
  439.      virtual bool ToggleUpmix(void) = 0;
  440. +    virtual bool ToggleVuvuzela(void) = 0;
  441. +    virtual bool IsVuvuzela(void) = 0;
  442.  
  443.    protected:
  444.      void Error(const QString &msg);
  445. Index: mythtv/libs/libmyth/audiooutpututil.cpp
  446. ===================================================================
  447. --- mythtv/libs/libmyth/audiooutpututil.cpp     (revision 0)
  448. +++ mythtv/libs/libmyth/audiooutpututil.cpp     (revision 0)
  449. @@ -0,0 +1,143 @@
  450. +#include "dsputil.h"
  451. +#include "mythconfig.h"
  452. +#include "audiooutpututil.h"
  453. +
  454. +#define IIR_NUM_COEFFICIENTS                           (3)     // Assumed biquads
  455. +
  456. +static void iir_update (AudioOutputUtil::IIR &instance)
  457. +{
  458. +       // Clear the filter state
  459. +    bzero(&instance.state.x_mem[0], IIR_NUM_COEFFICIENTS * sizeof(float));
  460. +    bzero(&instance.state.y_mem[0], IIR_NUM_COEFFICIENTS * sizeof(float));
  461. +    
  462. +    memcpy(&instance.state.b[0], &instance.parameters.b[0],
  463. +           IIR_NUM_COEFFICIENTS * sizeof(float));
  464. +    memcpy(&instance.state.a[0], &instance.parameters.a[0],
  465. +           IIR_NUM_COEFFICIENTS * sizeof(float));
  466. +}
  467. +
  468. +/* Notch filter (c) 2010 Hydrix & Jean-Yves Avenard */
  469. +/* www.hydrix.com */
  470. +
  471. +// Processes a single block of samples with a single IIR biquad stage
  472. +//    N                   M
  473. +//   SUM a(k+1) y(n-k) = SUM b(k+1) x(n-k)      for 1<=n<=length(x)
  474. +//   k=0                 k=0
  475. +// where N=length(a)-1 and M=length(b)-1.
  476. +// Vector s is the initial state of the system. The final state is also returned
  477. +// The state vector is a column vector whose length is equal to the
  478. +//     length of the longest coefficient vector minus one.
  479. +static void iir_biquad (float* x, float* y,
  480. +                        float* a, float* b,
  481. +                        float* x_mem, float* y_mem,
  482. +                        unsigned int N)
  483. +{
  484. +       // Direct Form I
  485. +       //               N+1               N+1
  486. +       //              y(n) = - SUM a(k) y(n-k) + SUM b(k) x(n-k)  for 0 <= n <length(x)
  487. +       //               k=1               k=0
  488. +       unsigned int n = 0;
  489. +       unsigned int k = 0;
  490. +       float y_n_minus_k = 0.0f;
  491. +       float x_n_minus_k = 0.0f;
  492. +       for (n = 0; n < N; n++)
  493. +       {
  494. +               y[n] = x[n] * b[0];
  495. +        
  496. +               for (k = 1; k < IIR_NUM_COEFFICIENTS; k++)
  497. +               {
  498. +                       signed int n_minus_k = n - k;
  499. +                       if (n_minus_k >= 0)
  500. +                       {
  501. +                               x_n_minus_k = x[n_minus_k];
  502. +                               y_n_minus_k = y[n_minus_k];
  503. +                       }
  504. +                       else
  505. +                       {
  506. +                               x_n_minus_k = x_mem[-n_minus_k-1];
  507. +                               y_n_minus_k = y_mem[-n_minus_k-1];
  508. +                       }
  509. +            
  510. +                       y[n] -= a[k] * y_n_minus_k;
  511. +                       y[n] += b[k] * x_n_minus_k;
  512. +               }
  513. +       }
  514. +    
  515. +       // Save input and output state, latest first
  516. +       unsigned int state_offset = N - 1;
  517. +       for (n=0; n < (IIR_NUM_COEFFICIENTS-1); n++)
  518. +       {
  519. +               x_mem[n] = x[state_offset];
  520. +               y_mem[n] = y[state_offset];
  521. +               state_offset--;
  522. +       }
  523. +}
  524. +
  525. +static void iir_execute(AudioOutputUtil::IIR &instance, float* x, float* y)
  526. +{
  527. +    iir_biquad(x, y,
  528. +               &instance.state.a[0], &instance.state.b[0],
  529. +               &instance.state.x_mem[0], &instance.state.y_mem[0],
  530. +               instance.parameters.N);
  531. +}
  532. +
  533. +// Notch filter
  534. +#define PI_FLOAT                    (3.14159265358979f)
  535. +
  536. +void AudioOutputUtil::notch_update (Notch &instance, float fs)
  537. +{
  538. +       instance.state.pole_position = 0.99f;
  539. +       instance.state.frequency_offset = 0.0f; // in normalised frequency (1.0 = fs)
  540. +       instance.state.a1s = -instance.state.pole_position;
  541. +       instance.state.a2 = -(instance.state.pole_position * instance.state.pole_position);
  542. +       instance.state.depth_factor = 0.999f;
  543. +
  544. +       // Calculate filter coefficients
  545. +       // Direct-form IIR
  546. +       // Ref: http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt and others
  547. +       float normalised_notch_frequency = (2.0f * instance.parameters.frequency / fs);
  548. +       normalised_notch_frequency += instance.state.frequency_offset;
  549. +       float frequency_factor = -2.0f * cosf(PI_FLOAT * normalised_notch_frequency);
  550. +       float a1 = frequency_factor * instance.state.a1s;
  551. +       float a2 = instance.state.a2;
  552. +       float b1 = frequency_factor * instance.state.depth_factor;
  553. +       float b2 = instance.state.depth_factor * instance.state.depth_factor;
  554. +       instance.iir.parameters.N = instance.parameters.N;
  555. +       instance.iir.parameters.a[0] = 1.0f;
  556. +       instance.iir.parameters.a[1] = -a1;
  557. +       instance.iir.parameters.a[2] = -a2;
  558. +       instance.iir.parameters.b[0] = 1.0f;
  559. +       instance.iir.parameters.b[1] = b1;
  560. +       instance.iir.parameters.b[2] = b2;
  561. +
  562. +       // Initialise the IIR stage
  563. +       iir_update(instance.iir);
  564. +
  565. +       // The notch filter strongly attenuates at the notch frequency.
  566. +       // The output is the weighted sum of the input and the
  567. +       //      notch-filtered input.  The weights are calculated from the
  568. +       //      attenuation parameters
  569. +       // instance.state.w0 = pow(10.0, (-instance.parameters.attenuation_dB / 20.0));
  570. +       // instance.state.w1 = 1.0 - instance.state.w0;
  571. +       float w0 = powf(10.0f, (-instance.parameters.attenuation_dB / 20.0f));
  572. +       float w1 = 1.0f - w0;
  573. +       instance.state.w0 = w0;
  574. +       instance.state.w1 = w1;
  575. +
  576. +       return;
  577. +}
  578. +
  579. +// Processes a single block of samples
  580. +void AudioOutputUtil::notch_execute (Notch &instance, float *in, float *out)
  581. +{
  582. +    // Apply the rejection filter
  583. +    iir_execute(instance.iir, in, out);
  584. +
  585. +    // The output is the weighted sum of the input and the
  586. +    // notch-filtered input
  587. +    for (uint i=0; i < instance.parameters.N; i++)
  588. +    {
  589. +        out[i] *= instance.state.w1;
  590. +        out[i] += instance.state.w0 * in[i];
  591. +    }
  592. +}
  593. Index: mythtv/programs/mythfrontend/globalsettings.cpp
  594. ===================================================================
  595. --- mythtv/programs/mythfrontend/globalsettings.cpp     (revision 25121)
  596. +++ mythtv/programs/mythfrontend/globalsettings.cpp     (working copy)
  597. @@ -181,6 +181,17 @@
  598.      return gc;
  599.  }
  600.  
  601. +static HostCheckBox *VuvuzelaFilter()
  602. +{
  603. +    HostCheckBox *gc = new HostCheckBox("VuvuzelaFilter");
  604. +    gc->setLabel(QObject::tr("Enable vuvuzela filter"));
  605. +    gc->setValue(false);
  606. +    gc->setHelpText(QObject::tr("With this option enabled, a dedicated vuvuzela "
  607. +                                "filter option will be accessible in the playback "
  608. +                                "menu"));
  609. +    return gc;
  610. +}
  611. +
  612.  static HostCheckBox *MythControlsVolume()
  613.  {
  614.      HostCheckBox *gc = new HostCheckBox("MythControlsVolume");
  615. @@ -3485,6 +3496,7 @@
  616.      settings2->addChild(srcqualityoverride);
  617.      settings2->addChild(sub3);
  618.      
  619. +    group2->addChild(VuvuzelaFilter());
  620.      group2->addChild(settings2);
  621.      group2->addChild(AggressiveBuffer());
  622.  
  623. Index: mythtv/programs/mythtranscode/transcode.cpp
  624. ===================================================================
  625. --- mythtv/programs/mythtranscode/transcode.cpp (revision 25121)
  626. +++ mythtv/programs/mythtranscode/transcode.cpp (working copy)
  627. @@ -217,7 +217,16 @@
  628.          // Do nothing
  629.          return false;
  630.      }
  631. -
  632. +    virtual bool ToggleVuvuzela(void)
  633. +    {
  634. +        // Do nothing
  635. +        return false;
  636. +    }
  637. +    virtual bool IsVuvuzela(void)
  638. +    {
  639. +        // Do nothing
  640. +        return false;
  641. +    }
  642.      virtual void SetSWVolume(int new_volume, bool save)
  643.      {
  644.          // Do nothing