Procházet zdrojové kódy

cmAudDsp,cmAudioFileDev,cmAudioPortFile,cmAudioSys: Changes to support audio port file devices.

master
kevin před 11 roky
rodič
revize
0efe33d6e0
9 změnil soubory, kde provedl 139 přidání a 16 odebrání
  1. 74
    1
      cmAudDsp.c
  2. 1
    0
      cmAudDsp.h
  3. 6
    4
      cmAudioFileDev.c
  4. 1
    0
      cmAudioFileDev.h
  5. 1
    1
      cmAudioNrtDev.c
  6. 46
    5
      cmAudioPortFile.c
  7. 2
    0
      cmAudioPortFile.h
  8. 4
    2
      cmAudioSys.c
  9. 4
    3
      cmAudioSys.h

+ 74
- 1
cmAudDsp.c Zobrazit soubor

@@ -14,6 +14,7 @@
14 14
 #include "cmAudioPort.h"
15 15
 #include "cmAudioAggDev.h"
16 16
 #include "cmAudioNrtDev.h"
17
+#include "cmAudioPortFile.h"
17 18
 #include "cmApBuf.h"
18 19
 #include "cmMidi.h"
19 20
 #include "cmMidiPort.h"
@@ -64,6 +65,15 @@ typedef struct
64 65
 
65 66
 typedef struct
66 67
 {
68
+  const cmChar_t* label;
69
+  const cmChar_t* inAudioFn;
70
+  const cmChar_t* outAudioFn;
71
+  unsigned        oBits;
72
+  unsigned        oChCnt;
73
+} cmAdAfpDev_t;
74
+
75
+typedef struct
76
+{
67 77
   cmErr_t            err;
68 78
   cmCtx_t            ctx;
69 79
   cmMsgSendFuncPtr_t cbFunc;
@@ -84,6 +94,9 @@ typedef struct
84 94
   cmAdNrtDev_t*      nrtDevArray;
85 95
   unsigned           nrtDevCnt;
86 96
 
97
+  cmAdAfpDev_t*      afpDevArray;
98
+  unsigned           afpDevCnt;
99
+
87 100
   cmAdAsCfg_t*       asCfgArray;
88 101
   unsigned           asCfgCnt;
89 102
   
@@ -151,6 +164,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
151 164
   cmJsonNode_t*   asCfgArrNodePtr  = NULL;
152 165
   cmJsonNode_t*   aggDevArrNodePtr = NULL;
153 166
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
167
+  cmJsonNode_t*   afpDevArrNodePtr = NULL;
154 168
   cmJsonNode_t*   audDspNodePtr    = NULL;
155 169
   const cmChar_t* errLabelPtr      = NULL;
156 170
   unsigned        i;
@@ -171,6 +185,7 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
171 185
         "audioSysCfgArray",   kArrayTId, &asCfgArrNodePtr,
172 186
         "aggDevArray",        kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
173 187
         "nrtDevArray",        kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
188
+        "afpDevArray",        kArrayTId | kOptArgJsFl, &afpDevArrNodePtr,
174 189
         NULL )) != kOkJsRC )
175 190
   {
176 191
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
@@ -242,6 +257,34 @@ cmAdRC_t _cmAdParseSysJsonTree( cmAd_t* p )
242 257
       }
243 258
 
244 259
     }
