Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
9567d9211d
1 değiştirilmiş dosya ile 22 ekleme ve 4 silme
  1. 22
    4
      dsp/cmDspBuiltIn.c

+ 22
- 4
dsp/cmDspBuiltIn.c Dosyayı Görüntüle

@@ -1474,17 +1474,29 @@ typedef struct
1474 1474
   cmAudioFileH_t afH;
1475 1475
   unsigned       openSymId;
1476 1476
   unsigned       closeSymId;
1477
+  const cmChar_t* afn;
1477 1478
 } cmDspAudioFileOut_t;
1478 1479
 
1479 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 1483
   cmDspAudioFileOut_t* p  = (cmDspAudioFileOut_t*)inst;
1483 1484
   const cmChar_t*      fn = cmDspStrcz(inst,kFnAofId);
1484 1485
 
1485 1486
   if(cmAudioFileIsValid(p->afH) )
1486 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 1500
   if( cmAudioFileIsValid(p->afH =  cmAudioFileNewCreate(fn, cmDspSampleRate(ctx), p->bits, chCnt, &rc, ctx->rpt )) == false )
1489 1501
     rc = cmDspClassErr(ctx,inst->classPtr,kVarArgParseFailDspRC,"The output audio file '%s' create failed.",fn);
1490 1502
 
@@ -1495,7 +1507,7 @@ cmDspInst_t*  _cmDspAudioFileOutAlloc(cmDspCtx_t* ctx, cmDspClass_t* classPtr, u
1495 1507
 {
1496 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 1511
     { "chs",   kChCntAofId, 0,   0, kInDsvFl | kUIntDsvFl   | kReqArgDsvFl, "Channel count"}, 
1500 1512
     { "gain0", kGain0AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 0 multiplier"},  
1501 1513
     { "gain1", kGain1AofId, 0,   0, kInDsvFl | kDoubleDsvFl | kOptArgDsvFl, "Output gain 1 multiplier"},
@@ -1534,7 +1546,7 @@ cmDspRC_t _cmDspAudioFileOutReset(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDs
1534 1546
   p->smpCnt = cmDspSamplesPerCycle(ctx) * chCnt;
1535 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 1551
   return rc;
1540 1552
 } 
@@ -1548,6 +1560,10 @@ cmDspRC_t _cmDspAudioFileOutExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
1548 1560
   cmSample_t*          chArray[chCnt];
1549 1561
   unsigned             i,j;
1550 1562
 
1563
+  if(!cmAudioFileIsValid(p->afH) )
1564
+    return rc;
1565
+
1566
+
1551 1567
   for(i=0,j=0; i<chCnt; ++i)
1552 1568
   {
1553 1569
     unsigned          chVarId = i == 0 ? kIn0AofId : kIn1AofId;     // get audio buf var id for this ch
@@ -1561,7 +1577,7 @@ cmDspRC_t _cmDspAudioFileOutExec(cmDspCtx_t* ctx, cmDspInst_t* inst, const cmDsp
1561 1577
     {
1562 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 1582
       if( gain != 1.0 )
1567 1583
         cmVOS_MultVVS(chArray[j], iSmpCnt, chArray[j], gain);           // apply gain
@@ -1625,6 +1641,8 @@ cmDspRC_t  _cmDspAudioFileOutFree( cmDspCtx_t* ctx, struct cmDspInst_str*  inst,
1625 1641
   if(cmAudioFileIsValid(p->afH) )
1626 1642
     cmAudioFileDelete(&p->afH);
1627 1643
 
1644
+  cmMemPtrFree(&p->afn);
1645
+
1628 1646
   return kOkDspRC;
1629 1647
 }
1630 1648
 

Loading…
İptal
Kaydet