Browse Source

cmAudDsp.h/c, cmAudioNrtDev.c,cmAudioSys.h : Audio devices are now set in aud_dsp.js by their name rather than their index.

master
kevin 4 years ago
parent
commit
186f815636
4 changed files with 62 additions and 14 deletions
  1. 44
    3
      src/cmAudDsp.c
  2. 2
    1
      src/cmAudDsp.h
  3. 4
    0
      src/cmAudioNrtDev.c
  4. 12
    10
      src/cmAudioSys.h

+ 44
- 3
src/cmAudDsp.c View File

354
     {
354
     {
355
       cmAudioSysArgs_t*   asap        = &p->asCfgArray[i].cfg.ssArray[j].args;
355
       cmAudioSysArgs_t*   asap        = &p->asCfgArray[i].cfg.ssArray[j].args;
356
       const cmJsonNode_t* argsNodePtr = cmJsonArrayElementC(ssArrayNodePtr,j);
356
       const cmJsonNode_t* argsNodePtr = cmJsonArrayElementC(ssArrayNodePtr,j);
357
+      
358
+      asap->inDevIdx    = cmInvalidIdx;
359
+      asap->outDevIdx   = cmInvalidIdx;
360
+      asap->inDevLabel  = NULL;
361
+      asap->outDevLabel = NULL;
357
 
362
 
358
       if((jsRC = cmJsonMemberValues( argsNodePtr, &errLabelPtr,
363
       if((jsRC = cmJsonMemberValues( argsNodePtr, &errLabelPtr,
359
-          "inDevIdx",           kIntTId,  &asap->inDevIdx,
360
-          "outDevIdx",          kIntTId,  &asap->outDevIdx,
364
+          "inDevLabel",         kStringTId,  &asap->inDevLabel,
365
+          "outDevLabel",        kStringTId,  &asap->outDevLabel,
361
           "syncToInputFl",      kTrueTId, &asap->syncInputFl,
366
           "syncToInputFl",      kTrueTId, &asap->syncInputFl,
362
           "msgQueueByteCnt",    kIntTId,  &asap->msgQueueByteCnt,
367
           "msgQueueByteCnt",    kIntTId,  &asap->msgQueueByteCnt,
363
           "devFramesPerCycle",  kIntTId,  &asap->devFramesPerCycle,
368
           "devFramesPerCycle",  kIntTId,  &asap->devFramesPerCycle,
443
   return rc;
448
   return rc;
444
 }
449
 }
445
 
450
 
451
+cmAdRC_t _cmAdResolveDeviceLabels( cmAd_t* p )
452
+{
453
+  cmAdRC_t rc = kOkAdRC;
454
+  unsigned i,j;
455
+  
456
+  // for each cmAsAudioSysCfg record in audioSysCfgArray[]
457
+  for(i=0; i<p->asCfgCnt; ++i)
458
+  {
459
+    // for each audio system sub-subsystem 
460
+    for(j=0; j<p->asCfgArray[i].cfg.ssCnt; ++j)
461
+    {
462
+      cmAudioSysArgs_t*   asap        = &p->asCfgArray[i].cfg.ssArray[j].args;
463
+      if((asap->inDevIdx = cmApDeviceLabelToIndex( asap->inDevLabel )) == cmInvalidId )
464
+      {
465
+        rc = cmErrMsg(&p->err,kInvalidAudioDevIdxAdRC,"The audio input device '%s' could not be found.", cmStringNullGuard(asap->inDevLabel));
466
+        goto errLabel;
467
+      }
468
+      
469
+      if((asap->outDevIdx = cmApDeviceLabelToIndex( asap->outDevLabel )) == cmInvalidId )
470
+      {
471
+        rc = cmErrMsg(&p->err,kInvalidAudioDevIdxAdRC,"The audio input device '%s' could not be found.", cmStringNullGuard(asap->inDevLabel));
472
+        goto errLabel;
473
+      }
474
+    }
475
+  }
476
+ errLabel:
477
+  return rc;
478
+}
479
+
446
 cmAdRC_t _cmAdCreateNrtDevices( cmAd_t* p )
480
 cmAdRC_t _cmAdCreateNrtDevices( cmAd_t* p )
447
 {
481
 {
448
   cmAdRC_t rc = kOkAdRC;
482
   cmAdRC_t rc = kOkAdRC;
721
   if((rc = _cmAdParseSysJsonTree(p)) != kOkAdRC )
755
   if((rc = _cmAdParseSysJsonTree(p)) != kOkAdRC )
722
     goto errLabel;
756
     goto errLabel;
723
 
757
 
758
+ 
724
   // create the aggregate device
759
   // create the aggregate device
725
   if( _cmAdCreateAggDevices(p) != kOkAdRC )
760
   if( _cmAdCreateAggDevices(p) != kOkAdRC )
726
     goto errLabel;
761
     goto errLabel;
727
-
762
+  
728
   // create the non-real-time devices
763
   // create the non-real-time devices
729
   if( _cmAdCreateNrtDevices(p) != kOkAdRC )
764
   if( _cmAdCreateNrtDevices(p) != kOkAdRC )
730
     goto errLabel;
765
     goto errLabel;
740
     goto errLabel;
775
     goto errLabel;
741
   }
776
   }
742
 
777
 
778
+  if( _cmAdResolveDeviceLabels(p) != kOkApRC )
779
+  {
780
+    rc = cmErrMsg(&p->err,kAudioPortFailAdRC,"Audio device labels could not be resolved..");
781
+    goto errLabel;
782
+  }
783
+
743
   // initialize the audio buffer
784
   // initialize the audio buffer
744
   if( cmApBufInitialize( cmApDeviceCount(), p->meterMs ) != kOkApRC )
785
   if( cmApBufInitialize( cmApDeviceCount(), p->meterMs ) != kOkApRC )
745
   {
786
   {

+ 2
- 1
src/cmAudDsp.h View File

27
     kAggDevCreateFailAdRC,
27
     kAggDevCreateFailAdRC,
28
     kNrtDevSysFailAdRC,
28
     kNrtDevSysFailAdRC,
29
     kAfpDevSysFailAdRC,
29
     kAfpDevSysFailAdRC,
30
-    kNetSysFailAdRC
30
+    kNetSysFailAdRC,
31
+    kInvalidAudioDevIdxAdRC
31
   };
32
   };
32
 
33
 
33
 
34
 

+ 4
- 0
src/cmAudioNrtDev.c View File

189
 cmApRC_t cmApNrtFree()
189
 cmApRC_t cmApNrtFree()
190
 {
190
 {
191
   cmApRC_t rc = kOkApRC;
191
   cmApRC_t rc = kOkApRC;
192
+  
193
+  if( _cmNrt == NULL )
194
+    return rc;
195
+  
192
   cmApNrtDev_t* dp = _cmNrt->devs;
196
   cmApNrtDev_t* dp = _cmNrt->devs;
193
   while( dp != NULL )
197
   while( dp != NULL )
194
   {
198
   {

+ 12
- 10
src/cmAudioSys.h View File

130
   // Audio device sub-sytem configuration record 
130
   // Audio device sub-sytem configuration record 
131
   typedef struct cmAudioSysArgs_str
131
   typedef struct cmAudioSysArgs_str
132
   {
132
   {
133
-    cmRpt_t*       rpt;               // system console object
134
-    unsigned       inDevIdx;          // input audio device
135
-    unsigned       outDevIdx;         // output audio device
136
-    bool           syncInputFl;       // true/false sync the DSP update callbacks with audio input/output
137
-    unsigned       msgQueueByteCnt;   // Size of the internal msg queue used to buffer msgs arriving via cmAudioSysDeliverMsg().
138
-    unsigned       devFramesPerCycle; // (512) Audio device samples per channel per device update buffer.
139
-    unsigned       dspFramesPerCycle; // (64)  Audio samples per channel per DSP cycle.
140
-    unsigned       audioBufCnt;       // (3)   Audio device buffers.
141
-    double         srate;             // Audio sample rate.
142
-    int            srateMult;         // Sample rate multiplication factor (negative for divide)
133
+    cmRpt_t*        rpt;               // system console object
134
+    const cmChar_t* inDevLabel;        // input audio device text label
135
+    const cmChar_t* outDevLabel;       // output audio device text label
136
+    unsigned        inDevIdx;          // input audio device index
137
+    unsigned        outDevIdx;         // output audio device index 
138
+    bool            syncInputFl;       // true/false sync the DSP update callbacks with audio input/output
139
+    unsigned        msgQueueByteCnt;   // Size of the internal msg queue used to buffer msgs arriving via cmAudioSysDeliverMsg().
140
+    unsigned        devFramesPerCycle; // (512) Audio device samples per channel per device update buffer.
141
+    unsigned        dspFramesPerCycle; // (64)  Audio samples per channel per DSP cycle.
142
+    unsigned        audioBufCnt;       // (3)   Audio device buffers.
143
+    double          srate;             // Audio sample rate.
144
+    int             srateMult;         // Sample rate multiplication factor (negative for divide)
143
   } cmAudioSysArgs_t;
145
   } cmAudioSysArgs_t;
144
 
146
 
145
   // Audio sub-system configuration record.
147
   // Audio sub-system configuration record.

Loading…
Cancel
Save