260
+    
261
+  }
262
+
263
+  // parse the audio file device specifications into p->afpDevArray[].
264
+  if( afpDevArrNodePtr != NULL && (p->afpDevCnt = cmJsonChildCount(afpDevArrNodePtr)) > 0)
265
+  {
266
+    // alloc the non-real-time spec. array
267
+    p->afpDevArray = cmMemResizeZ( cmAdAfpDev_t, p->afpDevArray, p->afpDevCnt );
268
+
269
+    // for each afp. device spec. recd
270
+    for(i=0; i<p->afpDevCnt; ++i)
271
+    {
272
+      const cmJsonNode_t* np   = cmJsonArrayElementC(afpDevArrNodePtr,i);
273
+
274
+      // read afpDevArray record values
275
+      if(( jsRC      = cmJsonMemberValues( np, &errLabelPtr, 
276
+            "label",      kStringTId,                &p->afpDevArray[i].label,
277
+            "iAudioFn",   kStringTId  | kOptArgJsFl, &p->afpDevArray[i].inAudioFn,
278
+            "oAudioFn",   kStringTId  | kOptArgJsFl, &p->afpDevArray[i].outAudioFn,
279
+            "oBits",      kIntTId     | kOptArgJsFl, &p->afpDevArray[i].oBits,
280
+            "oChCnt",     kIntTId     | kOptArgJsFl, &p->afpDevArray[i].oChCnt,
281
+            NULL )) != kOkJsRC )
282
+      {
283
+        rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, cmStringNullGuard(p->afpDevArray[i].label) );
284
+        goto errLabel;
285
+      }
286
+
287
+    }
245 288
 
246 289
   }
247 290
 
@@ -368,6 +411,26 @@ cmAdRC_t _cmAdCreateNrtDevices( cmAd_t* p )
368 411
   return rc;
369 412
 }
370 413
 
414
+cmAdRC_t _cmAdCreateAfpDevices( cmAd_t* p )
415
+{
416
+  cmAdRC_t rc = kOkAdRC;
417
+
418
+  if( cmApFileAllocate(p->err.rpt) != kOkApRC )
419
+    return cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device system allocation failed.");
420
+
421
+  unsigned i;
422
+  // create the audio file devices
423
+  for(i=0; i<p->afpDevCnt; ++i)
424
+  {
425
+    //const cmAudioSysFilePort_t* afp = cfg->afpArray + i;
426
+    cmAdAfpDev_t* afp = p->afpDevArray + i;
427
+    if( cmApFileDeviceCreate( afp->label, afp->inAudioFn, afp->outAudioFn, afp->oBits, afp->oChCnt ) != kOkApRC )
428
+      rc = cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device '%s' creation failed.",cmStringNullGuard(afp->label));
429
+  }
430
+
431
+  return rc;
432
+}
433
+
371 434
 cmAdRC_t _cmAdSendAudioSysCfgLabels( cmAd_t* p)
372 435
 {
373 436
   cmAdRC_t     rc = kOkAdRC;
@@ -480,9 +543,15 @@ cmAdRC_t _cmAudDspFree( cmAd_t* p )
480 543
     goto errLabel;
481 544
   }
482 545
 
546
+  if( cmApFileFree() != kOkApRC )
547
+  {
548
+    rc = cmErrMsg(&p->err,kAfpDevSysFailAdRC,"The audio file device system release failed.");
549
+    goto errLabel;
550
+  }
551
+
483 552
   if( cmApNrtFree() != kOkAgRC )
484 553
   {
485
-    rc = cmErrMsg(&p->err,kNrtDevSysFailAdRC,"The non-real-time device system realease failed.");
554
+    rc = cmErrMsg(&p->err,kNrtDevSysFailAdRC,"The non-real-time device system release failed.");
486 555
     goto errLabel;
487 556
   }
488 557
 
