Browse Source

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

master
kevin 4 years ago
parent
commit
7630f0a453
1 changed files with 25 additions and 24 deletions
  1. 25
    24
      cmApBuf.c

+ 25
- 24
cmApBuf.c View File

212
 
212
 
213
   // The total count of output samples is determined by 'dstN'
213
   // The total count of output samples is determined by 'dstN'
214
   // Downsampling is acheived by advancing the src index by 'div' samples.
214
   // Downsampling is acheived by advancing the src index by 'div' samples.
215
-  
215
+
216
   for(di=0,si=srcIdx; di<dstN; ++di)
216
   for(di=0,si=srcIdx; di<dstN; ++di)
217
   {
217
   {
218
     dst[di*dstChN+dstChIdx] = gain * src[si];
218
     dst[di*dstChN+dstChIdx] = gain * src[si];
219
     si = (si + div) % srcN;
219
     si = (si + div) % srcN;
220
   }
220
   }
221
-  
221
+
222
   return si;  
222
   return si;  
223
 }
223
 }
224
 
224
 
267
     di = (di+dstChCnt) % dstN;
267
     di = (di+dstChCnt) % dstN;
268
   }
268
   }
269
 
269
 
270
+  
270
   return sigN;
271
   return sigN;
271
 }
272
 }
272
 
273
 
298
   chPtr->oi   = 0;
299
   chPtr->oi   = 0;
299
   chPtr->fn   = 0;
300
   chPtr->fn   = 0;
300
   chPtr->fl   = (n!=0 ? kChApFl : 0);
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
   chPtr->mn   = mn;
304
   chPtr->mn   = mn;
304
   chPtr->m    = cmMemAllocZ(cmApSample_t,mn);
305
   chPtr->m    = cmMemAllocZ(cmApSample_t,mn);
305
   chPtr->mi   = 0;
306
   chPtr->mi   = 0;
582
       for(j=0; j<pp->chCnt; ++j)
583
       for(j=0; j<pp->chCnt; ++j)
583
       {
584
       {
584
         cmApCh*  cp = op->chArray + pp->begChIdx + j; // dest ch
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
         volatile unsigned fn = cp->fn; // store fn because it may be changed by the client thread
588
         volatile unsigned fn = cp->fn; // store fn because it may be changed by the client thread
588
 
589
 
589
         // if the outgoing samples  will underflow the buffer 
590
         // if the outgoing samples  will underflow the buffer 
602
           pp->audioFramesCnt = fn;
603
           pp->audioFramesCnt = fn;
603
         }
604
         }
604
 
605
 
606
+        
605
         // if the outgong segments would go off the end of the buffer then 
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
         // if the tone is enabled on this channel
619
         // if the tone is enabled on this channel
619
         if( enaFl && cmIsFlag(cp->fl,kToneApFl) )
620
         if( enaFl && cmIsFlag(cp->fl,kToneApFl) )
620
         {
621
         {
621
           //_cmApSine(cp, dp, n0, dp + n0*pp->chCnt, n1, pp->chCnt, op->srate );
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
           //const cmApSample_t* ep = sp + n0;
628
           //const cmApSample_t* ep = sp + n0;
629
 
629
 
630
           unsigned pi = cp->oi;
630
           unsigned pi = cp->oi;
632
 
632
 
633
           decrSmpN = cp->oi>pi ? cp->oi-pi : (op->n-pi) + cp->oi;
633
           decrSmpN = cp->oi>pi ? cp->oi-pi : (op->n-pi) + cp->oi;
634
 
634
 
635
-          if( true )
635
+          /*
636
+          if( false )
636
             if( j == 2 && _cmApBuf.abufIdx < 16384 )
637
             if( j == 2 && _cmApBuf.abufIdx < 16384 )
637
             {
638
             {
638
               int ii;
639
               int ii;
643
               }
644
               }
644
 
645
 
645
             }
646
             }
646
-          
647
+          */
647
           /*
648
           /*
648
           // copy the first segment
649
           // copy the first segment
649
           for(; sp < ep; dp += pp->chCnt )
650
           for(; sp < ep; dp += pp->chCnt )
678
         //cp->fn -= pp->audioFramesCnt;
679
         //cp->fn -= pp->audioFramesCnt;
679
         cmThUIntDecr(&cp->fn,decrSmpN);
680
         cmThUIntDecr(&cp->fn,decrSmpN);
680
       }
681
       }
681
-    }    
682
+    }
682
   }
683
   }
683
   return kOkAbRC;
684
   return kOkAbRC;
684
 }
685
 }

Loading…
Cancel
Save