Browse Source

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

master
kevin 11 years ago
parent
commit
0efe33d6e0
9 changed files with 139 additions and 16 deletions
  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 View File

14
 #include "cmAudioPort.h"
14
 #include "cmAudioPort.h"
15
 #include "cmAudioAggDev.h"
15
 #include "cmAudioAggDev.h"
16
 #include "cmAudioNrtDev.h"
16
 #include "cmAudioNrtDev.h"
17
+#include "cmAudioPortFile.h"
17
 #include "cmApBuf.h"
18
 #include "cmApBuf.h"
18
 #include "cmMidi.h"
19
 #include "cmMidi.h"
19
 #include "cmMidiPort.h"
20
 #include "cmMidiPort.h"
64
 
65
 
65
 typedef struct
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
   cmErr_t            err;
77
   cmErr_t            err;
68
   cmCtx_t            ctx;
78
   cmCtx_t            ctx;
69
   cmMsgSendFuncPtr_t cbFunc;
79
   cmMsgSendFuncPtr_t cbFunc;
84
   cmAdNrtDev_t*      nrtDevArray;
94
   cmAdNrtDev_t*      nrtDevArray;
85
   unsigned           nrtDevCnt;
95
   unsigned           nrtDevCnt;
86
 
96
 
97
+  cmAdAfpDev_t*      afpDevArray;
98
+  unsigned           afpDevCnt;
99
+
87
   cmAdAsCfg_t*       asCfgArray;
100
   cmAdAsCfg_t*       asCfgArray;
88
   unsigned           asCfgCnt;
101
   unsigned           asCfgCnt;
89
   
102
   
151
   cmJsonNode_t*   asCfgArrNodePtr  = NULL;
164
   cmJsonNode_t*   asCfgArrNodePtr  = NULL;
152
   cmJsonNode_t*   aggDevArrNodePtr = NULL;
165
   cmJsonNode_t*   aggDevArrNodePtr = NULL;
153
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
166
   cmJsonNode_t*   nrtDevArrNodePtr = NULL;
167
+  cmJsonNode_t*   afpDevArrNodePtr = NULL;
154
   cmJsonNode_t*   audDspNodePtr    = NULL;
168
   cmJsonNode_t*   audDspNodePtr    = NULL;
155
   const cmChar_t* errLabelPtr      = NULL;
169
   const cmChar_t* errLabelPtr      = NULL;
156
   unsigned        i;
170
   unsigned        i;
171
         "audioSysCfgArray",   kArrayTId, &asCfgArrNodePtr,
185
         "audioSysCfgArray",   kArrayTId, &asCfgArrNodePtr,
172
         "aggDevArray",        kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
186
         "aggDevArray",        kArrayTId | kOptArgJsFl, &aggDevArrNodePtr,
173
         "nrtDevArray",        kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
187
         "nrtDevArray",        kArrayTId | kOptArgJsFl, &nrtDevArrNodePtr,
188
+        "afpDevArray",        kArrayTId | kOptArgJsFl, &afpDevArrNodePtr,
174
         NULL )) != kOkJsRC )
189
         NULL )) != kOkJsRC )
