Browse Source

cmDspBuiltIn.c : The AudioFileOut object no longer creates an output

file when the object is created. It now waits until it is sent an
'open' symbol to create the audio output file.

If the AudioFileOut object is sent a directory rather than a file then
it automatically generates a file name in the given directory.
master
kevin 11 years ago
parent
commit
9567d9211d
1 changed files with 22 additions and 4 deletions
  1. 22
    4
      dsp/cmDspBuiltIn.c

+ 22
- 4
dsp/cmDspBuiltIn.c View File

1474
   cmAudioFileH_t afH;
1474
   cmAudioFileH_t afH;
1475
   unsigned       openSymId;
1475
   unsigned       openSymId;
1476
   unsigned       closeSymId;
1476
   unsigned       closeSymId;
1477
+  const cmChar_t* afn;
1477
 } cmDspAudioFileOut_t;
1478
 } cmDspAudioFileOut_t;
1478
 
1479
 
1479
 cmDspRC_t _cmDspAudioFileOutCreateFile( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned chCnt )
1480
 cmDspRC_t _cmDspAudioFileOutCreateFile( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned chCnt )
1480
 {
1481
 {
1481
-  cmDspRC_t rc = kOkDspRC;
1482
+  cmDspRC_t            rc = kOkDspRC;
1482
   cmDspAudioFileOut_t* p  = (cmDspAudioFileOut_t*)inst;
1483
   cmDspAudioFileOut_t* p  = (cmDspAudioFileOut_t*)inst;
1483
   const cmChar_t*      fn = cmDspStrcz(inst,kFnAofId);
1484
   const cmChar_t*      fn = cmDspStrcz(inst,kFnAofId);
1484
 
1485
 
1485
   if(cmAudioFileIsValid(p->afH) )
1486
   if(cmAudioFileIsValid(p->afH) )
1486
     cmAudioFileDelete(&p->afH);
1487
     cmAudioFileDelete(&p->afH);
1487
 
1488
 
1489
+  // if the supplied audio file name is actually a directory name then generate a file name
1490
+  if( cmFsIsDir(fn) )
1491
+  {
1492
+    cmMemPtrFree(&p->afn);
1493
+
1494
+    if( cmFsGenFn(fn,"recd","aiff",&p->afn) != kOkFsRC )
1495
+      return cmDspInstErr(ctx,&p->inst,kFileSysFailDspRC,"An output audio file name could not be generated.");
1496
+    
1497
+    fn = p->afn;
1498
+  }
1499
+
1488
   if( cmAudioFileIsValid(p->afH =  cmAudioFileNewCreate(fn, cmDspSampleRate(ctx), p->bits, chCnt, &rc, ctx->rpt )) == false )
1500
   if( cmAudioFileIsValid(p->afH =  cmAudioFileNewCreate(fn, cmDspSampleRate(ctx), p->bits, chCnt, &rc, ctx->rpt )) == false )
1489
     rc = cmDspClassErr(ctx,inst->classPtr,kVarArgParseFailDspRC,"The output audio file '%s' create failed.",fn);
1501
     rc = cmDspClassErr(ctx,inst->classPtr,kVarArgParseFailDspRC,"The output audio file '%s' create failed.",fn);
1490
 
1502
 
1495
 {
1507
 {
1496
   cmDspVarArg_t args[] =
1508
   cmDspVarArg_t args[] =
1497
   {
1509
   {
1498
-    { "fn",    kFnAofId,    0,   0, kInDsvFl | kStrzDsvFl   | kReqArgDsvFl, "Audio file name"},
1510
+    { "fn",    kFnAofId,    0,   0, kInDsvFl | kStrzDsvFl   | kReqArgDsvFl, "Audio file or directory name"},
1499
     { "chs",   kChCntAofId, 0,   0, kInDsvFl | kUIntDsvFl   | kReqArgDsvFl, "Channel count"}, 
1511
     { "chs",   kChCntAofId, 0,   0, kInDsvFl | kUIntDsvFl   | kReqArgDsvFl, "Channel count"}, 
1500
     { "gain0", kGain0AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 0 multiplier"},  
1512
     { "gain0", kGain0AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 0 multiplier"},  
1501
     { "gain1", kGain1AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 1 multiplier"},
1513
     { "gain1", kGain1AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 1 multiplier"},
1534
   p->smpCnt = cmDspSamplesPerCycle(ctx) * chCnt;
1546
   p->smpCnt = cmDspSamplesPerCycle(ctx) * chCnt;
1535
   p->smpBuf = cmLhResizeN(ctx->lhH, cmSample_t, p->smpBuf, p->smpCnt);
1547
   p->smpBuf = cmLhResizeN(ctx->lhH, cmSample_t, p->smpBuf, p->smpCnt);
1536
   
1548
   
1537
-  rc = _cmDspAudioFileOutCreateFile( ctx, inst, chCnt );
1549
+  //rc = _cmDspAudioFileOutCreateFile( ctx, inst, chCnt );
1538
 
1550
 
1539
   return rc;
1551
   return rc;
1540
 } 
1552
 } 
1548
   cmSample_t*          chArray[chCnt];
1560
   cmSample_t*          chArray[chCnt];
1549
   unsigned             i,j;
1561
   unsigned             i,j;
1550
 
1562
 
1563
+  if(!cmAudioFileIsValid(p->afH) )
1564
+    return rc;
1565
+
1566
+
1551
   for(i=0,j=0; i<chCnt; ++i)
1567
   for(i=0,j=0; i<chCnt; ++i)
1552
   {
1568
   {
1553
     unsigned          chVarId = i == 0 ? kIn0AofId : kIn1AofId;     // get audio buf var id for this ch
1569
     unsigned          chVarId = i == 0 ? kIn0AofId : kIn1AofId;     // get audio buf var id for this ch
1561
     {
1577
     {
1562
       cmSample_t gain = cmDspSample(inst,i==0?kGain0AofId:kGain1AofId); // get ch gain
1578
       cmSample_t gain = cmDspSample(inst,i==0?kGain0AofId:kGain1AofId); // get ch gain
1563
     
1579
     
1564
-      chArray[j] = cmDspAudioBuf(ctx,inst,chVarId,i);                   // get incoming audio buf ptr
1580
+      chArray[j] = cmDspAudioBuf(ctx,inst,chVarId,0);                   // get incoming audio buf ptr
1565
 
1581
 
1566
       if( gain != 1.0 )
1582
       if( gain != 1.0 )
1567
         cmVOS_MultVVS(chArray[j], iSmpCnt, chArray[j], gain);           // apply gain
1583
         cmVOS_MultVVS(chArray[j], iSmpCnt, chArray[j], gain);           // apply gain
1625
   if(cmAudioFileIsValid(p->afH) )
1641
   if(cmAudioFileIsValid(p->afH) )
1626
     cmAudioFileDelete(&p->afH);
1642
     cmAudioFileDelete(&p->afH);
1627
 
1643
 
1644
+  cmMemPtrFree(&p->afn);
1645
+
1628
   return kOkDspRC;
1646
   return kOkDspRC;
1629
 }
1647
 }
1630
 
1648
 

Loading…
Cancel
Save