Browse Source

cmDspFx.c, cmDspFx.c : If the second character in the 'scalarOp' object is '$' then any input triggers an output.

master
kevin 3 years ago
parent
commit
c9dc494178
2 changed files with 41 additions and 11 deletions
  1. 24
    8
      src/dsp/cmDspFx.c
  2. 17
    3
      src/dsp/cmDspPgm.c

+ 24
- 8
src/dsp/cmDspFx.c View File

2909
   cmDspInst_t          inst;
2909
   cmDspInst_t          inst;
2910
   _cmDspScalarOpFunc_t func;
2910
   _cmDspScalarOpFunc_t func;
2911
   unsigned             inPortCnt;
2911
   unsigned             inPortCnt;
2912
+  bool                 allActiveFl;                  
2912
 } cmDspScalarOp_t;
2913
 } cmDspScalarOp_t;
2913
 
2914
 
2914
 cmDspRC_t _cmDspScalarOpFuncMult(cmDspCtx_t* ctx, cmDspInst_t* inst )
2915
 cmDspRC_t _cmDspScalarOpFuncMult(cmDspCtx_t* ctx, cmDspInst_t* inst )
2966
   double             dfltVal[ inPortCnt ];
2967
   double             dfltVal[ inPortCnt ];
2967
   unsigned           i;
2968
   unsigned           i;
2968
   _cmDspScalarOpFunc_t fp = NULL;
2969
   _cmDspScalarOpFunc_t fp = NULL;
2970
+  bool allActiveFl = false;
2969
 
2971
 
2970
   // validate the count of input ports
2972
   // validate the count of input ports
2971
   if( inPortCnt == 0 )
2973
   if( inPortCnt == 0 )
2974
     goto errLabel;
2976
     goto errLabel;
2975
   }
2977
   }
2976
 
2978
 
2977
-  // locate the operation function
2978
-  if( strcmp(opIdStr,"*") == 0 )
2979
-    fp = _cmDspScalarOpFuncMult;
2980
-  else
2981
-    if( strcmp(opIdStr,"+") == 0 )
2982
-      fp = _cmDspScalarOpFuncAdd;
2979
+  if( opIdStr != NULL )
2980
+  {
2981
+    switch( opIdStr[0] )
2982
+    {
2983
+      case '*':
2984
+        fp = _cmDspScalarOpFuncMult;
2985
+        break;
2986
+      case '+':
2987
+        fp = _cmDspScalarOpFuncAdd;
2988
+        break;      
2989
+    }
2990
+
2991
+    // if the second character of the operator string is '$' then all input ports trigger an output
2992
+    if( strlen( opIdStr ) > 0 && opIdStr[1]=='$' )
2993
+      allActiveFl = true;
2994
+    
2995
+    
2996
+  }
2997
+  
2998
+  
2983
 
2999
 
2984
   // validate the operation function
3000
   // validate the operation function
2985
   if( fp == NULL )
3001
   if( fp == NULL )
3012
 
3028
 
3013
   p->inPortCnt = inPortCnt;
3029
   p->inPortCnt = inPortCnt;
3014
   p->func      = fp;
3030
   p->func      = fp;
3015
-  
3031
+  p->allActiveFl = allActiveFl;
3016
   va_end(vl1);
3032
   va_end(vl1);
3017
 
3033
 
3018
   return &p->inst;
3034
   return &p->inst;
3039
 
3055
 
3040
   if((rc = cmDspSetEvent(ctx,inst,evt)) == kOkDspRC )
3056
   if((rc = cmDspSetEvent(ctx,inst,evt)) == kOkDspRC )
3041
   {
3057
   {
3042
-    if( evt->dstVarId == kBaseOpdSoId )
3058
+    if( evt->dstVarId == kBaseOpdSoId || p->allActiveFl )
3043
       p->func(ctx,inst);
3059
       p->func(ctx,inst);
3044
   }
3060
   }
3045
 
3061
 

+ 17
- 3
src/dsp/cmDspPgm.c View File

898
   cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL,   1, ">" );
