Procházet zdrojové kódy

cmApBuf.c : Fixed bug in call to generate output test tone.

master
kevin před 4 roky
rodič
revize
7630f0a453
1 změnil soubory, kde provedl 25 přidání a 24 odebrání
  1. 25
    24
      cmApBuf.c

+ 25
- 24
cmApBuf.c Zobrazit soubor

@@ -212,13 +212,13 @@ unsigned _cmApCopyOutDnSample( const cmApSample_t* src, unsigned srcN, unsigned
212 212
 
213 213
   // The total count of output samples is determined by 'dstN'
214 214
   // Downsampling is acheived by advancing the src index by 'div' samples.
215
-  
215
+
216 216
   for(di=0,si=srcIdx; di<dstN; ++di)
217 217
   {
218 218
     dst[di*dstChN+dstChIdx] = gain * src[si];
219 219
     si = (si + div) % srcN;
220 220
   }
221
-  
221
+
222 222
   return si;  
223 223
 }
224 224
 
@@ -267,6 +267,7 @@ unsigned  _cmApSine( cmApCh* cp, cmApSample_t* dst, unsigned dstN, unsigned dstI
267 267
     di = (di+dstChCnt) % dstN;
268 268
   }
269 269
 
270
+  
270 271
   return sigN;
271 272
 }
272 273
 
@@ -298,8 +299,8 @@ void _cmApChInitialize( cmApCh* chPtr, unsigned n, unsigned mn )
298 299
   chPtr->oi   = 0;
299 300
   chPtr->fn   = 0;
300 301
   chPtr->fl   = (n!=0 ? kChApFl : 0);
301
-  chPtr->hz   = 1000;
302
-  chPtr->gain = 1.0;
302
+  chPtr->hz   = 440;
303
+  chPtr->gain = 0.8; // use reduced gain to prevent clipping
303 304
   chPtr->mn   = mn;
304 305
   chPtr->m    = cmMemAllocZ(cmApSample_t,mn);
305 306
   chPtr->mi   = 0;
@@ -582,8 +583,8 @@ cmAbRC_t cmApBufUpdate(
582 583
       for(j=0; j<pp->chCnt; ++j)
583 584
       {
584 585
         cmApCh*  cp = op->chArray + pp->begChIdx + j; // dest ch
585
-        unsigned n0 = op->n - cp->oi;                 // first src segment
586
-        unsigned n1 = 0;                              // second src segment
586
+        //unsigned n0 = op->n - cp->oi;                 // first src segment
587
+        //unsigned n1 = 0;                              // second src segment
587 588
         volatile unsigned fn = cp->fn; // store fn because it may be changed by the client thread
588 589
 
589 590
         // if the outgoing samples  will underflow the buffer 
@@ -602,29 +603,28 @@ cmAbRC_t cmApBufUpdate(
602 603
           pp->audioFramesCnt = fn;
603 604
         }
604 605
 
606
+        
605 607
         // if the outgong segments would go off the end of the buffer then 
606
-        // arrange to wrap to the begining of the buffer
607
-        if( n0 < pp->audioFramesCnt )
608
-          n1 = pp->audioFramesCnt-n0;
609
-        else
610
-          n0 = pp->audioFramesCnt;
611
-
612
-        cmApSample_t* bpp   = ((cmApSample_t*)pp->audioBytesPtr) + j;
613
-        //cmApSample_t* dp    = bpp;
614
-        bool          enaFl = cmIsFlag(cp->fl,kChApFl) && cmIsFlag(cp->fl,kMuteApFl)==false;
615
-
616
-        unsigned decrSmpN = 0;
608
+        //// arrange to wrap to the begining of the buffer
609
+        //if( n0 < pp->audioFramesCnt )
610
+        //  n1 = pp->audioFramesCnt-n0;
611
+        //else
612
+        //  n0 = pp->audioFramesCnt;
613
+
614
+        //cmApSample_t* bpp      = ((cmApSample_t*)pp->audioBytesPtr) + j;
615
+        //cmApSample_t* dp     = bpp;
616
+        bool          enaFl    = cmIsFlag(cp->fl,kChApFl) && cmIsFlag(cp->fl,kMuteApFl)==false;
617
+        unsigned      decrSmpN = 0;
617 618
         
618 619
         // if the tone is enabled on this channel
619 620
         if( enaFl && cmIsFlag(cp->fl,kToneApFl) )
620 621
         {
621 622
           //_cmApSine(cp, dp, n0, dp + n0*pp->chCnt, n1, pp->chCnt, op->srate );
622
-          decrSmpN =  _cmApSine( cp, (cmApSample_t*)pp->audioBytesPtr, pp->audioFramesCnt, 0,  pp->chCnt, pp->audioFramesCnt, op->srateMult, op->srate, cp->gain );
623
-
623
+          decrSmpN =  _cmApSine( cp, (cmApSample_t*)pp->audioBytesPtr, pp->audioFramesCnt * pp->chCnt, j,  pp->chCnt, pp->audioFramesCnt, op->srateMult, op->srate, cp->gain );
624 624
         }
625
-        else                    // otherwise copy samples from the output buffer to the packet
625
+        else    // otherwise copy samples from the output buffer to the packet
626 626
         {
627
-          const cmApSample_t* sp = enaFl ? cp->b + cp->oi : _cmApBuf.zeroBuf;
627
+          //const cmApSample_t* sp = enaFl ? cp->b + cp->oi : _cmApBuf.zeroBuf;
628 628
           //const cmApSample_t* ep = sp + n0;
629 629
 
630 630
           unsigned pi = cp->oi;
@@ -632,7 +632,8 @@ cmAbRC_t cmApBufUpdate(
632 632
 
633 633
           decrSmpN = cp->oi>pi ? cp->oi-pi : (op->n-pi) + cp->oi;
634 634
 
635
-          if( true )
635
+          /*
636
+          if( false )
636 637
             if( j == 2 && _cmApBuf.abufIdx < 16384 )
637 638
             {
638 639
               int ii;
@@ -643,7 +644,7 @@ cmAbRC_t cmApBufUpdate(
643 644
               }
644 645
 
645 646
             }
646
-          
647
+          */
647 648
           /*
648 649
           // copy the first segment
649 650
           for(; sp < ep; dp += pp->chCnt )
@@ -678,7 +679,7 @@ cmAbRC_t cmApBufUpdate(
678 679
         //cp->fn -= pp->audioFramesCnt;
679 680
         cmThUIntDecr(&cp->fn,decrSmpN);
680 681
       }
681
-    }    
682
+    }
682 683
   }
683 684
   return kOkAbRC;
684 685
 }

Načítá se…
Zrušit
Uložit