Skip to content

Commit

Permalink
properly handle output buffering.
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremysalwen committed Jun 4, 2011
1 parent 4abf43f commit 1c19e1b
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions kn0ck0ut6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,16 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp

{
static long gRover=false;
static long outAccumIndex=0;
static long outAccumIndex=0;
static long copiesremaining=0;

if(numSampsToProcess<copiesremaining) {
outAccumIndex=copy_from_circular_buffer(fftFrameSize,outdata,gOutputAccum,outAccumIndex,numSampsToProcess);
copiesremaining-=numSampsToProcess;
} else {
outAccumIndex=copy_from_circular_buffer(fftFrameSize,outdata,gOutputAccum,outAccumIndex,copiesremaining);
copiesremaining=0;
}
/* set up some handy variables */
long fftFrameSize2 = fftFrameSize/2;
long stepSize = fftFrameSize/osamp;
Expand All @@ -167,7 +176,7 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp
gRover = inFifoLatency;
}
/* main processing loop */
for (long i = 0; i < numSampsToProcess; i++){
for (long i=0; i < numSampsToProcess; i++){

/* As long as we have not yet collected enough data just read in */
gInFIFO[gRover] = indata[i];
Expand Down Expand Up @@ -333,22 +342,16 @@ void AKnockout::do_rebuild(long numSampsToProcess, long fftFrameSize, long osamp
inindex++;
}
}
long max=outAccumIndex+stepSize;
long offset=i-outAccumIndex;
if(max<fftFrameSize) {
for(; outAccumIndex<max; outAccumIndex++ ) {
outdata[outAccumIndex+offset]=gOutputAccum[outAccumIndex];
}
} else {
for(; outAccumIndex<fftFrameSize; outAccumIndex++ ) {
outdata[outAccumIndex+offset]=gOutputAccum[outAccumIndex];
}
max-=fftFrameSize;
offset+=fftFrameSize;
for(outAccumIndex=0; outAccumIndex<max; outAccumIndex++ ) {
outdata[outAccumIndex+offset]=gOutputAccum[outAccumIndex];
}
}
//We output as much of the buffer as we can now, and use copiesremaining to notify later run() calls to empty the
//rest of the buffer when it can.
long numcopy=stepSize;
if(numcopy>(numSampsToProcess-i-1)) {
numcopy=numSampsToProcess-i-1;
copiesremaining=stepSize-numcopy;
copiesremaining*=(copiesremaining>0);
}
outAccumIndex=copy_from_circular_buffer(fftFrameSize,(outdata+i),gOutputAccum,outAccumIndex,numcopy);

memmove (gInFIFO, gInFIFO+stepSize, inFifoLatency*sizeof(float));
memmove (gInFIFO2, gInFIFO2+stepSize, inFifoLatency*sizeof(float));

Expand Down

0 comments on commit 1c19e1b

Please sign in to comment.