898
   cmDspInst_t* prp = cmDspSysAllocInst(h,"Printer", NULL,   1, ">" );
899
   cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter", "meter",  3, 0.0,  0.0, 4.0);
899
   cmDspInst_t* mtp = cmDspSysAllocInst(h,"Meter", "meter",  3, 0.0,  0.0, 4.0);
900
   cmDspInst_t* ctp = cmDspSysAllocInst(h,"Counter", NULL,   3, 0.0, 10.0, 1.0 );
900
   cmDspInst_t* ctp = cmDspSysAllocInst(h,"Counter", NULL,   3, 0.0, 10.0, 1.0 );
901
-                     cmDspSysAllocInst(h,"Label",  "label1", 1, "label2");
901
+  cmDspInst_t* lbl = cmDspSysAllocInst(h,"Label",  "label1", 1, "label2");
902
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
902
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
903
     return rc;
903
     return rc;
904
 
904
 
924
   cmDspSysInstallCb(h, chb, "out", prp, "in", NULL );
924
   cmDspSysInstallCb(h, chb, "out", prp, "in", NULL );
925
   cmDspSysInstallCb(h, chb, "sym", prp, "in", NULL );
925
   cmDspSysInstallCb(h, chb, "sym", prp, "in", NULL );
926
 
926
 
927
+  cmDspSysInstallCb(h, mdp, "val", lbl, "in", NULL );
928
+
927
   return rc;
929
   return rc;
928
 
930
 
929
 }
931
 }
2055
 {
2057
 {
2056
   cmDspRC_t rc;
2058
   cmDspRC_t rc;
2057
 
2059
 
2058
-  cmDspInst_t* add   = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "+", "in-0", 0.0, "in-1", 0.0 );
2059
-  cmDspInst_t* mul0  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
2060
+  cmDspInst_t* add   = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "+",  "in-0", 0.0, "in-1", 0.0 );
2061
+  cmDspInst_t* mul0  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*$", "in-0", 0.0, "in-1", 0.0 );
2060
   cmDspInst_t* mul1  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
2062
   cmDspInst_t* mul1  = cmDspSysAllocInst(   h, "ScalarOp", NULL,  6, 2, "*", "in-0", 0.0, "in-1", 0.0 );
2061
   cmDspInst_t* in    = cmDspSysAllocScalar( h, "Input",      0.0, 10.0, 0.001, 0.0);
2063
   cmDspInst_t* in    = cmDspSysAllocScalar( h, "Input",      0.0, 10.0, 0.001, 0.0);
2062
   cmDspInst_t* in_m  = cmDspSysAllocScalar( h, "Input_M",    0.0, 10.0, 0.001, 0.0);
2064
   cmDspInst_t* in_m  = cmDspSysAllocScalar( h, "Input_M",    0.0, 10.0, 0.001, 0.0);
2068
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
2070
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
2069
     goto errLabel;
2071
     goto errLabel;
2070
 
2072
 
2073
+  // Notice that changing 'in' or 'in_m' causes 'out' to be recomputed, but other
2074
+  // changes are cached prior to 'add'.  This prevents the program from going into
2075
+  // an infinite loop.
2076
+  //
2077
+  //     in   -> mult0
2078
+  //     in_m -> mult0--+
2079
+  // +-->fb   -> mult1  +----> add
2080
+  // |   fb_m -> mult1-------> add --------+------> out
2081
+  // |                                     |
2082
+  // +-------------------------------------+
2083
+  //
2084
+  
2071
   cmDspSysInstallCb( h, in,    "val", mul0, "in-0", NULL );
2085
   cmDspSysInstallCb( h, in,    "val", mul0, "in-0", NULL );
2072
   cmDspSysInstallCb( h, in_m,  "val", mul0, "in-1", NULL );
2086
   cmDspSysInstallCb( h, in_m,  "val", mul0, "in-1", NULL );
2073
   cmDspSysInstallCb( h, fb,    "val", mul1, "in-0", NULL );
2087
   cmDspSysInstallCb( h, fb,    "val", mul1, "in-0", NULL );

Loading…
Cancel
Save