Explorar el Código

cmDspBuiltIn.c cmDspWaveTable can now report the current audio file sample index periodically rather than on every exec.

master
kevin hace 11 años
padre
commit
ab0589a216
Se han modificado 1 ficheros con 20 adiciones y 56 borrados
  1. 20
    56
      dsp/cmDspBuiltIn.c

+ 20
- 56
dsp/cmDspBuiltIn.c Ver fichero

@@ -2779,7 +2779,8 @@ typedef struct
2779 2779
   unsigned       offSymId;
2780 2780
   unsigned       doneSymId;
2781 2781
   bool           useThreadFl;
2782
-  unsigned       wt_oi;
2782
+  unsigned       minAfIndexRptCnt; // min count of audio samples between transmitting the current audio file index
2783
+  unsigned       afIndexRptCnt;    // current audio file sample index count
2783 2784
  } cmDspWaveTable_t;
2784 2785
 
2785 2786
 bool _cmDspWaveTableThreadFunc( void* param);
@@ -2810,9 +2811,12 @@ cmDspInst_t*  _cmDspWaveTableAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsi
2810 2811
   // get the filename given in the va_list (or NULL if no filename was given)
2811 2812
   const cmChar_t* fn = cmDspDefaultStrcz(&p->inst,kFnWtId);
2812 2813
 
2813
-  p->offSymId = cmSymTblRegisterStaticSymbol(ctx->stH,"off");
2814
-  p->onSymId  = cmSymTblRegisterStaticSymbol(ctx->stH,"on");
2815
-  p->doneSymId= cmSymTblRegisterStaticSymbol(ctx->stH,"done");
2814
+  p->offSymId         = cmSymTblRegisterStaticSymbol(ctx->stH,"off");
2815
+  p->onSymId          = cmSymTblRegisterStaticSymbol(ctx->stH,"on");
2816
+  p->doneSymId        = cmSymTblRegisterStaticSymbol(ctx->stH,"done");
2817
+
2818
+  double  adCurFileIdxRptPeriodMs = 100.0;
2819
+  p->minAfIndexRptCnt = floor(adCurFileIdxRptPeriodMs * cmDspSampleRate(ctx) / 1000.0);
2816 2820
 
2817 2821
   cmDspSetDefaultUInt(  ctx, &p->inst, kLenWtId,   0,    cmDspSampleRate(ctx));
2818 2822
   cmDspSetDefaultUInt(  ctx, &p->inst, kShapeWtId, 0,    kSilenceWtId  );
@@ -3202,56 +3206,6 @@ cmDspRC_t _cmDspWaveTableReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEv
3202 3206
 
3203 3207
 }
3204 3208
 
3205
-cmDspRC_t _cmDspWaveTableExec1(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3206
-{
3207
-  cmDspRC_t         rc       = kOkDspRC;
3208
-  cmDspWaveTable_t* p        = (cmDspWaveTable_t*)inst;
3209
-  unsigned          mode     = cmDspSymbol(inst,kCmdWtId);
3210
-  unsigned          srcId    = cmDspUInt(inst,kShapeWtId);
3211
-
3212
-  if( mode == p->offSymId || srcId == kSilenceWtId )
3213
-  {
3214
-    cmDspZeroAudioBuf(ctx,inst,kOutWtId);
3215
-    return kOkDspRC;
3216
-  }
3217
-
3218
-  cmSample_t*       outV     = cmDspAudioBuf(ctx,inst,kOutWtId,0);
3219
-  unsigned          outCnt   = cmDspVarRows(inst,kOutWtId);
3220
-  unsigned          wtSmpCnt = cmDspUInt(inst,kLenWtId);
3221
-  double            gain     = cmDspDouble(inst,kGainWtId);
3222
-  unsigned          i;
3223
-
3224
-  // for each output sample
3225
-  for(i=0; i<outCnt; ++i)
3226
-  {
3227
-    p->wt_oi = (p->wt_oi + 1) % wtSmpCnt;
3228
-    outV[i] = gain * p->wt[p->wt_oi];
3229
-  }
3230
-
3231
-  // if we are reading from a file ...
3232
-  if( srcId == kFileWtId )
3233
-  {
3234
-    unsigned rdSmpCnt = 8192; // file read block sample count
3235
-
3236
-    p->wtn += outCnt;
3237
-
3238
-    // ... and there are rdSmpCnt avail locations in the wave table
3239
-    if( p->wtn >= rdSmpCnt )
3240
-      rc =  _cmDspWaveTableReadAudioFile(ctx, p, wtSmpCnt, rdSmpCnt );
3241
-
3242
-    // send the current audio file index
3243
-    if( p->doneFl && p->cfi < p->cfn && p->cfn <= (p->cfi + outCnt) )
3244
-      cmDspSetSymbol(ctx,inst,kDoneWtId,p->doneSymId);
3245
-    else
3246
-      cmDspSetUInt(ctx,inst,kFIdxWtId,p->cfi);
3247
-
3248
-    p->cfi += outCnt;
3249
-
3250
-  }
3251
-
3252
-  return rc;
3253
-
3254
-}
3255 3209
 
3256 3210
 cmDspRC_t _cmDspWaveTableExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
3257 3211
 {
@@ -3315,11 +3269,21 @@ cmDspRC_t _cmDspWaveTableExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt
3315 3269
 
3316 3270
     // send the current audio file index
3317 3271
     if( p->doneFl && p->cfi < p->cfn && p->cfn <= (p->cfi + outCnt) )
3272
+    {
3273
+      cmDspSetUInt(ctx,inst,kFIdxWtId,p->cfn);
3318 3274
       cmDspSetSymbol(ctx,inst,kDoneWtId,p->doneSymId);
3275
+    }
3319 3276
     else
3320
-      cmDspSetUInt(ctx,inst,kFIdxWtId,p->cfi);
3277
+    {
3278
+      if( p->afIndexRptCnt >= p->minAfIndexRptCnt )
3279
+      {
3280
+        p->afIndexRptCnt -= p->minAfIndexRptCnt;
3281
+        cmDspSetUInt(ctx,inst,kFIdxWtId,p->cfi);
3282
+      }
3283
+    }
3321 3284
 
3322
-    p->cfi += outCnt;
3285
+    p->afIndexRptCnt += outCnt;
3286
+    p->cfi           += outCnt;
3323 3287
 
3324 3288
   }
3325 3289
 

Loading…
Cancelar
Guardar