Bladeren bron

cmDspKr.c : Added ability to pre-load a list of segments for the cmRecdPlay object.

master
kevin 11 jaren geleden
bovenliggende
commit
d37fd59317
1 gewijzigde bestanden met toevoegingen van 78 en 14 verwijderingen
  1. 78
    14
      dsp/cmDspKr.c

+ 78
- 14
dsp/cmDspKr.c Bestand weergeven

@@ -2484,8 +2484,6 @@ enum
2484 2484
   kMaxLaSecsPrId,
2485 2485
   kCurLaSecsPrId,
2486 2486
   kFadeRatePrId,
2487
-  kSegFnPrId,
2488
-  kSegLblPrId,
2489 2487
   kScInitLocIdxPrId,
2490 2488
   kScLocIdxPrId,
2491 2489
   kCmdPrId,
@@ -2506,6 +2504,80 @@ typedef struct
2506 2504
   unsigned    scLocIdx;
2507 2505
 } cmDspRecdPlay_t;
2508 2506
 
2507
+cmDspRC_t _cmDspRecdPlayParseRsrc( cmDspCtx_t* ctx, cmDspInst_t* inst, cmRecdPlay* rcdply )
2508
+{
2509
+  cmDspRC_t       rc   = kOkDspRC;
2510
+  const cmChar_t* path = NULL;
2511
+
2512
+  // read the 'recdplay' audio file path
2513
+  if( cmDspRsrcString( ctx->dspH, &path, "recdPlayPath", NULL ) != kOkDspRC )
2514
+  {
2515
+    cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The 'recdPlayPath' resource string was not found.");
2516
+  }
2517
+
2518
+  if( path == NULL )
2519
+    path = "";
2520
+
2521
+  cmJsonH_t     jsH = cmDspSysPgmRsrcHandle(ctx->dspH);
2522
+  cmJsonNode_t* jnp = cmJsonFindValue(jsH,"recdPlay",NULL, kStringTId);
2523
+
2524
+  if( jnp == NULL || cmJsonIsArray(jnp)==false )
2525
+  {
2526
+    // this is really a warning - the object does not require preloaded segments.
2527
+    cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The 'recdPlay' resource used to define pre-loaded segments was not found.");
2528
+    return kOkDspRC;
2529
+  }
2530
+
2531
+  unsigned n = cmJsonChildCount(jnp);
2532
+  unsigned i;
2533
+
2534
+  // for each 'recdplay' segment record
2535
+  for(i=0; i<n && rc==kOkDspRC; ++i)
2536
+  {
2537
+    cmJsonNode_t*   cnp      = cmJsonArrayElement(jnp,i);
2538
+    const cmChar_t* label    = NULL;
2539
+    unsigned        segSymId = cmInvalidId;
2540
+    const cmChar_t* errLabel = NULL;
2541
+    const cmChar_t* fn       = NULL;
2542
+
2543
+    // read the ith segment record
2544
+    if( cmJsonMemberValues(cnp,&errLabel,
2545
+        "label", kStringTId, &label,
2546
+        "file",  kStringTId, &fn,
2547
+        NULL) != kOkJsRC )
2548
+    {
2549
+      rc = cmDspInstErr(ctx,inst,kRsrcNotFoundDspRC,"The record at index %i in the 'recdPlay' pre-loaded segment list could not be parsed.",i);
2550
+      goto errLabel;
2551
+    }
2552
+
2553
+    // find or generate the symbol id for the segment label symbol
2554
+    if((segSymId = cmSymTblRegisterSymbol(ctx->stH,label)) == cmInvalidId )
2555
+    {
2556
+      rc = cmDspInstErr(ctx,inst,kSymNotFoundDspRC,"The 'recdPlay' pre-load segment symbol '%s' could not be found or registered.",cmStringNullGuard(label));
2557
+      goto errLabel;
2558
+    }
2559
+
2560
+    // create the full path name for the segment audio file
2561
+    if((fn = cmFsMakeFn( path, fn, NULL, NULL )) == NULL )
2562
+    {
2563
+      rc = cmDspInstErr(ctx,inst,kFileSysFailDspRC,"The 'recdPlay' file name '%s/%s' could not be generated.",cmStringNullGuard(path),cmStringNullGuard(fn));
2564
+      goto errLabel;
2565
+    }
2566
+    
2567
+
2568
+    // pre-load the segment
2569
+    if( cmRecdPlayInsertRecord(rcdply,segSymId,fn) != cmOkRC )
2570
+      rc = cmDspInstErr(ctx,inst,kSubSysFailDspRC,"The 'recdPlay' segment label:'%s'  file:'%s' could not be loaded.",cmStringNullGuard(label),cmStringNullGuard(fn));
2571
+
2572
+   
2573
+    cmFsFreeFn(fn);
2574
+        
2575
+  }
2576
+  
2577
+ errLabel:
2578
+  return rc;
2579
+}
2580
+
2509 2581
 cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2510 2582
 {
2511 2583
   cmDspRC_t rc =kOkDspRC;
@@ -2517,10 +2589,10 @@ cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2517 2589
 
2518 2590
 
2519 2591
   if((fn = cmDspStrcz(inst,kFnPrId)) == NULL || strlen(fn)==0 )
2520
-    return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
2592
+    return cmDspInstErr(ctx,inst, kInvalidArgDspRC, "No score file name supplied.");
2521 2593
 
2522 2594
   if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL, ctx->stH ) != kOkScRC )
2523
-    return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
2595
+    return cmDspInstErr(ctx,inst, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
2524 2596
 
2525 2597
   if( cmScoreIsValid(p->scH) )
2526 2598
   {
@@ -2539,14 +2611,8 @@ cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2539 2611
     for(i=0; i<markerCnt; ++i)
2540 2612
       cmRecdPlayRegisterFrag(p->rcdply,i, cmScoreMarkerLabelSymbolId(p->scH,i ));
2541 2613
 
2542
-    const cmChar_t* segFn = cmDspStrcz(inst,kSegFnPrId);
2543
-    const cmChar_t* segLbl= cmDspStrcz(inst,kSegLblPrId);
2544
-    
2545
-    if( cmTextLength(segFn)>0 && cmTextLength(segLbl)>0 )
2546
-    {
2547
-      unsigned segSymId = cmSymTblRegisterSymbol(ctx->stH,segLbl);
2548
-      cmRecdPlayInsertRecord(p->rcdply,segSymId,segFn);
2549
-    }
2614
+    if((rc = _cmDspRecdPlayParseRsrc(ctx,inst,p->rcdply)) != kOkDspRC )
2615
+      rc = cmDspInstErr(ctx,inst,kInstResetFailDspRC,"The 'recdplay' segment pre-load failed.");
2550 2616
 
2551 2617
     p->scLocIdx = cmDspUInt(inst,kScInitLocIdxPrId);
2552 2618
 
@@ -2578,8 +2644,6 @@ cmDspInst_t*  _cmDspRecdPlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsig
2578 2644
     1,         "maxla",  kMaxLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kReqArgDsvFl, "Maximum look-ahead buffer in seconds.",
2579 2645
     1,         "curla",  kCurLaSecsPrId,  0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Current look-head buffer in seconds.",
2580 2646
     1,         "frate",  kFadeRatePrId,   0,0, kInDsvFl   | kDoubleDsvFl | kOptArgDsvFl, "Fade rate in dB per second.",
2581
-    1,         "segFn",  kSegFnPrId,      0,0, kInDsvFl   | kStrzDsvFl   | kOptArgDsvFl, "Preload an audio segment.",
2582
-    1,         "segLbl", kSegLblPrId,     0,0, kInDsvFl   | kStrzDsvFl   | kOptArgDsvFl, "Score symbol of preloaded audio segment.",
2583 2647
     1,         "initIdx",kScInitLocIdxPrId,0,0,kInDsvFl   | kUIntDsvFl,                  "Score search start location.",
2584 2648
     1,         "index",  kScLocIdxPrId,   0,0, kInDsvFl   | kUIntDsvFl,                "Score follower location index.",
2585 2649
     1,         "cmd",    kCmdPrId,        0,0, kInDsvFl   | kSymDsvFl,                 "on=reset off=stop.",

Laden…
Annuleren
Opslaan