소스 검색

cmDspKr.h/c : Added the cmDspRecdPlay object.

The cmScoreInitialize() call in cmDspScore now is passed a valid symbol table handle.
master
kpl 11 년 전
부모
커밋
8f4981728c
2개의 변경된 파일249개의 추가작업 그리고 1개의 파일을 삭제
  1. 248
    1
      dsp/cmDspKr.c
  2. 1
    0
      dsp/cmDspKr.h

+ 248
- 1
dsp/cmDspKr.c 파일 보기

@@ -572,7 +572,7 @@ cmDspRC_t _cmDspScoreReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t*
572 572
   }
573 573
 
574 574
   if((tlFn =  cmDspStrcz(inst, kFnScId )) !=  NULL )
575
-    if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, cmDspSampleRate(ctx), dynRefArray, dynRefCnt, _cmDspScoreCb, p, cmSymTblNullHandle ) != kOkTlRC )
575
+    if( cmScoreInitialize(ctx->cmCtx, &p->scH, tlFn, cmDspSampleRate(ctx), dynRefArray, dynRefCnt, _cmDspScoreCb, p, ctx->stH ) != kOkTlRC )
576 576
       rc = cmErrMsg(&inst->classPtr->err, kInstResetFailDspRC, "Score file open failed.");
577 577
 
578 578
  errLabel:
@@ -2264,3 +2264,250 @@ struct cmDspClass_str* cmNanoMapClassCons( cmDspCtx_t* ctx )
2264 2264
 
2265 2265
   return &_cmNanoMapDC;
2266 2266
 }
