From d8d63d7e292a15c84eb4b2b25bbd45541aee380e Mon Sep 17 00:00:00 2001 From: kevin Date: Tue, 4 Feb 2014 08:39:51 -0800 Subject: [PATCH] cmProc4.h/c,cmProc5.h/c,Makefiile.am : Moved cmGoertzel from cmProc4.h/c into new file (cmProc5.h/c). --- Makefile.am | 4 +- cmProc4.c | 102 ------------------------------------------ cmProc4.h | 32 -------------- cmProc5.c | 125 ++++++++++++++++++++++++++++++++++++++++++++++++++++ cmProc5.h | 47 ++++++++++++++++++++ 5 files changed, 174 insertions(+), 136 deletions(-) create mode 100644 cmProc5.c create mode 100644 cmProc5.h diff --git a/Makefile.am b/Makefile.am index 013f9a4..885065a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -67,8 +67,8 @@ cmHDR += src/libcm/vop/cmVectOps.h src/libcm/vop/cmProcTemplate.h cmSRC += src/libcm/vop/cmVectOps.c src/libcm/vop/cmProcTemplate.c -cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/cmProc3.h src/libcm/cmProc4.h src/libcm/cmProcTest.h -cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProcTest.c +cmHDR += src/libcm/cmProcObj.h src/libcm/cmProc.h src/libcm/cmProc2.h src/libcm/cmProc3.h src/libcm/cmProc4.h src/libcm/cmProc5.h src/libcm/cmProcTest.h +cmSRC += src/libcm/cmProcObj.c src/libcm/cmProc.c src/libcm/cmProc2.c src/libcm/cmProc3.c src/libcm/cmProc4.c src/libcm/cmProc5.c src/libcm/cmProcTest.c cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h diff --git a/cmProc4.c b/cmProc4.c index 7c1365c..d95dc88 100644 --- a/cmProc4.c +++ b/cmProc4.c @@ -24,7 +24,6 @@ #include "cmTimeLine.h" #include "cmScore.h" #include "cmProc4.h" -#include "cmTime.h" cmScFol* cmScFolAlloc( cmCtx* c, cmScFol* p, cmReal_t srate, cmScH_t scH, unsigned bufN, unsigned minWndLookAhead, unsigned maxWndCnt, unsigned minVel ) @@ -4547,104 +4546,3 @@ cmRC_t cmRecdPlayExec( cmRecdPlay* p, const cmSample_t** iChs, cmSample_ return cmOkRC; } -//======================================================================================================================= -cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ) -{ - cmGoertzel* op = cmObjAlloc(cmGoertzel,c,p); - - op->shb = cmShiftBufAlloc(c,NULL,0,0,0); - - if( srate > 0 ) - if( cmGoertzelInit(op,srate,fcHzV,chCnt,procSmpCnt,wndSmpCnt,hopSmpCnt) != cmOkRC ) - cmGoertzelFree(&op); - - return op; -} - -cmRC_t cmGoertzelFree( cmGoertzel** pp ) -{ - cmRC_t rc = cmOkRC; - if( pp==NULL || *pp==NULL ) - return rc; - - cmGoertzel* p = *pp; - if((rc = cmGoertzelFinal(p)) != cmOkRC ) - return rc; - - cmShiftBufFree(&p->shb); - cmMemFree(p->ch); - cmMemFree(p->wnd); - cmObjFree(pp); - return rc; - -} - -cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ) -{ - cmRC_t rc; - unsigned i; - - if((rc = cmGoertzelFinal(p)) != cmOkRC ) - return rc; - - p->ch = cmMemResizeZ(cmGoertzelCh,p->ch,chCnt); - p->chCnt = chCnt; - p->srate = srate; - p->wnd = cmMemResizeZ(cmSample_t,p->wnd,wndSmpCnt); - - cmVOS_Hann(p->wnd,wndSmpCnt); - - cmShiftBufInit(p->shb,procSmpCnt,wndSmpCnt,hopSmpCnt); - - for(i=0; ichCnt; ++i) - { - cmGoertzelSetFcHz(p,i,fcHzV[i]); - } - - return rc; -} - -cmRC_t cmGoertzelFinal( cmGoertzel* p ) -{ return cmOkRC; } - -cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz ) -{ - assert( chIdx < p->chCnt ); - p->ch[chIdx].hz = hz; - p->ch[chIdx].coeff = 2*cos(2*M_PI*hz/p->srate); - - return cmOkRC; -} - -cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* inpV, unsigned procSmpCnt, double* outV, unsigned chCnt ) -{ - unsigned i,j; - - while( cmShiftBufExec(p->shb,inpV,procSmpCnt) ) - { - unsigned xn = p->shb->wndSmpCnt; - cmSample_t x[ xn ]; - - cmVOS_MultVVV(x,xn,p->wnd,p->shb->outV); - - for(i=0; ich + i; - - ch->s2 = x[0]; - ch->s1 = x[1] + 2 * x[0] * ch->coeff; - for(j=2; js0 = x[j] + ch->coeff * ch->s1 - ch->s2; - ch->s2 = ch->s1; - ch->s1 = ch->s0; - } - - outV[i] = ch->s2*ch->s2 + ch->s1*ch->s1 - ch->coeff * ch->s2 * ch->s1; - } - } - - return cmOkRC; -} - - diff --git a/cmProc4.h b/cmProc4.h index 82cc243..97bac3b 100644 --- a/cmProc4.h +++ b/cmProc4.h @@ -698,38 +698,6 @@ extern "C" { cmRC_t cmRecdPlayExec( cmRecdPlay* p, const cmSample_t** iChs, cmSample_t** oChs, unsigned chCnt, unsigned smpCnt ); - //======================================================================================================================= - // Goertzel Filter - // - - typedef struct - { - double s0; - double s1; - double s2; - double coeff; - double hz; - } cmGoertzelCh; - - struct cmShiftBuf_str; - - typedef struct cmGoertzel_str - { - cmObj obj; - cmGoertzelCh* ch; - unsigned chCnt; - double srate; - struct cmShiftBuf_str* shb; - cmSample_t* wnd; - } cmGoertzel; - - cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ); - cmRC_t cmGoertzelFree( cmGoertzel** pp ); - cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ); - cmRC_t cmGoertzelFinal( cmGoertzel* p ); - cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz ); - cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* in, unsigned procSmpCnt, double* outV, unsigned chCnt ); - #ifdef __cplusplus } diff --git a/cmProc5.c b/cmProc5.c new file mode 100644 index 0000000..beaf543 --- /dev/null +++ b/cmProc5.c @@ -0,0 +1,125 @@ +#include "cmPrefix.h" +#include "cmGlobal.h" +#include "cmRpt.h" +#include "cmErr.h" +#include "cmCtx.h" +#include "cmMem.h" +#include "cmMallocDebug.h" +#include "cmLinkedHeap.h" +#include "cmFloatTypes.h" +#include "cmComplexTypes.h" +#include "cmFileSys.h" +#include "cmJson.h" +#include "cmSymTbl.h" +#include "cmAudioFile.h" +#include "cmText.h" +#include "cmProcObj.h" +#include "cmProcTemplate.h" +#include "cmMath.h" +#include "cmProc.h" +#include "cmProc5.h" + +#include "cmVectOps.h" + + +//======================================================================================================================= +cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ) +{ + cmGoertzel* op = cmObjAlloc(cmGoertzel,c,p); + + op->shb = cmShiftBufAlloc(c,NULL,0,0,0); + + if( srate > 0 ) + if( cmGoertzelInit(op,srate,fcHzV,chCnt,procSmpCnt,wndSmpCnt,hopSmpCnt) != cmOkRC ) + cmGoertzelFree(&op); + + return op; +} + +cmRC_t cmGoertzelFree( cmGoertzel** pp ) +{ + cmRC_t rc = cmOkRC; + if( pp==NULL || *pp==NULL ) + return rc; + + cmGoertzel* p = *pp; + if((rc = cmGoertzelFinal(p)) != cmOkRC ) + return rc; + + cmShiftBufFree(&p->shb); + cmMemFree(p->ch); + cmMemFree(p->wnd); + cmObjFree(pp); + return rc; + +} + +cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ) +{ + cmRC_t rc; + unsigned i; + + if((rc = cmGoertzelFinal(p)) != cmOkRC ) + return rc; + + p->ch = cmMemResizeZ(cmGoertzelCh,p->ch,chCnt); + p->chCnt = chCnt; + p->srate = srate; + p->wnd = cmMemResizeZ(cmSample_t,p->wnd,wndSmpCnt); + + cmVOS_Hann(p->wnd,wndSmpCnt); + + cmShiftBufInit(p->shb,procSmpCnt,wndSmpCnt,hopSmpCnt); + + for(i=0; ichCnt; ++i) + { + cmGoertzelSetFcHz(p,i,fcHzV[i]); + } + + return rc; +} + +cmRC_t cmGoertzelFinal( cmGoertzel* p ) +{ return cmOkRC; } + +cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz ) +{ + assert( chIdx < p->chCnt ); + p->ch[chIdx].hz = hz; + p->ch[chIdx].coeff = 2*cos(2*M_PI*hz/p->srate); + + return cmOkRC; +} + +cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* inpV, unsigned procSmpCnt, double* outV, unsigned chCnt ) +{ + unsigned i,j; + + while( cmShiftBufExec(p->shb,inpV,procSmpCnt) ) + { + unsigned xn = p->shb->wndSmpCnt; + cmSample_t x[ xn ]; + + cmVOS_MultVVV(x,xn,p->wnd,p->shb->outV); + + for(i=0; ich + i; + + ch->s2 = x[0]; + ch->s1 = x[1] + 2 * x[0] * ch->coeff; + for(j=2; js0 = x[j] + ch->coeff * ch->s1 - ch->s2; + ch->s2 = ch->s1; + ch->s1 = ch->s0; + } + + outV[i] = ch->s2*ch->s2 + ch->s1*ch->s1 - ch->coeff * ch->s2 * ch->s1; + } + } + + return cmOkRC; +} + + diff --git a/cmProc5.h b/cmProc5.h new file mode 100644 index 0000000..927d158 --- /dev/null +++ b/cmProc5.h @@ -0,0 +1,47 @@ +#ifndef cmProc5_h +#define cmProc5_h + +#ifdef __cplusplus +extern "C" { +#endif + + + //======================================================================================================================= + // Goertzel Filter + // + + typedef struct + { + double s0; + double s1; + double s2; + double coeff; + double hz; + } cmGoertzelCh; + + struct cmShiftBuf_str; + + typedef struct cmGoertzel_str + { + cmObj obj; + cmGoertzelCh* ch; + unsigned chCnt; + double srate; + struct cmShiftBuf_str* shb; + cmSample_t* wnd; + } cmGoertzel; + + cmGoertzel* cmGoertzelAlloc( cmCtx* c, cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ); + cmRC_t cmGoertzelFree( cmGoertzel** pp ); + cmRC_t cmGoertzelInit( cmGoertzel* p, double srate, const double* fcHzV, unsigned chCnt, unsigned procSmpCnt, unsigned hopSmpCnt, unsigned wndSmpCnt ); + cmRC_t cmGoertzelFinal( cmGoertzel* p ); + cmRC_t cmGoertzelSetFcHz( cmGoertzel* p, unsigned chIdx, double hz ); + cmRC_t cmGoertzelExec( cmGoertzel* p, const cmSample_t* in, unsigned procSmpCnt, double* outV, unsigned chCnt ); + + + +#ifdef __cplusplus +} +#endif + +#endif