⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wahwah.cpp

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************  Audacity: A Digital Audio Editor  Wahwah.cpp  Effect programming:  Nasca Octavian Paul  UI programming:  Dominic Mazzoni (with the help of wxDesigner)  Vaughan Johnson (Preview)**********************************************************************/#include "Wahwah.h"#include "../WaveTrack.h"#include "../FFT.h"#include <math.h>#include <wx/intl.h>#include <wx/button.h>#include <wx/stattext.h>#include <wx/textctrl.h>#include <wx/sizer.h>#include <wx/intl.h>//// EffectWahwah//#define lfoskipsamples 30EffectWahwah::EffectWahwah(){   freq = float(1.5);   startphase = 0;   depth = (float)0.7;   freqofs = (float)0.3;   res = float(2.5);}wxString EffectWahwah::GetEffectDescription() {    // Note: This is useful only after values have been set.    return wxString::Format(_("Applied effect: %s frequency = %.1f Hz, start phase = %.0f deg, depth = %.0f%%, resonance = %.1f, frequency offset = %.0f%%"),                           this->GetEffectName().c_str(),                            freq,                            (startphase * 180 / M_PI),                            (depth * 100),                            res,                            (freqofs * 100)); } bool EffectWahwah::PromptUser(){   WahwahDialog dlog(this, mParent, -1, _("Wahwah"));   dlog.freq = freq;   dlog.freqoff = freqofs * 100;   dlog.startphase = startphase * 180 / M_PI;   dlog.res = res;   dlog.depth = depth * 100;   dlog.TransferDataToWindow();   dlog.CentreOnParent();   dlog.ShowModal();   if (!dlog.GetReturnCode())      return false;   freq = dlog.freq;   freqofs = dlog.freqoff / 100;   startphase = dlog.startphase * M_PI / 180;   res = dlog.res;   depth = dlog.depth / 100;   return true;}bool EffectWahwah::TransferParameters( Shuttle & shuttle ){     shuttle.TransferFloat(wxT("Freq"),freq,1.5f);   shuttle.TransferFloat(wxT("Phase"),startphase,0.0f);   shuttle.TransferFloat(wxT("Depth"),depth,0.7f);   shuttle.TransferFloat(wxT("Resonance"),res,2.5f);   shuttle.TransferFloat(wxT("Offset"),freqofs,0.3f);   return true;}bool EffectWahwah::NewTrackSimpleMono(){   lfoskip = freq * 2 * M_PI / mCurRate;   skipcount = 0;   xn1 = 0;   xn2 = 0;   yn1 = 0;   yn2 = 0;   b0 = 0;   b1 = 0;   b2 = 0;   a0 = 0;   a1 = 0;   a2 = 0;   phase = startphase;   if (mCurChannel == Track::RightChannel)      phase += (float)M_PI;   return true;}bool EffectWahwah::ProcessSimpleMono(float *buffer, sampleCount len){   float frequency, omega, sn, cs, alpha;   float in, out;   for (int i = 0; i < len; i++) {      in = buffer[i];            if ((skipcount++) % lfoskipsamples == 0) {         frequency = (1 + cos(skipcount * lfoskip + phase)) / 2;         frequency = frequency * depth * (1 - freqofs) + freqofs;         frequency = exp((frequency - 1) * 6);         omega = M_PI * frequency;         sn = sin(omega);         cs = cos(omega);         alpha = sn / (2 * res);         b0 = (1 - cs) / 2;         b1 = 1 - cs;         b2 = (1 - cs) / 2;         a0 = 1 + alpha;         a1 = -2 * cs;         a2 = 1 - alpha;      };      out = (b0 * in + b1 * xn1 + b2 * xn2 - a1 * yn1 - a2 * yn2) / a0;      xn2 = xn1;      xn1 = in;      yn2 = yn1;      yn1 = out;            // Prevents clipping      if (out < -1.0)         out = float(-1.0);      else if (out > 1.0)         out = float(1.0);            buffer[i] = (float) out;   }   return true;}// WDR: class implementations//----------------------------------------------------------------------------// WahwahDialog//----------------------------------------------------------------------------#define FREQ_MIN 1#define FREQ_MAX 40#define FREQOFF_MIN 0#define FREQOFF_MAX 100#define PHASE_MIN 0#define PHASE_MAX 359#define DEPTH_MIN 0#define DEPTH_MAX 100#define RES_MIN 0#define RES_MAX 100// WDR: event table for WahwahDialogBEGIN_EVENT_TABLE(WahwahDialog, wxDialog)    EVT_BUTTON(wxID_OK, WahwahDialog::OnOk)    EVT_BUTTON(wxID_CANCEL, WahwahDialog::OnCancel)    EVT_TEXT(ID_FREQTEXT, WahwahDialog::OnFreqText)    EVT_TEXT(ID_FREQOFFTEXT, WahwahDialog::OnFreqOffText)    EVT_TEXT(ID_PHASETEXT, WahwahDialog::OnPhaseText)    EVT_TEXT(ID_DEPTHTEXT, WahwahDialog::OnDepthText)    EVT_TEXT(ID_RESONANCETEXT, WahwahDialog::OnResonanceText)    EVT_SLIDER(ID_FREQSLIDER, WahwahDialog::OnFreqSlider)    EVT_SLIDER(ID_FREQOFFSLIDER, WahwahDialog::OnFreqOffSlider)    EVT_SLIDER(ID_PHASESLIDER, WahwahDialog::OnPhaseSlider)    EVT_SLIDER(ID_DEPTHSLIDER, WahwahDialog::OnDepthSlider)    EVT_SLIDER(ID_RESONANCESLIDER, WahwahDialog::OnResonanceSlider)    EVT_BUTTON(ID_BUTTON_PREVIEW, WahwahDialog::OnPreview)END_EVENT_TABLE()WahwahDialog::WahwahDialog(EffectWahwah * effect, 									wxWindow * parent, wxWindowID id, const wxString & title, 									const wxPoint & position, const wxSize & size, long style):wxDialog(parent, id, title, position, size, style){	m_pEffect = effect;   CreateWahwahDialog(this, TRUE);}bool WahwahDialog::Validate(){   return TRUE;}bool WahwahDialog::TransferDataToWindow(){   wxSlider *slider;   slider = GetFreqSlider();   if (slider)      slider->SetValue((int)(freq * 10));   slider = GetFreqOffSlider();   if (slider)      slider->SetValue((int)freqoff);   slider = GetDepthSlider();   if (slider)      slider->SetValue((int)depth);   slider = GetPhaseSlider();   if (slider)      slider->SetValue((int)startphase);   slider = GetResonanceSlider();   if (slider)      slider->SetValue((int)(res * 10));   wxTextCtrl *text = GetFreqText();   if (text) {      wxString str;      str.Printf(wxT("%.1f"), freq);      text->SetValue(str);   }   text = GetFreqOffText();   if (text) {      wxString str;      str.Printf(wxT("%d"), (int) freqoff);      text->SetValue(str);   }   text = GetPhaseText();   if (text) {      wxString str;      str.Printf(wxT("%d"), (int) startphase);      text->SetValue(str);   }   text = GetDepthText();   if (text) {      wxString str;      str.Printf(wxT("%d"), (int) depth);      text->SetValue(str);   }   text = GetResonanceText();   if (text) {      wxString str;      str.Printf(wxT("%.1f"), res);      text->SetValue(str);   }   return TRUE;}bool WahwahDialog::TransferDataFromWindow(){   wxTextCtrl *c;   long x;   c = GetFreqText();   if (c) {      double d;      c->GetValue().ToDouble(&d);      freq = TrapDouble(d * 10, FREQ_MIN, FREQ_MAX) / 10;   }   c = GetFreqOffText();   if (c) {      double d;      c->GetValue().ToDouble(&d);      freqoff = TrapDouble(d, FREQOFF_MIN, FREQOFF_MAX);   }   c = GetPhaseText();   if (c) {      c->GetValue().ToLong(&x);      startphase = TrapLong(x, PHASE_MIN, PHASE_MAX);   }   c = GetDepthText();   if (c) {      c->GetValue().ToLong(&x);      depth = TrapLong(x, DEPTH_MIN, DEPTH_MAX);   }   c = GetResonanceText();   if (c) {      double d;      c->GetValue().ToDouble(&d);      res = TrapDouble(d * 10, RES_MIN, RES_MAX) / 10;   }   return TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -