Преглед изворни кода

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

master
Kevin Larke пре 10 година
родитељ
комит
ae14a04442
1 измењених фајлова са 59 додато и 2 уклоњено
  1. 59
    2
      linux/cmAudioPortAlsa.c

+ 59
- 2
linux/cmAudioPortAlsa.c Прегледај датотеку

18
 #define DESC_CHAR_CNT (255)
18
 #define DESC_CHAR_CNT (255)
19
 #define INIT_DEV_CNT  (5)
19
 #define INIT_DEV_CNT  (5)
20
 
20
 
21
+//#define IMPULSE_FN "/home/kevin/temp/recd0.txt"
22
+
21
 enum { kDfltPeriodsPerBuf = 2, kPollfdsArrayCnt=2 };
23
 enum { kDfltPeriodsPerBuf = 2, kPollfdsArrayCnt=2 };
22
 
24
 
23
 enum { kInFl=0x01, kOutFl=0x02 };
25
 enum { kInFl=0x01, kOutFl=0x02 };
51
   cmApSample_t*        iBuf;    // iBuf[ iFpc * iChCnt ]
53
   cmApSample_t*        iBuf;    // iBuf[ iFpc * iChCnt ]
52
   cmApSample_t*        oBuf;    // oBuf[ oFpc * oChCnt ]
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
   unsigned             iFpC;    // buffer frames per cycle  (in ALSA this is call period_size)
64
   unsigned             iFpC;    // buffer frames per cycle  (in ALSA this is call period_size)
55
   unsigned             oFpC;
65
   unsigned             oFpC;
56
 
66
 
447
   drp->devIdx  = p->devCnt; // set the device index 
457
   drp->devIdx  = p->devCnt; // set the device index 
448
   drp->rootPtr = p;         // set the pointer back to the root
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
   memcpy(p->devArray + p->devCnt, drp, sizeof(cmApDevRecd_t));
466
   memcpy(p->devArray + p->devCnt, drp, sizeof(cmApDevRecd_t));
451
   
467
   
452
   ++p->devCnt;
468
   ++p->devCnt;
597
 
613
 
598
 // Returns count of frames written on success or < 0 on error;
614
 // Returns count of frames written on success or < 0 on error;
599
 // set smpPtr to NULL to write a buffer of silence
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
   int                 err         = 0;
618
   int                 err         = 0;
603
   unsigned            bytesPerSmp = (bits==24 ? 32 : bits)/8;
619
   unsigned            bytesPerSmp = (bits==24 ? 32 : bits)/8;
641
       case 32:
657
       case 32:
642
         {
658
         {
643
           int* dp = (int*)obuf;
659
           int* dp = (int*)obuf;
660
+
644
           while( sp < ep )
661
           while( sp < ep )
645
             *dp++ = (int)(*sp++ * 0x7fffffff);        
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
         break;
673
         break;
648
     }
674
     }
649
   }
675
   }
650
 
676
 
677
+
651
   // send the bytes to the device
678
   // send the bytes to the device
652
   err = snd_pcm_writei( pcmH, obuf, frmCnt );
679
   err = snd_pcm_writei( pcmH, obuf, frmCnt );
680
+
681
+  ++drp->oBufCnt;
653
   
682
   
654
   if( err < 0 )
683
   if( err < 0 )
655
   {
684
   {
670
 
699
 
671
 // Returns frames read on success or < 0 on error.
700
 // Returns frames read on success or < 0 on error.
672
 // Set smpPtr to NULL to read the incoming buffer and discard it
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
   int      err         = 0;
704
   int      err         = 0;
676
   unsigned bytesPerSmp = (bits==24 ? 32 : bits)/8;
705
   unsigned bytesPerSmp = (bits==24 ? 32 : bits)/8;
742
         int  mv = sigBits==24 ? 0x7fffff00 : 0x7fffffff;
771
         int  mv = sigBits==24 ? 0x7fffff00 : 0x7fffffff;
743
         while(dp < ep)
772
         while(dp < ep)
744
           *dp++ = ((cmApSample_t)*sp++) /  mv;
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
       break;
783
       break;
747
     default:
784
     default:
1435
 
1472
 
1436
   } // card loop
1473
   } // card loop
1437
 
1474
 
1475
+
1438
   if( rc == kOkApRC && p->asyncFl==false )
1476
   if( rc == kOkApRC && p->asyncFl==false )
1439
   {
1477
   {
1440
     p->pollfdsCnt      = 0;
1478
     p->pollfdsCnt      = 0;
1469
   {
1507
   {
1470
     _cmApDevShutdown(p,p->devArray+i,true);
1508
     _cmApDevShutdown(p,p->devArray+i,true);
1471
     _cmApDevShutdown(p,p->devArray+i,false);
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
     cmMemPtrFree(&p->devArray[i].iBuf);
1527
     cmMemPtrFree(&p->devArray[i].iBuf);
1473
     cmMemPtrFree(&p->devArray[i].oBuf);
1528
     cmMemPtrFree(&p->devArray[i].oBuf);
1529
+  
1474
   }
1530
   }
1475
 
1531
 
1476
   cmMemPtrFree(&p->pollfds);
1532
   cmMemPtrFree(&p->pollfds);
1483
   recdFree();
1539
   recdFree();
1484
   //write_rec(2);
1540
   //write_rec(2);
1485
 
1541
 
1542
+
1486
   return rc;
1543
   return rc;
1487
 }
1544
 }
1488
 
1545
 

Loading…
Откажи
Сачувај