Browse Source

cmAudioPortAlsa.c : Added, but disabled, use of IMPULSE_FN.

master
Kevin Larke 10 years ago
parent
commit
ae14a04442
1 changed files with 59 additions and 2 deletions
  1. 59
    2
      linux/cmAudioPortAlsa.c

+ 59
- 2
linux/cmAudioPortAlsa.c View File

@@ -18,6 +18,8 @@
18 18
 #define DESC_CHAR_CNT (255)
19 19
 #define INIT_DEV_CNT  (5)
20 20
 
21
+//#define IMPULSE_FN "/home/kevin/temp/recd0.txt"
22
+
21 23
 enum { kDfltPeriodsPerBuf = 2, kPollfdsArrayCnt=2 };
22 24
 
23 25
 enum { kInFl=0x01, kOutFl=0x02 };
@@ -51,6 +53,14 @@ typedef struct devRecd_str
51 53
   cmApSample_t*        iBuf;    // iBuf[ iFpc * iChCnt ]
52 54
   cmApSample_t*        oBuf;    // oBuf[ oFpc * oChCnt ]
53 55
 
56
+  unsigned             oBufCnt;  // count of buffers written
57
+
58
+#ifdef IMPULSE_FN
59
+  int*                 recdBuf;
60
+  unsigned             recdN;
61
+  unsigned             recdIdx;
62
+#endif
63
+
54 64
   unsigned             iFpC;    // buffer frames per cycle  (in ALSA this is call period_size)
55 65
   unsigned             oFpC;
56 66
 
@@ -447,6 +457,12 @@ void _cmApDevAppend( cmApRoot_t* p, cmApDevRecd_t* drp )
447 457
   drp->devIdx  = p->devCnt; // set the device index 
448 458
   drp->rootPtr = p;         // set the pointer back to the root
449 459
 
460
+#ifdef IMPULSE_FN
461
+  drp->recdN   = 44100*2*2;
462
+  drp->recdBuf = cmMemAllocZ(int,drp->recdN);
463
+  drp->recdIdx = 0;
464
+#endif
465
+
450 466
   memcpy(p->devArray + p->devCnt, drp, sizeof(cmApDevRecd_t));
451 467
   
452 468
   ++p->devCnt;
@@ -597,7 +613,7 @@ void _cmApStateRecover( snd_pcm_t* pcmH, cmApDevRecd_t* drp, bool inputFl  )
597 613
 
598 614
 // Returns count of frames written on success or < 0 on error;
599 615
 // set smpPtr to NULL to write a buffer of silence
600
-int _cmApWriteBuf( const cmApDevRecd_t* drp, snd_pcm_t* pcmH, const cmApSample_t* sp, unsigned chCnt, unsigned frmCnt, unsigned bits, unsigned sigBits )
616
+int _cmApWriteBuf( cmApDevRecd_t* drp, snd_pcm_t* pcmH, const cmApSample_t* sp, unsigned chCnt, unsigned frmCnt, unsigned bits, unsigned sigBits )
601 617
 {
602 618
   int                 err         = 0;
603 619
   unsigned            bytesPerSmp = (bits==24 ? 32 : bits)/8;
@@ -641,15 +657,28 @@ int _cmApWriteBuf( const cmApDevRecd_t* drp, snd_pcm_t* pcmH, const cmApSample_t
641 657
       case 32:
642 658
         {
643 659
           int* dp = (int*)obuf;
660
+
644 661
           while( sp < ep )
645 662
             *dp++ = (int)(*sp++ * 0x7fffffff);        
663
+
664
+#ifdef IMPLUSE_FN
665
+          int* tmp = (int*)obuf;
666
+          unsigned ii = 0;
667
+          if( drp->oBufCnt < 3 )
668
+            for(; ii<32; ++ii)
669
+              tmp[ii] = 0x7fffffff;
670
+#endif
671
+
646 672
         }
647 673
         break;
648 674
     }
649 675
   }
650 676
 