175
   {
190
   {
176
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
191
     rc = _cmAdParseMemberErr(p, jsRC, errLabelPtr, "aud_dsp" );
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
   return rc;
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
 cmAdRC_t _cmAdSendAudioSysCfgLabels( cmAd_t* p)
434
 cmAdRC_t _cmAdSendAudioSysCfgLabels( cmAd_t* p)
372
 {
435
 {
373
   cmAdRC_t     rc = kOkAdRC;
436
   cmAdRC_t     rc = kOkAdRC;
480
     goto errLabel;
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
   if( cmApNrtFree() != kOkAgRC )
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
     goto errLabel;
555
     goto errLabel;
487
   }
556
   }
488
 
557
 
562
   if( _cmAdCreateNrtDevices(p) != kOkAdRC )
631
   if( _cmAdCreateNrtDevices(p) != kOkAdRC )
563
     goto errLabel;
632
     goto errLabel;
564
 
633
 
634
+  // create the audio file devices
635
+  if( _cmAdCreateAfpDevices(p) != kOkAdRC )
636
+    goto errLabel;
637
+
565
   // initialize the audio device system
638
   // initialize the audio device system
566
   if( cmApInitialize(&ctx->rpt) != kOkApRC )
639
   if( cmApInitialize(&ctx->rpt) != kOkApRC )
567
   {
640
   {

+ 1
- 0
cmAudDsp.h View File

25
     kAggDevSysFailAdRC,
25
     kAggDevSysFailAdRC,
26
     kAggDevCreateFailAdRC,
26
     kAggDevCreateFailAdRC,
27
     kNrtDevSysFailAdRC,
27
     kNrtDevSysFailAdRC,
28
+    kAfpDevSysFailAdRC,
28
     kNetSysFailAdRC
29
     kNetSysFailAdRC
29
   };
30
   };
30
 
31
 

+ 6
- 4
cmAudioFileDev.c View File

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

+ 1
- 0
cmAudioFileDev.h View File

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

+ 1
- 1
cmAudioNrtDev.c View File

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

+ 46
- 5
cmAudioPortFile.c View File

11
 typedef struct
11
 typedef struct
12
 {
12
 {
13
   cmAfdH_t devH;
13
   cmAfdH_t devH;
14
+  unsigned devIdx;  // afp dev idx
15
+  unsigned baseApDevIdx; // global audio device index for first afp device
14
 } cmApDev_t;
16
 } cmApDev_t;
15
 
17
 
16
 typedef struct
18
 typedef struct
18
   cmErr_t    err;
20
   cmErr_t    err;
19
   cmApDev_t* devArray;
21
   cmApDev_t* devArray;
20
   unsigned   devCnt;
22
   unsigned   devCnt;
23
+  unsigned   baseApDevIdx;
21
 } cmApf_t;
24
 } cmApf_t;
22
 
25
 
23
 cmApf_t* _cmApf = NULL;
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
   _cmApf = cmMemAllocZ(cmApf_t,1);
35
   _cmApf = cmMemAllocZ(cmApf_t,1);
32
 
36
 
33
   cmErrSetup(&_cmApf->err,rpt,"Audio Port File");
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
   return rc;      
71
   return rc;      
36
 }
72
 }
85
   {
121
   {
86
     cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device initialization failed.");
122
     cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device initialization failed.");
87
     i = cmInvalidIdx;
123
     i = cmInvalidIdx;
124
+    goto errLabel;
88
   }
125
   }
126
+
127
+  _cmApf->devArray[i].devIdx = i;
128
+
129
+ errLabel:
89
   
130
   
90
   return i;
131
   return i;
91
 }
132
 }
134
 {
175
 {
135
   assert( devIdx < cmApFileDeviceCount());
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
     return cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device setup failed.");
179
     return cmErrMsg(&_cmApf->err,kAudioPortFileFailApRC,"The audio file device setup failed.");
139
 
180
 
140
   return kOkApRC;
181
   return kOkApRC;

+ 2
- 0
cmAudioPortFile.h View File

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

+ 4
- 2
cmAudioSys.c View File

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

+ 4
- 3
cmAudioSys.h View File

172
     
172
     
173
   } cmAudioSysCtx_t;
173
   } cmAudioSysCtx_t;
174
 
174
 
175
+  /*
175
   typedef struct
176
   typedef struct
176
   {
177
   {
177
     const cmChar_t* devLabel;
178
     const cmChar_t* devLabel;
180
     unsigned        oBits;
181
     unsigned        oBits;
181
     unsigned        oChCnt;
182
     unsigned        oChCnt;
182
   } cmAudioSysFilePort_t;
183
   } cmAudioSysFilePort_t;
183
-
184
+  */
184
 
185
 
185
   /// Audio system configuration record used by cmAudioSysAllocate().
186
   /// Audio system configuration record used by cmAudioSysAllocate().
186
   typedef struct cmAudioSysCfg_str
187
   typedef struct cmAudioSysCfg_str
187
   {
188
   {
188
     cmAudioSysSubSys_t*   ssArray;      ///< sub-system cfg record array
189
     cmAudioSysSubSys_t*   ssArray;      ///< sub-system cfg record array
189
     unsigned              ssCnt;        ///< count of sub-systems   
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
     unsigned              meterMs;      ///< Meter sample period in milliseconds
193
     unsigned              meterMs;      ///< Meter sample period in milliseconds
193
     void*                 clientCbData; ///< User arg. for clientCbFunc().
194
     void*                 clientCbData; ///< User arg. for clientCbFunc().
194
     cmTsQueueCb_t         clientCbFunc; ///< Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 
195
     cmTsQueueCb_t         clientCbFunc; ///< Called by  cmAudioSysReceiveMsg() to deliver internally generated msg's to the host. 

Loading…
Cancel
Save