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

📄 taudiofilterheadphone.cpp.svn-base

📁 ffshow源码
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
   0.01729258494072014f, 0.017468204169564034f,   0.009729094845051928f, -0.002976992018531901f,   -0.00956986166277019f, -0.016125733548332074f,   -0.02934094241442545f, -0.04133767871051455f,   -0.043536981145416466f, -0.0385966307108608f,   -0.02784453599342459f, -0.018995135307247116f,   -0.012849534096536747f, -0.004437491064613308f,   0.00028385411598204655f, 0.003776874988516643f,   0.008069432041547833f, 0.008764754183751848f,   0.008020908861878062f, 0.006830351461360802f,   0.002218330884267235f, -0.0020478725582339444f,   -0.003997428121462543f, -0.007066287373515421f,   -0.00940847412544698f, -0.010938998446237963f,   -0.011775483016151306f, -0.011391103919484287f,   -0.010586061195163017f, -0.009842793078929053f,   -0.007753202010139829f, -0.00569213732353025f,   -0.006506783349722073f, -0.005346134281903736f,   -0.003913089814898934f, -0.0036091443854759727f,   -0.0020328564301266287f, 0.00017932870773467683f,   0.0032779786679056357f, 0.003969695813293966f,   0.0020339334412434987f, -0.00011345940675415259f,   -0.0018344103399567666f, -0.003556764701666365f,   -0.004263523639408391f, -0.002940568582022133f,   -0.0034341188272627556f, -0.006023399920020824f,   -0.0077456903203677865f, -0.007912219312377842f,   -0.00625202770436523f, -0.00530785086116117f,   -0.005569722659634311f, -0.004664448462594344f,   -0.0037747773914077747f, -0.004175649656985592f,   -0.004659601521384289f, -0.005008602967819641f,   -0.004730625079902729f, -0.0034039554356604146f,   -0.0017110333873406587f, -0.0006091938771510242f,   -0.0016051679050678297f, -0.003312864664007262f,   -0.004505512715977288f, -0.004152222189861692f,   -0.003218596419678823f, -0.0027277806209877343f,   -0.001715005444317267f, -0.0012589960071233749f,   -0.001852908777923165f, -0.002540339553144362f};/* Center rear (180 degree) */const float TaudioFilterHeadphone2::cr_filt[128] = {   -0.00005989110716536726f, -0.00022790291829128702f,   0.0002659166098971966f, -0.0003774772716776257f,   0.0004540309551867803f, -0.000420238187386368f,   0.00025518536450885686f, 0.00028285526288953955f,   -0.001016391007574093f, 0.0028634984299063795f,   0.0021574799687976045f, 0.01035121276682072f,   -0.010481720917298163f, -0.013197198495899292f,   0.0031928225328717195f, 0.02903137843618603f,   0.1632429772511569f, 0.1047487989875262f,   -0.10464685060623742f, -0.09260196288035998f,   -0.007514241993554443f, 0.013596249226741712f,   -0.019876166508450258f, 0.1255626123599804f,   0.3648170359521724f, 0.19458249753223478f,   -0.04434070930031298f, 0.046582528121935265f,   0.09484427347230277f, -0.03137795311969644f,   -0.10297437925363695f, -0.09351091015917065f,   -0.1129521092162064f, -0.14925322995658827f,   -0.1231466295584665f, -0.06356719756705227f,   -0.05442277895126282f, -0.07568433015661316f,   -0.023314932828602003f, 0.04260950721318558f,   0.02249026315598923f, 0.02048195669571197f,   0.05651342117268278f, 0.05885038917623213f,   0.03797102097397795f, 0.011767394419953451f,   0.00560502503429481f, 0.005051125343961189f,   -0.012925933188033823f, -0.023918884651306566f,   -0.013251659441678816f, -0.010694772488866284f,   -0.03080486448617846f, -0.03661278237783158f,   -0.0379227303416262f, -0.042189005718490775f,   -0.026595666344596286f, -0.009759025956801257f,   -0.002064986663513004f, -0.002420117028098389f,   -0.006629991977552491f, 0.004619970897631026f,   0.019450642967537877f, 0.0173521119057514f,   0.017641425439988062f, 0.02270029598048491f,   0.018976431925275348f, 0.009299852902290885f,   -0.001695039371619912f, -0.00675162574265618f,   -0.009380968871003034f, -0.011208396125485165f,   -0.01308640049201482f, -0.0165636375633249f,   -0.022004099870933345f, -0.025173458684139286f,   -0.016918759559175375f, -0.00865150653575917f,   -0.006999929082792643f, -0.005454830010518988f,   -0.0021129521131095317f, 0.00018717090054046307f,   -0.0002864344788569993f, 0.0017615225381095569f,   0.006985907557802283f, 0.010577308310476465f,   0.006466104789306027f, -0.0014988738575948326f,   -0.0039669755229277195f, -0.0065156971200080235f,   -0.009343206924192169f, -0.0076430644693577495f,   -0.004395214976600924f, -0.003052735340422483f,   -0.007019103043066595f, -0.00974109267696527f,   -0.007968015032797376f, -0.007801513845528344f,   -0.007535748903681969f, -0.003543341967287925f,   0.0015083125553729722f, 0.0023345972556147025f,   -0.0010043623069557037f, -0.0025295765105203746f,   -0.0023701840891643634f, -0.0005908186035024362f,   0.0029826252289082847f, 0.004829048542117764f,   0.004488360022902081f, 0.00002643748103005408f,   -0.0042100779212597295f, -0.006170600558114495f,   -0.007267149164680168f, -0.006825522903494639f,   -0.006899834372739123f, -0.0073493916110062675f,   -0.009554351265163382f, -0.011790297433830197f,   -0.010645796603734424f, -0.0064661575394022106f,   -0.002026743466524137f, -0.0004337034584909932f,   -0.0011172647031654614f, -0.0017947816283674731f,   -0.00255615052036616f, -0.0017721562881944813f,   -0.0002379619297227554f, 0.0007130120121089036f};/* Amplitude scaling factors */const float TaudioFilterHeadphone2::M17_0DB=0.1414213562f;const float TaudioFilterHeadphone2::M9_03DB=0.3535533906f;const float TaudioFilterHeadphone2::M6_99DB=0.4472135955f;const float TaudioFilterHeadphone2::M4_77DB=0.5773502692f;const float TaudioFilterHeadphone2::M3_01DB=0.7071067812f;const float TaudioFilterHeadphone2::M1_76DB=0.8164965809f;const float TaudioFilterHeadphone2::IRTHRESH=0.001f;	/* Impulse response pruning thresh. */const float TaudioFilterHeadphone2::BASSGAIN=(float)M_SQRT2;	/* Bass compensation gain */const float TaudioFilterHeadphone2::BASSCROSS=0.35f;	/* Bass cross talk */const float TaudioFilterHeadphone2::STEXPAND2=0.07f;	/* Stereo expansion / 2 */TaudioFilterHeadphone2::TaudioFilterHeadphone2(IffdshowBase *Ideci,Tfilters *Iparent):TaudioFilter(Ideci,Iparent){ s=NULL; oldfmt.freq=0;}void TaudioFilterHeadphone2::done(void){ if (s) delete s;s=NULL;}bool TaudioFilterHeadphone2::getOutputFmt(TsampleFormat &fmt,const TfilterSettingsAudio *cfg){ if (super::getOutputFmt(fmt,cfg))  {   fmt.setChannels(2);   return true;  } else  return false;  }/* Detect when the impulse response starts (significantly) */int TaudioFilterHeadphone2::pulse_detect(const float *sx){    /* nmax must be the reference impulse response length (128) minus       s->hrflen */    const int nmax = 128 - HRTFFILTLEN;    const float thresh = IRTHRESH;    int i;    for(i = 0; i < nmax; i++)	if(fabs(sx[i]) > thresh)	    return i;    return 0;}TaudioFilterHeadphone2::af_hrtf_s::af_hrtf_s(const TsampleFormat &fmt): dlbuflen(DELAYBUFLEN), hrflen(HRTFFILTLEN), basslen(BASSFILTLEN), lf(DELAYBUFLEN), rf(DELAYBUFLEN), lr(DELAYBUFLEN), rr(DELAYBUFLEN), cf(DELAYBUFLEN), cr(DELAYBUFLEN), ba_l(DELAYBUFLEN), ba_r(DELAYBUFLEN){    cyc_pos = dlbuflen - 1;    for(int i = 0; i < dlbuflen; i++)	lf[i] = rf[i] = lr[i] = rr[i] = cf[i] =	    cr[i] = 0;    cf_ir = cf_filt + (cf_o = pulse_detect(cf_filt));    af_ir = af_filt + (af_o = pulse_detect(af_filt));    of_ir = of_filt + (of_o = pulse_detect(of_filt));    ar_ir = ar_filt + (ar_o = pulse_detect(ar_filt));    or_ir = or_filt + (or_o = pulse_detect(or_filt));    cr_ir = cr_filt + (cr_o = pulse_detect(cr_filt));    //ba_ir = (float*)malloc(basslen * sizeof(float));    float fc = 2.0f * BASSFILTFREQ / (float)fmt.freq;    ba_ir=TfirFilter::design_fir(&basslen, &fc, TfirSettings::LOWPASS, TfirSettings::WINDOW_KAISER, float(4*M_PI));    for(unsigned int i = 0; i < basslen; i++)	ba_ir[i] *= BASSGAIN;}TaudioFilterHeadphone2::af_hrtf_s::~af_hrtf_s(){ if(ba_ir) aligned_free(ba_ir);}void TaudioFilterHeadphone2::af_hrtf_s::update_ch(const float *in, const int k){       /* 5/5+1 channel sources */       lf[k] = in[0];       cf[k] = in[4];       rf[k] = in[1];       lr[k] = in[2];       rr[k] = in[3];    /* We need to update the bass compensation delay line, too. */    ba_l[k] = in[0] + in[4] + in[2];    ba_r[k] = in[4] + in[1] + in[3];}inline float af_filter_fir(register unsigned int n, const float* w, const float* x){ return TfirFilter::firfilter(w,0,n,n,x);}float TaudioFilterHeadphone2::conv(const int nx, const int nk, const float *sx, const float *sk,const int offset){    /* k = reminder of offset / nx */    int k = offset >= 0 ? offset % nx : nx + (offset % nx);    if(nk + k <= nx)	return af_filter_fir(nk, sx + k, sk);    else	return af_filter_fir(nk + k - nx, sx, sk + nx - k) + af_filter_fir(nx - k, sx + k, sk);}HRESULT TaudioFilterHeadphone2::process(TfilterQueue::iterator it,TsampleFormat &fmt,void *samples,size_t numsamples,const TfilterSettingsAudio *cfg0){ const TmixerSettings *cfg=(const TmixerSettings*)cfg0;  if (!s || oldfmt!=fmt)  {   oldfmt=fmt;   done();   /* MPlayer's 5 channel layout (notation for the variable):    *     * 0: L (LF), 1: R (RF), 2: Ls (LR), 3: Rs (RR), 4: C (CF), matrix    * encoded: Cs (CR)    *    * or: L = left, C = center, R = right, F = front, R = rear*/   indexes[0]=fmt.findSpeaker(SPEAKER_FRONT_LEFT);   indexes[1]=fmt.findSpeaker(SPEAKER_FRONT_RIGHT);   indexes[2]=fmt.findSpeaker(SPEAKER_BACK_LEFT);   indexes[3]=fmt.findSpeaker(SPEAKER_BACK_RIGHT);   indexes[4]=fmt.findSpeaker(SPEAKER_FRONT_CENTER);   indexes[5]=fmt.findSpeaker(SPEAKER_LOW_FREQUENCY);   s=new af_hrtf_s(fmt);  }  float *inbuf=(float*)init(cfg,fmt,samples,numsamples); // Input audio data float *end=inbuf+numsamples*fmt.nchannels; // Loop end fmt.setChannels(2); float *out=(float*)(samples=alloc_buffer(fmt,numsamples,buf));  const int dblen = s->dlbuflen, hlen = s->hrflen, blen = s->basslen; while(inbuf < end)   {	const int k = s->cyc_pos;	for (int i=0;i<6;i++)         in[i]=indexes[i]!=-1?inbuf[indexes[i]]:0.0f;        	s->update_ch(in, k);	/* Simulate a 7.5 ms -20 dB echo of the center channel in the	   front channels (like reflection from a room wall) - a kind of	   psycho-acoustically "cheating" to focus the center front	   channel, which is normally hard to be perceived as front */	static const float CFECHOAMPL=M17_0DB;	/* Center front echo amplitude */        s->lf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen];	s->rf[k] += CFECHOAMPL * s->cf[(k + CFECHODELAY) % s->dlbuflen];		float common,left,right;	   common = conv(dblen, hlen, &s->cf[0], &s->cf_ir[0], k + s->cf_o);		      left    =		 ( conv(dblen, hlen, &s->lf[0], s->af_ir, k + s->af_o) +		   conv(dblen, hlen, &s->rf[0], s->of_ir, k + s->of_o) +		   conv(dblen, hlen, &s->lr[0], s->ar_ir, k + s->ar_o) +		   conv(dblen, hlen, &s->rr[0], s->or_ir, k + s->or_o) +		   common);	      right   =		 ( conv(dblen, hlen, &s->rf[0], s->af_ir, k + s->af_o) +		   conv(dblen, hlen, &s->lf[0], s->of_ir, k + s->of_o) +		   conv(dblen, hlen, &s->rr[0], s->ar_ir, k + s->ar_o) +		   conv(dblen, hlen, &s->lr[0], s->or_ir, k + s->or_o) +		   common);		/* Bass compensation for the lower frequency cut of the HRTF.  A	   cross talk of the left and right channel is introduced to	   match the directional characteristics of higher frequencies.	   The bass will not have any real 3D perception, but that is	   OK (note at 180 Hz, the wavelength is about 2 m, and any	   spatial perception is impossible). */	float left_b  = conv(dblen, blen, &s->ba_l[0], s->ba_ir, k);	float right_b = conv(dblen, blen, &s->ba_r[0], s->ba_ir, k);	left  += (1 - BASSCROSS) * left_b  + BASSCROSS * right_b;	right += (1 - BASSCROSS) * right_b + BASSCROSS * left_b;	/* Also mix the LFE channel (if available) */	if(indexes[5]!=-1) {	    left  += in[5] * M3_01DB;	    right += in[5] * M3_01DB;	}	/* Amplitude renormalization. */	static const float AMPLNORM=M6_99DB;	/* Overall amplitude renormalization */        left  *= AMPLNORM;	right *= AMPLNORM;	   /* "Cheating": linear stereo expansion to amplify the 3D	      perception.  Note: Too much will destroy the acoustic space	      and may even result in headaches. */	   float diff = STEXPAND2 * (left - right);	   out[0] = left  + diff;	   out[1] = right - diff;	/* Next sample... */	inbuf += oldfmt.nchannels;	out += fmt.nchannels;	s->cyc_pos--;	if(s->cyc_pos < 0)	    s->cyc_pos += dblen;  }  return parent->deliverSamples(++it,fmt,samples,numsamples); }

⌨️ 快捷键说明

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