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

📄 noiseremoval.cpp

📁 Audacity是一款用於錄音和編輯聲音的、免費的開放源碼軟體。它可以執行於Mac OS X、Microsoft Windows、GNU/Linux和其它作業系統
💻 CPP
📖 第 1 页 / 共 2 页
字号:
         track->Set((samplePtr) buffer, floatSample, start + s, block);            s += block;            if (TrackProgress(count, s / (double) len)) {         retCode = false;         break;      }   }   delete[] buffer;   delete[] window1;   delete[] window2;      return retCode;}void EffectNoiseRemoval::GetProfile(sampleCount len,                                    float *buffer){   float *in = new float[len];   float *out = new float[len];      int i;      for(i=0; i<len; i++)      in[i] = buffer[i];   // Apply window and FFT   /* WindowFunc(3, len, in); // Hanning window */   PowerSpectrum(len, in, out);      for(i=0; i<=len/2; i++) {      float value = log(out[i]);            if (finite(value)) {         sum[i] += value;         sumsq[i] += value*value;         profileCount[i]++;      }   }   delete[] in;   delete[] out;}void EffectNoiseRemoval::RemoveNoise(sampleCount len, float *buffer){   float *inr = new float[len];   float *ini = new float[len];   float *outr = new float[len];   float *outi = new float[len];   float *power = new float[len];   float *plog = new float[len];      int i;      for(i=0; i<len; i++)      inr[i] = buffer[i];   // Apply window and FFT   /* WindowFunc(3, len, inr); // Hanning window */   FFT(len, false, inr, NULL, outr, outi);   for(i=0; i<len; i++)      inr[i] = buffer[i];   WindowFunc(3, len, inr); // Hanning window   PowerSpectrum(len, inr, power);   for(i=0; i<=len/2; i++)      plog[i] = log(power[i]);       int half = len/2;   for(i=0; i<=half; i++) {      float smooth;      //Factor of 4 here replaces previous 2, giving a //finer gradation of noise removal choice.            if (plog[i] < mNoiseGate[i] + (mLevel / 4.0))         smooth = float(0.0);      else         smooth = float(1.0);            smoothing[i] = smooth * 0.5 + smoothing[i] * 0.5;   }   /* try to eliminate tinkle bells */   for(i=2; i<=half-2; i++) {      if (smoothing[i]>=0.5 &&          smoothing[i]<=0.55 &&          smoothing[i-1]<0.1 &&          smoothing[i-2]<0.1 &&          smoothing[i+1]<0.1 &&          smoothing[i+2]<0.1)          smoothing[i] = float(0.0);   }   outr[0] *= smoothing[0];   outi[0] *= smoothing[0];   outr[half] *= smoothing[half];   outi[half] *= smoothing[half];   for(i=1; i<half; i++) {      int j = len - i;      float smooth = smoothing[i];      outr[i] *= smooth;      outi[i] *= smooth;      outr[j] *= smooth;      outi[j] *= smooth;   }   // Inverse FFT and normalization   FFT(len, true, outr, outi, inr, ini);   WindowFunc(3, len, inr); // Hanning window */      for(i=0; i<len; i++)      buffer[i] = inr[i];   delete[] inr;   delete[] ini;   delete[] outr;   delete[] outi;   delete[] power;   delete[] plog;}// WDR: class implementations//----------------------------------------------------------------------------// NoiseRemovalDialog//----------------------------------------------------------------------------// WDR: event table for NoiseRemovalDialogenum {   ID_BUTTON_GETPROFILE = 10001,	ID_BUTTON_PREVIEW};BEGIN_EVENT_TABLE(NoiseRemovalDialog,wxDialog)	EVT_BUTTON(wxID_OK, NoiseRemovalDialog::OnRemoveNoise)	EVT_BUTTON(wxID_CANCEL, NoiseRemovalDialog::OnCancel)	EVT_BUTTON(ID_BUTTON_GETPROFILE, NoiseRemovalDialog::OnGetProfile)	EVT_BUTTON(ID_BUTTON_PREVIEW, NoiseRemovalDialog::OnPreview)END_EVENT_TABLE()NoiseRemovalDialog::NoiseRemovalDialog(EffectNoiseRemoval * 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;   	// NULL out the control members until the controls are created.	m_pButton_GetProfile = NULL;	m_pSlider = NULL;	m_pButton_Preview = NULL;	m_pButton_RemoveNoise = NULL;   this->MakeNoiseRemovalDialog(true); }// WDR: handler implementations for NoiseRemovalDialogvoid NoiseRemovalDialog::OnGetProfile( wxCommandEvent &event ){   EndModal(1);}void NoiseRemovalDialog::OnPreview(wxCommandEvent &event){	// Save & restore parameters around Preview, because we didn't do OK.   bool oldDoProfile = m_pEffect->mDoProfile;	int oldLevel = m_pEffect->mLevel;	m_pEffect->mDoProfile = false;	m_pEffect->mLevel = m_pSlider->GetValue();   	m_pEffect->Preview();   	m_pEffect->mDoProfile = oldDoProfile;	m_pEffect->mLevel = oldLevel; }void NoiseRemovalDialog::OnRemoveNoise( wxCommandEvent &event ){   EndModal(2);}void NoiseRemovalDialog::OnCancel(wxCommandEvent &event){   EndModal(0);}wxSizer *NoiseRemovalDialog::MakeNoiseRemovalDialog(bool call_fit /* = true */, 																	 bool set_sizer /* = true */){   wxBoxSizer *mainSizer = new wxBoxSizer( wxVERTICAL );   wxStaticBoxSizer *group;   wxControl *item;      item = new wxStaticText(this, -1,                   _("Noise Removal by Dominic Mazzoni"), wxDefaultPosition,                   wxDefaultSize, wxALIGN_CENTRE );   mainSizer->Add(item, 0, wxALIGN_CENTRE|wxALL, 5);	AudacityProject * p;	p=GetActiveProject();	bool bCleanSpeechMode = p && p->GetCleanSpeechMode();	if( bCleanSpeechMode )	{      item = new wxStaticText(this, -1,         _("Entire recording should have been Normalized prior to this step.\n\nFor noisy speech, find the best tradeoff for quieting the gaps between phrases and\nnot causing the voice to sound distorted. For good audio with low noise, a setting\nmore to the left should work well. Leveling and TruncateSilence work better with\nmore of the noise removed, even if the voice ends up sounding somewhat distorted.\nYour objective is that the softly spoken words can be heard more clearly."),           wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );      	  mainSizer->Add(item, 0, wxALIGN_LEFT|wxALL, 15);	}   // Step 1   group = new wxStaticBoxSizer(new wxStaticBox(this, -1,	bCleanSpeechMode ? 		_("Preparation Steps")	: 	_("Step 1")		), wxVERTICAL);   item = new wxStaticText(this, -1,                           bCleanSpeechMode ?                              _("Listen carefully to section with some speech and some silence to check before/after.\nSelect a few seconds of just noise ('thinner' part of wave pattern usually between\nspoken phrases or during pauses) so Audacity knows what to filter out, then click")                              :  _("Select a few seconds of just noise\nso Audacity knows what to filter out, then\nclick Get Noise Profile:"),                           wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );   group->Add(item, 0, wxALIGN_CENTRE|wxALL, 5 );   m_pButton_GetProfile = new wxButton(this, ID_BUTTON_GETPROFILE, _("Get Noise Profile"), wxDefaultPosition, wxDefaultSize, 0 );   group->Add(m_pButton_GetProfile, 0, wxALIGN_CENTRE|wxALL, 5 );   mainSizer->Add( group, 1, wxALIGN_CENTRE|wxALL|wxGROW, 5 );      // Step 2      group = new wxStaticBoxSizer(new wxStaticBox(this, -1,			bCleanSpeechMode ?          	_("Actually Remove Noise")			:  _("Step 2")), wxVERTICAL);   item = new wxStaticText(this, -1,	                        bCleanSpeechMode ?                                 _("Select what part of the audio you want filtered (Ctrl-A = All), chose how much noise\nyou want filtered out with Slider below, and then click 'OK' to remove noise.\nFind best setting with Ctrl-Z to Undo, Select All, and change Slider position.")                              :	_("Select all of the audio you want filtered,\nchoose how much noise you want filtered out,\nand then click 'OK' to remove noise.\n"),                           wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT );   group->Add(item, 0, wxALIGN_CENTRE|wxALL, 5 );   m_pSlider = new wxSlider(this, -1, mLevel, 0, MAX_NOISE_LEVEL,    //lda-131a mLevel=0 indicates skip										wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL);   group->Add(m_pSlider, 1, wxEXPAND|wxALIGN_CENTRE|wxLEFT | wxRIGHT | wxTOP, 5 );   wxBoxSizer *hSizer = new wxBoxSizer(wxHORIZONTAL);   item = new wxStaticText(this, -1, _("None"));   hSizer->Add(item, 0, wxALIGN_CENTRE|wxLEFT | wxRIGHT | wxBOTTOM, 5 );      hSizer->Add(10, 10, 1, wxALIGN_CENTRE | wxLEFT | wxRIGHT | wxBOTTOM, 5);	if( bCleanSpeechMode )	{      item = new wxStaticText(this, -1, _("Medium"));      hSizer->Add(item, 0, wxALIGN_CENTRE|wxLEFT | wxRIGHT | wxBOTTOM, 5 );         hSizer->Add(10, 10, 1, wxALIGN_CENTRE | wxLEFT | wxRIGHT | wxBOTTOM, 5);	}   item = new wxStaticText(this, -1, 	bCleanSpeechMode ?		_("Extreme (May Distort)")	:	_("More"));   hSizer->Add(item, 0, wxALIGN_CENTRE|wxLEFT | wxRIGHT | wxBOTTOM, 5 );   group->Add(hSizer, 1, wxEXPAND|wxALIGN_CENTRE|wxALL, 5 );      hSizer = new wxBoxSizer(wxHORIZONTAL);   m_pButton_Preview = new wxButton(this, ID_BUTTON_PREVIEW, m_pEffect->GetPreviewName());   hSizer->Add(m_pButton_Preview, 0, wxALIGN_LEFT | wxALL, 5);      hSizer->Add(25, 5); // horizontal spacer   item = new wxButton( this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxDefaultSize, 0 );   hSizer->Add(item, 0, wxALIGN_CENTER | wxALL, 5 );   hSizer->Add(25, 5); // horizontal spacer   	m_pButton_RemoveNoise = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxDefaultSize, 0 );   hSizer->Add(m_pButton_RemoveNoise, 0, wxALIGN_RIGHT | wxALL, 5 );	group->Add(hSizer, 0, wxALIGN_CENTER | wxALL, 5 );   mainSizer->Add( group, 0, wxALIGN_CENTRE|wxALL|wxGROW, 5 );   if (set_sizer) {      this->SetAutoLayout( TRUE );      this->SetSizer( mainSizer );      if (call_fit) {         mainSizer->Fit( this );         mainSizer->SetSizeHints( this );      }   }       return mainSizer;}// Indentation settings for Vim and Emacs and unique identifier for Arch, a// version control system. Please do not modify past this point.//// Local Variables:// c-basic-offset: 3// indent-tabs-mode: nil// End://// vim: et sts=3 sw=3// arch-tag: 685e0d8c-89eb-427b-8933-af606cf33c2b

⌨️ 快捷键说明

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