@@ -562,6 +631,10 @@ cmAdRC_t cmAudDspAlloc( cmCtx_t* ctx, cmAdH_t* hp, cmMsgSendFuncPtr_t cbFunc, vo
562 631
   if( _cmAdCreateNrtDevices(p) != kOkAdRC )
563 632
     goto errLabel;
564 633
 
634
+  // create the audio file devices
635
+  if( _cmAdCreateAfpDevices(p) != kOkAdRC )
636
+    goto errLabel;
637
+
565 638
   // initialize the audio device system
566 639
   if( cmApInitialize(&ctx->rpt) != kOkApRC )
567 640
   {

+ 1
- 0
cmAudDsp.h Zobrazit soubor

@@ -25,6 +25,7 @@ extern "C" {
25 25
     kAggDevSysFailAdRC,
26 26
     kAggDevCreateFailAdRC,
27 27
     kNrtDevSysFailAdRC,
28
+    kAfpDevSysFailAdRC,
28 29
     kNetSysFailAdRC
29 30
   };
30 31
 

+ 6
- 4
cmAudioFileDev.c Zobrazit soubor

@@ -220,8 +220,6 @@ cmAfdRC_t cmAudioFileDevInitialize(
220 220
       goto errLabel;
221 221
     }
222 222
 
223
-
224
-
225 223
     p->iPkt.devIdx         = devIdx;
226 224
     p->iPkt.begChIdx       = 0;
227 225
     p->iPkt.chCnt          = afInfo.chCnt;   // setting iPkt.chCnt to a non-zero value marks the input file as active
@@ -294,6 +292,7 @@ bool      cmAudioFileDevIsValid( cmAfdH_t h )
294 292
 
295 293
 cmAfdRC_t cmAudioFileDevSetup( 
296 294
   cmAfdH_t                        h, 
295
+  unsigned                        baseDevIdx,
297 296
   double                          srate, 
298 297
   unsigned                        framesPerCycle, 
299 298
   cmApCallbackPtr_t               callbackPtr, 
@@ -344,13 +343,14 @@ cmAfdRC_t cmAudioFileDevSetup(
344 343
 
345 344
     cmApSample_t* bp = (cmApSample_t*)p->oPkt.audioBytesPtr;
346 345
 
347
-    p->oPkt.devIdx         = p->devIdx;
346
+    p->oPkt.devIdx         = p->devIdx + baseDevIdx;
348 347
     p->oPkt.begChIdx       = 0;
349 348
     p->oPkt.chCnt          = p->oChCnt;
350 349
     p->oPkt.audioFramesCnt = framesPerCycle;
351 350
     p->oPkt.bitsPerSample  = p->oBits;
352 351
     p->oPkt.flags          = kFloatApFl;
353 352
     p->oPkt.audioBytesPtr  = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->oChCnt );
353
+    p->oPkt.userCbPtr      = cbDataPtr;
354 354
     p->oChArray            = cmMemResizeZ( cmApSample_t*, p->oChArray, p->oChCnt );
355 355
     
356 356
     for(i=0; i<p->oChCnt; ++i)
@@ -362,8 +362,10 @@ cmAfdRC_t cmAudioFileDevSetup(
362 362
   {
363 363
     cmApSample_t* bp = (cmApSample_t*)p->iPkt.audioBytesPtr;
364 364
 
365
+    p->iPkt.devIdx         = p->devIdx + baseDevIdx;
365 366
     p->iPkt.audioFramesCnt = framesPerCycle;
366 367
     p->iPkt.audioBytesPtr  = bp = cmMemResizeZ( cmApSample_t, bp, framesPerCycle*p->iPkt.chCnt ); ;
368
+    p->iPkt.userCbPtr      = cbDataPtr;
367 369
     for(i=0; i<p->iPkt.chCnt; ++i)
368 370
       p->iChArray[i] = bp + (i*framesPerCycle);
369 371
   }
@@ -534,7 +536,7 @@ void      cmAudioFileDevTest( cmRpt_t* rpt )
534 536
   if( cmAudioFileDevInitialize(&afdH,"file",devIdx,iFn,oFn,oBits,oChCnt,rpt) != kOkAfdRC )
535 537
     goto errLabel;
536 538
 
537
-  if( cmAudioFileDevSetup(afdH,srate,framesPerCycle,_cmAfdCallback,cbDataPtr) != kOkAfdRC )
539
+  if( cmAudioFileDevSetup(afdH,0,srate,framesPerCycle,_cmAfdCallback,cbDataPtr) != kOkAfdRC )
538 540
     goto errLabel;
539 541
 
540 542
   char c;

+ 1
- 0
cmAudioFileDev.h Zobrazit soubor

@@ -37,6 +37,7 @@ bool      cmAudioFileDevIsValid( cmAfdH_t h );
37 37
 /// Setup the device. This function must be called prior to cmAudioFileDevStart().
38 38
 cmAfdRC_t cmAudioFileDevSetup( 
39 39
   cmAfdH_t          h, 
40
+  unsigned          baseApDevIdx,
40 41
   double            srate, 
41 42
   unsigned          framesPerCycle, 
42 43
   cmApCallbackPtr_t callbackPtr, 

+ 1
- 1
cmAudioNrtDev.c Zobrazit soubor

@@ -25,7 +25,7 @@ typedef struct
25 25
 typedef struct cmApNrtDev_str
26 26
 {
27 27
   unsigned               flags;
28
-  unsigned               devIdx; // nrt device index
28
+  unsigned               devIdx;       // nrt device index
29 29
   unsigned               baseApDevIdx; // global audio device index for first nrt device
30 30
   cmChar_t*              label;         
31 31
   unsigned               iChCnt;

+ 46
- 5
cmAudioPortFile.c Zobrazit soubor

@@ -11,6 +11,8 @@
11 11
 typedef struct
12 12
 {
13 13
   cmAfdH_t devH;
14
+  unsigned devIdx;  // afp dev idx
15
+  unsigned baseApDevIdx; // global audio device index for first afp device
14 16
 } cmApDev_t;
15 17
 
16 18
 typedef struct
@@ -18,19 +20,53 @@ typedef struct
18 20
   cmErr_t    err;
19 21
   cmApDev_t* devArray;
20 22
   unsigned   devCnt;
23
+  unsigned   baseApDevIdx;
21 24
 } cmApf_t;
22 25
 
23 26
 cmApf_t* _cmApf = NULL;
24 27
 
25
-cmApRC_t      cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx )
28
+cmApRC_t      cmApFileAllocate( cmRpt_t* rpt )
26 29
 {
27
-  cmApRC_t rc;
28
-  if((rc = cmApFileFinalize()) != kOkApRC )
29
-    return rc;
30
+  cmApRC_t rc = kOkApRC;
31
+
32
+  if( _cmApf != NULL )
33
+    cmApFileFree();
30 34
 
31 35
   _cmApf = cmMemAllocZ(cmApf_t,1);
32 36
 
33 37
   cmErrSetup(&_cmApf->err,rpt,"Audio Port File");
38
+  _cmApf->devArray     = NULL;
39
+  _cmApf->devCnt       = 0;
40
+  _cmApf->baseApDevIdx = 0;
41
+
42
+  return rc;
43
+}
44
+
45
+cmApRC_t      cmApFileFree()
46
+{
47
+  cmApRC_t rc = kOkApRC;
48
+
49
+  if( _cmApf == NULL )
50
+    return rc;
51
+
52
+  if((rc = cmApFileFinalize()) != kOkApRC )
53
+    return rc;
54
+
55
+  cmMemFree(_cmApf);
56
+  _cmApf = NULL;
57
+  return rc;
58
+}
59
+
60
+
61
+cmApRC_t      cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx )
62
+{
63
+  cmApRC_t rc = kOkApRC;
64
+
65
+  unsigned i = 0;
66
+  for(; i<_cmApf->devCnt; ++i)
67
+    _cmApf->devArray[i].baseApDevIdx = baseApDevIdx;
68
+
69
+  _cmApf->baseApDevIdx = baseApDevIdx;
34 70
 
35 71
   return rc;      
36 72
 }
@@ -85,7 +121,12 @@ unsigned      cmApFileDeviceCreate(
85 121
   {
86 122
     cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device initialization failed.");
87 123
     i = cmInvalidIdx;
124
+    goto errLabel;
88 125
   }
126
+
127
+  _cmApf->devArray[i].devIdx = i;
128
+
129
+ errLabel:
89 130
   
90 131
   return i;
91 132
 }
@@ -134,7 +175,7 @@ cmApRC_t      cmApFileDeviceSetup(
134 175
 {
135 176
   assert( devIdx < cmApFileDeviceCount());
136 177
 
137
-  if( cmAudioFileDevSetup( _cmApf->devArray[devIdx].devH,srate,framesPerCycle,callbackPtr,userCbPtr) != kOkAfdRC )
178
+  if( cmAudioFileDevSetup( _cmApf->devArray[devIdx].devH,_cmApf->baseApDevIdx,srate,framesPerCycle,callbackPtr,userCbPtr) != kOkAfdRC )
138 179
     return cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device setup failed.");
139 180
 
140 181
   return kOkApRC;

+ 2
- 0
cmAudioPortFile.h Zobrazit soubor

@@ -5,6 +5,8 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  cmApRC_t      cmApFileAllocate( cmRpt_t* rpt );
9
+  cmApRC_t      cmApFileFree();
8 10
 
9 11
   cmApRC_t      cmApFileInitialize( cmRpt_t* rpt, unsigned baseApDevIdx );
10 12
   cmApRC_t      cmApFileFinalize();

+ 4
- 2
cmAudioSys.c Zobrazit soubor

@@ -729,11 +729,13 @@ cmAsRC_t cmAudioSysInitialize( cmAudioSysH_t h, const cmAudioSysCfg_t* cfg )
729 729
     return rc;
730 730
 
731 731
   // create the audio file devices
732
+  /*
732 733
   for(i=0; i<cfg->afpCnt; ++i)
733 734
   {
734 735
     const cmAudioSysFilePort_t* afp = cfg->afpArray + i;
735 736
     cmApFileDeviceCreate( afp->devLabel, afp->inAudioFn, afp->outAudioFn, afp->oBits, afp->oChCnt );
736 737
   }
738
+  */
737 739
 
738 740
   p->ssArray = cmMemAllocZ( _cmAsCfg_t, cfg->ssCnt );
739 741
   p->ssCnt   = cfg->ssCnt;
@@ -1281,8 +1283,8 @@ void cmAudioSysTest( cmRpt_t* rpt, int argc, const char* argv[] )
1281 1283
 
1282 1284
   cfg.ssArray = &ss;
1283 1285
   cfg.ssCnt   = 1;
1284
-  cfg.afpArray= NULL;
1285
-  cfg.afpCnt  = 0;
1286
+  //cfg.afpArray= NULL;
1287
+  //cfg.afpCnt  = 0;
1286 1288
   cfg.meterMs = 50;
1287 1289
 
1288 1290
   if(_cmAsGetBoolOpt(argc,argv,"-h",false))

+ 4
- 3
cmAudioSys.h Zobrazit soubor

@@ -172,6 +172,7 @@ extern "C" {
172 172
     
173 173
   } cmAudioSysCtx_t;
174 174
 
175
+  /*
175 176
   typedef struct
176 177
   {
177 178
     const cmChar_t* devLabel;
@@ -180,15 +181,15 @@ extern "C" {
180 181
     unsigned        oBits;
181 182
     unsigned        oChCnt;
182 183
   } cmAudioSysFilePort_t;
183
-
184
+  */
184 185
 
185 186
   /// Audio system configuration record used by cmAudioSysAllocate().
186 187
   typedef struct cmAudioSysCfg_str
187 188
   {
188 189
     cmAudioSysSubSys_t*   ssArray;      ///< sub-system cfg record array
189 190
     unsigned              ssCnt;        ///< count of sub-systems   
190
-    cmAudioSysFilePort_t* afpArray;     ///< audio port file cfg recd array
191
-    unsigned              afpCnt;       ///< audio port file cnt
191
+    //cmAudioSysFilePort_t* afpArray;     ///< audio port file cfg recd array
192
+    //unsigned              afpCnt;       ///< audio port file cnt
192 193
     unsigned              meterMs;      ///< Meter sample period in milliseconds
193 194
     void*                 clientCbData; ///< User arg. for clientCbFunc().
194 195
     cmTsQueueCb_t         clientCbFunc; ///< Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 

Načítá se…
Zrušit
Uložit