Ver código fonte

cmDspPgm.c : Added more channels to _cmDspSysPgm_Goertzel() and parameters

to support window size on the Goertzel detector.
master
kevin 10 anos atrás
pai
commit
af002db879
1 arquivos alterados com 36 adições e 25 exclusões
  1. 36
    25
      dsp/cmDspPgm.c

+ 36
- 25
dsp/cmDspPgm.c Ver arquivo

@@ -2453,25 +2453,38 @@ cmDspRC_t _cmDspSysPgm_AvailCh( cmDspSysH_t h, void** userPtrPtr )
2453 2453
 cmDspRC_t _cmDspSysPgm_Goertzel( cmDspSysH_t h, void** userPtrPtr )
2454 2454
 {
2455 2455
   cmDspRC_t rc;
2456
-  const unsigned chCnt        = 3;
2457
-  double         dfltHz       = 19000;
2458
-  double fcHzV[]              = { 18000, dfltHz, 20000 };
2456
+  const unsigned chCnt        = 8;
2457
+  unsigned       hopFact      = 2;
2458
+  double         dfltHz       = 18000.0;
2459 2459
   unsigned       sigGenMode   = 2; // sine
2460 2460
   double         sigGenGain   = 0.9;
2461
+  double         dfltMixGain  = 1.0/chCnt;
2462
+  double         fcHzV[chCnt];
2463
+  unsigned       i;
2461 2464
 
2462
-  cmDspInst_t*  ain  = cmDspSysAllocAudioIn(  h, 0, 1.0);
2463
-  cmDspInst_t* amtr  = cmDspSysAllocInst( h, "AMeter", NULL, 0 );
2464
-
2465
-  cmDspInst_t*  goer = cmDspSysAllocInst( h, "Goertzel",  NULL,   2, chCnt, fcHzV );
2466
-  cmDspInst_t** mtr  = cmDspSysAllocInstArray(h, chCnt,"Meter", "Mtr", NULL,  3, 0.0, 0.0, 1.0 );
2465
+  for(i=0; i<chCnt; ++i)
2466
+    fcHzV[i] = 18000.0 + (20000.0-18000.0) * i /chCnt;
2467 2467
   
2468
-  cmDspInst_t*  sg   = cmDspSysAllocInst( h, "SigGen",    NULL,   2, dfltHz, sigGenMode, sigGenGain, 0 );
2469
-  cmDspInst_t*  ao0  = cmDspSysAllocAudioOut( h, 0, 1.0);
2470
-  cmDspInst_t*  ao1  = cmDspSysAllocAudioOut( h, 0, 1.0);
2471 2468
 
2472
-  cmDspInst_t*  hz   = cmDspSysAllocScalar(    h, "hz",0.0, 22000.0, 100.0, dfltHz );
2473
-  cmDspInst_t*  ogain= cmDspSysAllocScalar(    h, "ogain", 0.0, 3.0, 0.01, 1.0 );
2474
-  cmDspInst_t*  igain= cmDspSysAllocScalar(    h, "igain", 0.0, 3.0, 0.01, 1.0 );
2469
+  cmDspInst_t*  ain   = cmDspSysAllocAudioIn(  h, 0, 1.0);
2470
+  cmDspInst_t*  amtr  = cmDspSysAllocInst(     h, "AMeter", "In", 0 );
2471
+
2472
+  cmDspInst_t*  goer  = cmDspSysAllocInst(     h, "Goertzel",  NULL,   3, hopFact, chCnt, fcHzV );
2473
+
2474
+  cmDspSysNewColumn(h,0);
2475
+  cmDspInst_t** mtrV  = cmDspSysAllocInstArray(h, chCnt, "Meter",  "Mtr", NULL,  3, 0.0, 0.0, 1.0 );  
2476
+  cmDspInst_t** sgV   = cmDspSysAllocInstArray(h, chCnt, "SigGen", "SG",  NULL,  2, dfltHz, sigGenMode, sigGenGain, 0 );
2477
+  cmDspInst_t*  mix   = cmDspSysAllocInst(     h, "AMix", NULL,1, chCnt );
2478
+  cmDspInst_t*  ao0   = cmDspSysAllocAudioOut( h, 0, 1.0);
2479
+  cmDspInst_t*  ao1   = cmDspSysAllocAudioOut( h, 0, 1.0);
2480
+
2481
+  cmDspSysNewColumn(h,0);
2482
+  cmDspInst_t**  hzV   = cmDspSysAllocInstArray( h, chCnt, "Scalar", "Hz",   NULL, 5, kNumberDuiId, 0.0, 22000.0, 100.0, dfltHz );
2483
+
2484
+  cmDspSysNewColumn(h,0);
2485
+  cmDspInst_t**  gnV   = cmDspSysAllocInstArray( h, chCnt, "Scalar", "Gain", NULL, 5, kNumberDuiId, 0.0, 1.0, 0.01, dfltMixGain );
2486
+  cmDspInst_t*   igain = cmDspSysAllocScalar(    h, "igain", 0.0,  3.0, 0.01, 1.0 );
2487
+  cmDspInst_t*   hop   = cmDspSysAllocScalar(    h, "hop",   0.0, 16.0, 1.0,  4.0 );
2475 2488
 
2476 2489
   cmDspInst_t* prnt = cmDspSysAllocInst( h,"Printer", NULL,     1, ">" );
2477 2490
 
@@ -2481,19 +2494,17 @@ cmDspRC_t _cmDspSysPgm_Goertzel( cmDspSysH_t h, void** userPtrPtr )
2481 2494
 
2482 2495
   cmDspSysConnectAudio(h,ain,"out", goer, "in" );
2483 2496
   cmDspSysConnectAudio(h,ain,"out", amtr, "in" );
2497
+  
2498
+  cmDspSysConnectAudioN11N(h,sgV, "out", mix, "in", chCnt );
2499
+  cmDspSysConnectAudio(h,mix,"out", ao0, "in" );
2500
+  cmDspSysConnectAudio(h,mix,"out", ao1, "in" );
2484 2501
 
2485
-
2486
-  cmDspSysConnectAudio(h,sg,"out", ao0, "in" );
2487
-  cmDspSysConnectAudio(h,sg,"out", ao1, "in" );
2488
-
2489
-  cmDspSysInstallCb( h, hz,    "val", sg,  "hz", NULL);
2490
-  cmDspSysInstallCb( h, ogain, "val", ao0, "gain", NULL);
2491
-  cmDspSysInstallCb( h, ogain, "val", ao1, "gain", NULL);
2492 2502
   cmDspSysInstallCb( h, igain, "val", ain, "gain", NULL);
2493
-  cmDspSysInstallCb(h,goer,"out-0", mtr[0], "in",NULL);
2494
-  cmDspSysInstallCb(h,goer,"out-1", mtr[1], "in",NULL);
2495
-  cmDspSysInstallCb(h,goer,"out-2", mtr[2], "in",NULL);
2496
-  //cmDspSysInstallCb(h,goer,"out-1", prnt, "in",NULL);
2503
+  cmDspSysInstallCbN1N1( h, hzV, "val", sgV, "hz",   chCnt);
2504
+  cmDspSysInstallCbN11N( h, hzV, "val", goer, "hz",  chCnt );
2505
+  cmDspSysInstallCbN11N( h, gnV, "val", mix, "gain", chCnt); 
2506
+  cmDspSysInstallCb1NN1( h, goer, "out", mtrV, "in", chCnt );
2507
+  cmDspSysInstallCb(     h, hop, "val",  goer, "hop", NULL ); 
2497 2508
   
2498 2509
  errLabel:
2499 2510
   return rc;

Carregando…
Cancelar
Salvar