Ticket #8568: vuvuzela-trunk25136.patch
File vuvuzela-trunk25136.patch, 19.6 KB (added by , 14 years ago) |
---|
-
mythtv/libs/libmythtv/tv_play.h
433 433 const QStringList &actions); 434 434 435 435 void ToggleUpmix(PlayerContext*); 436 void ToggleVuvuzela(PlayerContext*); 436 437 void ChangeAudioSync(PlayerContext*, int dir, bool allowEdit = true); 437 438 bool AudioSyncHandleAction(PlayerContext*, const QStringList &actions); 438 439 -
mythtv/libs/libmythtv/audioplayer.cpp
269 269 return toggle; 270 270 } 271 271 272 bool 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 272 284 void AudioPlayer::SetStretchFactor(float factor) 273 285 { 274 286 m_stretchfactor = factor; -
mythtv/libs/libmythtv/tv_play.cpp
4219 4219 ToggleTimeStretch(ctx); 4220 4220 else if (has_action("TOGGLEUPMIX", actions)) 4221 4221 ToggleUpmix(ctx); 4222 else if (has_action("TOGGLEVUVUZELA", actions)) 4223 ToggleVuvuzela(ctx); 4222 4224 else if (has_action("TOGGLESLEEP", actions)) 4223 4225 ToggleSleepTimer(ctx); 4224 4226 else if (has_action("TOGGLERECORD", actions) && islivetv) … … 7874 7876 SetOSDMessage(ctx, text); 7875 7877 } 7876 7878 7879 void 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 7877 7893 // dir in 10ms jumps 7878 7894 void TV::ChangeAudioSync(PlayerContext *ctx, int dir, bool allowEdit) 7879 7895 { … … 9639 9655 ToggleTimeStretch(actx); 9640 9656 else if (action == "TOGGLEUPMIX") 9641 9657 ToggleUpmix(actx); 9658 else if (action == "TOGGLEVUVUZELA") 9659 ToggleVuvuzela(actx); 9642 9660 else if (action.left(13) == "ADJUSTSTRETCH") 9643 9661 { 9644 9662 bool floatRead; … … 9916 9934 9917 9935 if (category == "DVD" && top && (ctx->GetState() == kState_WatchingDVD)) 9918 9936 { 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"); 9922 9940 } 9923 9941 else if (category == "GUIDE" && top) 9924 osd->DialogAddButton(tr("Program Guide"), "GUIDE");9942 osd->DialogAddButton(tr("Program Guide"), "GUIDE"); 9925 9943 else if (category == "EDITCHANNEL" && top) 9926 osd->DialogAddButton(tr("Edit Channel"), "EDIT");9944 osd->DialogAddButton(tr("Edit Channel"), "EDIT"); 9927 9945 else if (category == "EDITRECORDING" && top) 9928 osd->DialogAddButton(tr("Edit Recording"), "EDIT");9946 osd->DialogAddButton(tr("Edit Recording"), "EDIT"); 9929 9947 else if (category == "TOGGLEBROWSE" && top && !db_browse_always) 9930 osd->DialogAddButton(tr("Enable Browse Mode"), "TOGGLEBROWSE");9948 osd->DialogAddButton(tr("Enable Browse Mode"), "TOGGLEBROWSE"); 9931 9949 else if ( category == "PREVCHAN" && top) 9932 osd->DialogAddButton(tr("Previous Channel"), "PREVCHAN");9950 osd->DialogAddButton(tr("Previous Channel"), "PREVCHAN"); 9933 9951 else if (category == "AUDIOSYNC" && top) 9934 osd->DialogAddButton(tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC");9952 osd->DialogAddButton(tr("Adjust Audio Sync"), "TOGGLEAUDIOSYNC"); 9935 9953 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"); 9937 9957 else if (category == "MANUALZOOM" && mainCtx && top) 9938 osd->DialogAddButton(tr("Manual Zoom Mode"), "TOGGLEMANUALZOOM");9958 osd->DialogAddButton(tr("Manual Zoom Mode"), "TOGGLEMANUALZOOM"); 9939 9959 else if (category == "TRANSCODE") 9940 9960 title = FillOSDMenuTranscode(ctx, osd, select, level); 9941 9961 else if (category == "COMMSKIP") -
mythtv/libs/libmythtv/tvosdmenuentry.cpp
1 1 #include "tvosdmenuentry.h" 2 2 #include "mythdb.h" 3 3 #include "mythverbose.h" 4 #include "mythcorecontext.h" 4 5 5 6 #define LOC QString("OSDMenuEntry:") 6 7 #define LOC_ERR QString("OSDMenuEntry Error:") … … 243 244 "AUDIOSYNC", 1, 1, 1, 1, "Audio Sync")); 244 245 curMenuEntries.append(new TVOSDMenuEntry( 245 246 "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 } 246 253 curMenuEntries.append(new TVOSDMenuEntry( 247 254 "TIMESTRETCH", 1, 1, 1, 1, "Time Stretch")); 248 255 curMenuEntries.append(new TVOSDMenuEntry( -
mythtv/libs/libmythtv/audioplayer.h
33 33 float GetStretchFactor(void) { return m_stretchfactor; } 34 34 void SetStretchFactor(float factor); 35 35 bool ToggleUpmix(void); 36 bool ToggleVuvuzela(void); 36 37 bool CanPassthrough(void); 37 38 long long GetAudioTime(void); 38 39 -
mythtv/libs/libmyth/audiooutputbase.h
17 17 // MythTV headers 18 18 #include "audiooutput.h" 19 19 #include "audiooutputsettings.h" 20 #include "audiooutpututil.h" 20 21 #include "samplerate.h" 21 22 #include "mythverbose.h" 22 23 … … 50 51 51 52 virtual bool CanPassthrough(bool willreencode=true) const; 52 53 virtual bool ToggleUpmix(void); 54 virtual bool ToggleVuvuzela(void); 53 55 54 56 virtual void Reset(void); 55 57 … … 211 213 /** main audio buffer */ 212 214 uchar audiobuffer[kAudioRingBufferSize]; 213 215 uint memory_corruption_test3; 216 217 //Vuvuzela filter 218 bool vuvuzela, last_vuvuzela; 219 AudioOutputUtil::Notch *notch_instance; 214 220 }; 215 221 216 222 #endif -
mythtv/libs/libmyth/audiooutpututil.h
5 5 #include "mythverbose.h" 6 6 #include "audiooutputsettings.h" 7 7 8 #define IIR_NUM_COEFFICIENTS (3) // Assumed biquads 9 8 10 class AudioOutputUtil 9 11 { 10 12 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 11 66 static int toFloat(AudioFormat format, void *out, void *in, int bytes); 12 67 static int fromFloat(AudioFormat format, void *out, void *in, int bytes); 13 68 static void MonoToStereo(void *dst, void *src, int samples); … … 15 70 bool music, bool upmix); 16 71 static void MuteChannel(int obits, int channels, int ch, 17 72 void *buffer, int bytes); 73 static void notch_update(Notch &instance, float fs); 74 static void notch_execute(Notch &instance, float *in, float *out); 18 75 }; 19 76 20 77 #endif -
mythtv/libs/libmyth/audiooutputbase.cpp
94 94 memory_corruption_test0(0xdeadbeef), 95 95 memory_corruption_test1(0xdeadbeef), 96 96 memory_corruption_test2(0xdeadbeef), 97 memory_corruption_test3(0xdeadbeef) 97 memory_corruption_test3(0xdeadbeef), 98 vuvuzela(false), last_vuvuzela(false), 99 notch_instance(NULL) 98 100 { 99 101 src_in = (float *)AOALIGN(src_in_buf); 100 102 // The following are not bzero() because MS Windows doesn't like it. … … 249 251 } 250 252 251 253 /** 254 * Toggle Vuvuzela filter 255 */ 256 bool 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 /** 252 274 * (Re)Configure AudioOutputBase 253 275 * 254 276 * Must be called from concrete subclasses … … 312 334 settings.use_passthru == passthru && 313 335 lneeds_upmix == needs_upmix && lreenc == reenc && 314 336 lsource_channels == source_channels && 337 last_vuvuzela == vuvuzela && 315 338 lneeds_downmix == needs_downmix; 316 339 317 340 if (general_deps) … … 320 343 return; 321 344 } 322 345 346 last_vuvuzela = vuvuzela; 347 323 348 KillAudio(); 324 349 325 350 QMutexLocker lock(&audio_buflock); … … 337 362 needs_downmix = lneeds_downmix; 338 363 format = output_format = settings.format; 339 364 source_samplerate = samplerate = settings.samplerate; 365 vuvuzela = last_vuvuzela; 340 366 341 367 killaudio = pauseaudio = false; 342 368 was_paused = true; … … 424 450 // Turn on float conversion? 425 451 if (need_resampler || needs_upmix || needs_downmix || 426 452 stretchfactor != 1.0f || (internal_vol && SWVolume()) || 427 (enc && output_format != FORMAT_S16) || 453 (enc && output_format != FORMAT_S16) || vuvuzela || 428 454 !output_settings->IsSupportedFormat(output_format)) 429 455 { 430 456 VBAUDIO("Audio processing enabled"); … … 435 461 output_format = output_settings->BestSupportedFormat(); 436 462 } 437 463 464 if (vuvuzela) 465 { 466 VBAUDIO("Vuvuzela filter enabled. Go Socceroos Go!"); 467 if (!notch_instance) 468 notch_instance = new AudioOutputUtil::Notch; 469 } 470 438 471 if (passthru) 439 472 channels = 2; // IEC958 bitstream - 2 ch 440 473 … … 569 602 src_ctx = NULL; 570 603 } 571 604 572 needs_upmix = need_resampler = enc = false; 605 if (notch_instance) 606 { 607 delete notch_instance; 608 notch_instance = NULL; 609 } 573 610 611 needs_upmix = need_resampler = enc = vuvuzela = false; 612 574 613 CloseDevice(); 575 614 576 615 killAudioLock.unlock(); … … 952 991 return false; // would overflow 953 992 } 954 993 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 955 1007 // Perform downmix if necessary 956 1008 if (needs_downmix) 957 1009 if(AudioOutputDownmix::DownmixFrames(source_channels, channels, -
mythtv/libs/libmyth/audiooutput.h
69 69 virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0; 70 70 71 71 virtual bool ToggleUpmix(void) = 0; 72 virtual bool ToggleVuvuzela(void) = 0; 72 73 73 74 protected: 74 75 void Error(const QString &msg); -
mythtv/libs/libmyth/audiooutpututil.cpp
610 610 else 611 611 _MuteChannel((int *)buffer, channels, ch, frames); 612 612 } 613 614 #define IIR_NUM_COEFFICIENTS (3) // Assumed biquads 615 616 static 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. 639 static 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 685 static 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 696 void 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 727 void 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
219 219 return gc; 220 220 } 221 221 222 static 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 222 233 static HostCheckBox *MythControlsVolume() 223 234 { 224 235 HostCheckBox *gc = new HostCheckBox("MythControlsVolume"); … … 3301 3312 settings4->addChild(srcqualityoverride); 3302 3313 settings4->addChild(sub4); 3303 3314 3315 group2->addChild(VuvuzelaFilter()); 3304 3316 group2->addChild(settings4); 3305 3317 group2->addChild(Audio48kOverride()); 3306 3318 group2->addChild(settings3); -
mythtv/programs/mythtranscode/transcode.cpp
186 186 // Do nothing 187 187 return false; 188 188 } 189 189 virtual bool ToggleVuvuzela(void) 190 { 191 // Do nothing 192 return false; 193 } 190 194 virtual void SetSWVolume(int new_volume, bool save) 191 195 { 192 196 // Do nothing