2267
+
2268
+//==========================================================================================================================================
2269
+enum
2270
+{
2271
+  kChCntPrId,
2272
+  kFnPrId,
2273
+  kSecsPrId,
2274
+  kFadeRatePrId,
2275
+  kScLocIdxPrId,
2276
+  kCmdPrId,
2277
+  kInAudioBasePrId
2278
+};
2279
+
2280
+cmDspClass_t _cmRecdPlayDC;
2281
+
2282
+typedef struct
2283
+{
2284
+  cmDspInst_t inst;
2285
+  cmRecdPlay* rcdply;
2286
+  cmScH_t     scH;
2287
+  unsigned    onSymId;
2288
+  unsigned    offSymId;
2289
+  unsigned    audioOutBaseId;
2290
+  unsigned    chCnt;
2291
+  unsigned    scLocIdx;
2292
+} cmDspRecdPlay_t;
2293
+
2294
+cmDspRC_t _cmDspRecdPlayOpenScore( cmDspCtx_t* ctx, cmDspInst_t* inst )
2295
+{
2296
+  cmDspRC_t rc =kOkDspRC;
2297
+  const cmChar_t* fn;
2298
+
2299
+  cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2300
+
2301
+  p->scLocIdx = 0;
2302
+
2303
+
2304
+  if((fn = cmDspStrcz(inst,kFnPrId)) == NULL || strlen(fn)==0 )
2305
+    return cmErrMsg(&inst->classPtr->err, kInvalidArgDspRC, "No score file name supplied.");
2306
+
2307
+  if( cmScoreInitialize(ctx->cmCtx, &p->scH, fn, cmDspSampleRate(ctx), NULL, 0, NULL, NULL, ctx->stH ) != kOkScRC )
2308
+    return cmErrMsg(&inst->classPtr->err, kSubSysFailDspRC, "Unable to open the score '%s'.",fn);
2309
+
2310
+  if( cmScoreIsValid(p->scH) )
2311
+  {
2312
+    unsigned i;
2313
+    unsigned markerCnt = cmScoreMarkerLabelCount(p->scH);
2314
+
2315
+    if((p->rcdply = cmRecdPlayAlloc(ctx->cmProcCtx, NULL, cmDspSampleRate(ctx), markerCnt, p->chCnt, cmDspDouble(inst,kSecsPrId))) == NULL)
2316
+      return cmErrMsg(&inst->classPtr->err,kSubSysFailDspRC,"Unable to create the internal recorder-player object.");    
2317
+
2318
+    for(i=0; i<markerCnt; ++i)
2319
+      cmRecdPlayRegisterFrag(p->rcdply,i, cmScoreMarkerLabelSymbolId(p->scH,i ));
2320
+
2321
+  }
2322
+
2323
+  return rc;
2324
+}
2325
+
2326
+
2327
+cmDspInst_t*  _cmDspRecdPlayAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, unsigned storeSymId, unsigned instSymId, unsigned id, unsigned va_cnt, va_list vl )
2328
+{
2329
+
2330
+  if( va_cnt < 1 )
2331
+  {
2332
+    cmDspClassErr(ctx,classPtr,kVarArgParseFailDspRC,"The 'RecdPlay' constructor must have a count of input ports.");
2333
+    return NULL;
2334
+  }
2335
+
2336
+  va_list vl1;
2337
+  va_copy(vl1,vl);
2338
+
2339
+  int      chCnt         = va_arg(vl,int);
2340
+  unsigned audioOutBase  = kInAudioBasePrId + chCnt;    
2341
+
2342
+  cmDspRecdPlay_t* p = cmDspInstAllocV(cmDspRecdPlay_t,ctx,classPtr,instSymId,id,storeSymId,va_cnt,vl1,
2343
+    1,         "chs",    kChCntPrId,      0,0, kUIntDsvFl | kReqArgDsvFl,              "channel count.",
2344
+    1,         "fn",     kFnPrId,         0,0, kInDsvFl   | kStrzDsvFl | kReqArgDsvFl, "Score file." ,
2345
+    1,         "secs",   kSecsPrId,       0,0, kInDsvFl   | kDoubleDsvFl | kReqArgDsvFl, "Initial fragment allocation in seconds.",
2346
+    1,         "frate",  kFadeRatePrId,   0,0, kInDsvFl   | kDoubleDsvFl,              "Fade rate in dB per second.",
2347
+    1,         "index",  kScLocIdxPrId,   0,0, kInDsvFl   | kUIntDsvFl,                "Score follower location index.",
2348
+    1,         "cmd",    kCmdPrId,        0,0, kInDsvFl   | kSymDsvFl,                 "on=reset off=stop.",
2349
+    chCnt,     "in",     kInAudioBasePrId,0,1, kInDsvFl   | kAudioBufDsvFl,            "Audio input",
2350
+    chCnt,     "out",    audioOutBase,    0,1, kOutDsvFl  | kAudioBufDsvFl,            "Audio output",
2351
+    0 );
2352
+
2353
+  va_end(vl1);
2354
+
2355
+  p->onSymId        = cmSymTblId(ctx->stH,"on");
2356
+  p->offSymId       = cmSymTblId(ctx->stH,"off");
2357
+  p->audioOutBaseId = audioOutBase;
2358
+  p->chCnt          = chCnt;
2359
+  p->scLocIdx       = 0;
2360
+
2361
+  cmDspSetDefaultDouble(ctx,&p->inst, kSecsPrId,     0, 10.0 );
2362
+  cmDspSetDefaultDouble(ctx,&p->inst, kFadeRatePrId, 0, 1.0);
2363
+
2364
+  return &p->inst;
2365
+}
2366
+
2367
+cmDspRC_t _cmDspRecdPlayFree(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2368
+{
2369
+  cmDspRC_t        rc = kOkDspRC;
2370
+  cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2371
+
2372
+  cmRecdPlayFree(&p->rcdply);
2373
+
2374
+  cmScoreFinalize(&p->scH);
2375
+  return rc;
2376
+}
2377
+
2378
+cmDspRC_t _cmDspRecdPlayReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2379
+{
2380
+  cmDspApplyAllDefaults(ctx,inst);
2381
+
2382
+  return _cmDspRecdPlayOpenScore(ctx,inst);
2383
+} 
2384
+
2385
+cmDspRC_t _cmDspRecdPlayExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2386
+{
2387
+  cmDspRC_t      rc = kOkDspRC;
2388
+
2389
+  cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2390
+
2391
+  const cmSample_t* x[ p->chCnt ];
2392
+  cmSample_t*       y[ p->chCnt ];
2393
+  unsigned n;
2394
+  unsigned i;
2395
+  unsigned actChCnt = 0;
2396
+
2397
+  for(i=0; i<p->chCnt; ++i)
2398
+  {
2399
+    if( i==0 )
2400
+      n  = cmDspAudioBufSmpCount(ctx,inst,kInAudioBasePrId+i,0);
2401
+    else
2402
+    { assert( n == cmDspAudioBufSmpCount(ctx,inst,kInAudioBasePrId+i,0)); }
2403
+
2404
+    x[i] = cmDspAudioBuf(ctx,inst,kInAudioBasePrId+i,0);
2405
+
2406
+    if( x[i] != NULL )
2407
+    {
2408
+      y[i] = cmDspAudioBuf(ctx,inst,p->audioOutBaseId+i,0);
2409
+
2410
+      if( y[i] != NULL )
2411
+      {
2412
+        assert( n == cmDspAudioBufSmpCount(ctx,inst,p->audioOutBaseId+i,0));
2413
+
2414
+        cmVOS_Zero(y[i],n);
2415
+
2416
+        actChCnt += 1;
2417
+      }
2418
+      
2419
+    }
2420
+  }
2421
+
2422
+  cmRecdPlayExec(p->rcdply,x,y,actChCnt,n);
2423
+
2424
+  return rc;
2425
+}
2426
+
2427
+cmDspRC_t _cmDspRecdPlayRecv(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDspEvt_t* evt )
2428
+{
2429
+  cmDspRecdPlay_t* p = (cmDspRecdPlay_t*)inst;
2430
+
2431
+  cmDspSetEvent(ctx,inst,evt);
2432
+
2433
+  switch( evt->dstVarId )
2434
+  {
2435
+    case kCmdPrId:
2436
+      if( cmDspSymbol(inst,kCmdPrId) == p->onSymId )
2437
+      {
2438
+        printf("rewind\n");
2439
+        cmRecdPlayRewind(p->rcdply);
2440
+        p->scLocIdx = 0;
2441
+      }
2442
+      else
2443
+        if( cmDspSymbol(inst,kCmdPrId) == p->offSymId )
2444
+        {
2445
+        }
2446
+
2447
+      break;
2448
+
2449
+    case kScLocIdxPrId:
2450
+      {
2451
+        unsigned endScLocIdx = cmDspUInt(inst,kScLocIdxPrId) ;
2452
+
2453
+        for(; p->scLocIdx<=endScLocIdx; p->scLocIdx+=1)
2454
+        {
2455
+          cmScoreLoc_t*    loc = cmScoreLoc(p->scH, p->scLocIdx );
2456
+          cmScoreMarker_t* mp  = loc->markList;
2457
+
2458
+          for(; mp!=NULL; mp=mp->link)
2459
+            switch( mp->markTypeId )
2460
+            {
2461
+              case kRecdBegScMId:
2462
+                printf("recd-beg\n");
2463
+                cmRecdPlayBeginRecord(p->rcdply, mp->labelSymId );
2464
+                break;
2465
+                
2466
+              case kRecdEndScMId:
2467
+                printf("recd-end\n");
2468
+                cmRecdPlayEndRecord(p->rcdply, mp->labelSymId );
2469
+                break;
2470
+                
2471
+              case kPlayBegScMId:
2472
+                printf("play-beg\n");
2473
+                cmRecdPlayBeginPlay(p->rcdply, mp->labelSymId );
2474
+                break;
2475
+
2476
+              case kPlayEndScMId:
2477
+                printf("recd-end\n");
2478
+                cmRecdPlayEndPlay(p->rcdply, mp->labelSymId );
2479
+                break;
2480
+
2481
+              case kFadeScMId:
2482
+                printf("fade-beg\n");
2483
+                cmRecdPlayBeginFade(p->rcdply, mp->labelSymId, cmDspDouble(inst,kFadeRatePrId) );
2484
+                break;
2485
+
2486
+              default:
2487
+                break;
2488
+            }
2489
+        }
2490
+
2491
+        p->scLocIdx = endScLocIdx+1;
2492
+      }
2493
+      break;
2494
+  }
2495
+
2496
+  return kOkDspRC;
2497
+}
2498
+
2499
+struct cmDspClass_str* cmRecdPlayClassCons( cmDspCtx_t* ctx )
2500
+{
2501
+  cmDspClassSetup(&_cmRecdPlayDC,ctx,"RecdPlay",
2502
+    NULL,
2503
+    _cmDspRecdPlayAlloc,
2504
+    _cmDspRecdPlayFree,
2505
+    _cmDspRecdPlayReset,
2506
+    _cmDspRecdPlayExec,
2507
+    _cmDspRecdPlayRecv,
2508
+    NULL,
2509
+    NULL,
2510
+    "Score controlled live recorder/player");
2511
+
2512
+  return &_cmRecdPlayDC;
2513
+}

+ 1
- 0
dsp/cmDspKr.h 파일 보기

@@ -16,6 +16,7 @@ extern "C" {
16 16
   struct cmDspClass_str* cmActiveMeasClassCons( cmDspCtx_t* ctx );
17 17
   struct cmDspClass_str* cmAmSyncClassCons( cmDspCtx_t* ctx );
18 18
   struct cmDspClass_str* cmNanoMapClassCons( cmDspCtx_t* ctx );
19
+  struct cmDspClass_str* cmRecdPlayClassCons( cmDspCtx_t* ctx );
19 20
 
20 21
 #ifdef __cplusplus
21 22
 }

Loading…
취소
저장