cmProc4.h/c,cmProc5.h/c,Makefiile.am : Moved cmGoertzel from cmProc4.h/c into new file (cmProc5.h/c).
This commit is contained in:
parent
4dcd756f33
commit
d8d63d7e29
@ -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
|
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
|
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/cmProcTest.c
|
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
|
cmHDR += src/libcm/app/cmOnset.h src/libcm/app/cmTimeLine.h src/libcm/app/cmScore.h src/libcm/app/cmScoreProc.h
|
||||||
|
102
cmProc4.c
102
cmProc4.c
@ -24,7 +24,6 @@
|
|||||||
#include "cmTimeLine.h"
|
#include "cmTimeLine.h"
|
||||||
#include "cmScore.h"
|
#include "cmScore.h"
|
||||||
#include "cmProc4.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 )
|
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;
|
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; i<p->chCnt; ++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; i<chCnt; ++i)
|
|
||||||
{
|
|
||||||
cmGoertzelCh* ch = p->ch + i;
|
|
||||||
|
|
||||||
ch->s2 = x[0];
|
|
||||||
ch->s1 = x[1] + 2 * x[0] * ch->coeff;
|
|
||||||
for(j=2; j<xn; ++j)
|
|
||||||
{
|
|
||||||
ch->s0 = 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
32
cmProc4.h
32
cmProc4.h
@ -698,38 +698,6 @@ extern "C" {
|
|||||||
|
|
||||||
cmRC_t cmRecdPlayExec( cmRecdPlay* p, const cmSample_t** iChs, cmSample_t** oChs, unsigned chCnt, unsigned smpCnt );
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
125
cmProc5.c
Normal file
125
cmProc5.c
Normal file
@ -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; i<p->chCnt; ++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; i<chCnt; ++i)
|
||||||
|
{
|
||||||
|
cmGoertzelCh* ch = p->ch + i;
|
||||||
|
|
||||||
|
ch->s2 = x[0];
|
||||||
|
ch->s1 = x[1] + 2 * x[0] * ch->coeff;
|
||||||
|
for(j=2; j<xn; ++j)
|
||||||
|
{
|
||||||
|
ch->s0 = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
47
cmProc5.h
Normal file
47
cmProc5.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user