677
+
651 678
   // send the bytes to the device
652 679
   err = snd_pcm_writei( pcmH, obuf, frmCnt );
680
+
681
+  ++drp->oBufCnt;
653 682
   
654 683
   if( err < 0 )
655 684
   {
@@ -670,7 +699,7 @@ int _cmApWriteBuf( const cmApDevRecd_t* drp, snd_pcm_t* pcmH, const cmApSample_t
670 699
 
671 700
 // Returns frames read on success or < 0 on error.
672 701
 // Set smpPtr to NULL to read the incoming buffer and discard it
673
-int _cmApReadBuf( const cmApDevRecd_t* drp, snd_pcm_t* pcmH, cmApSample_t* smpPtr, unsigned chCnt, unsigned frmCnt, unsigned bits, unsigned sigBits )
702
+int _cmApReadBuf( cmApDevRecd_t* drp, snd_pcm_t* pcmH, cmApSample_t* smpPtr, unsigned chCnt, unsigned frmCnt, unsigned bits, unsigned sigBits )
674 703
 {
675 704
   int      err         = 0;
676 705
   unsigned bytesPerSmp = (bits==24 ? 32 : bits)/8;
@@ -742,6 +771,14 @@ int _cmApReadBuf( const cmApDevRecd_t* drp, snd_pcm_t* pcmH, cmApSample_t* smpPt
742 771
         int  mv = sigBits==24 ? 0x7fffff00 : 0x7fffffff;
743 772
         while(dp < ep)
744 773
           *dp++ = ((cmApSample_t)*sp++) /  mv;
774
+
775
+#ifdef IMPULSE_FN
776
+        sp = (int*)buf;
777
+        int* esp = sp + smpCnt;
778
+        for(; sp<esp && drp->recdIdx < drp->recdN; ++drp->recdIdx)
779
+          drp->recdBuf[drp->recdIdx] = *sp++;
780
+#endif
781
+
745 782
       }
746 783
       break;
747 784
     default:
@@ -1435,6 +1472,7 @@ cmApRC_t      cmApAlsaInitialize( cmRpt_t* rpt, unsigned baseApDevIdx )
1435 1472
 
1436 1473
   } // card loop
1437 1474
 
1475
+
1438 1476
   if( rc == kOkApRC && p->asyncFl==false )
1439 1477
   {
1440 1478
     p->pollfdsCnt      = 0;
@@ -1469,8 +1507,26 @@ cmApRC_t      cmApAlsaFinalize()
1469 1507
   {
1470 1508
     _cmApDevShutdown(p,p->devArray+i,true);
1471 1509
     _cmApDevShutdown(p,p->devArray+i,false);
1510
+
1511
+#ifdef IMPULSE_FN
1512
+    if( p->devArray[i].recdIdx > 0 )
1513
+    {
1514
+      const char* fn = "/home/kevin/temp/recd0.txt";
1515
+      FILE* fp = fopen(fn,"wt");
1516
+      if( fp != NULL )
1517
+      {
1518
+        unsigned j;
1519
+        for(j=0; j<p->devArray[i].recdIdx; ++j)
1520
+          fprintf(fp,"%i\n",p->devArray[i].recdBuf[j]);
1521
+        fclose(fp);
1522
+      }
1523
+    }
1524
+    cmMemFree(p->devArray[i].recdBuf);
1525
+#endif
1526
+
1472 1527
     cmMemPtrFree(&p->devArray[i].iBuf);
1473 1528
     cmMemPtrFree(&p->devArray[i].oBuf);
1529
+  
1474 1530
   }
1475 1531
 
1476 1532
   cmMemPtrFree(&p->pollfds);
@@ -1483,6 +1539,7 @@ cmApRC_t      cmApAlsaFinalize()
1483 1539
   recdFree();
1484 1540
   //write_rec(2);
1485 1541
 
1542
+
1486 1543
   return rc;
1487 1544
 }
1488 1545
 

Loading…
Cancel
Save