Various fixes for R8Brain resampler wrapper
Fixes to the resampler wrapper, such that it will survive some close encounters with the edge of the buffer, if necessary. Also so it will obey the buffer size limit for the output buffer. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
e1fa8d1e9b
commit
ed0f7d81ab
|
@ -8,9 +8,12 @@
|
|||
#ifndef r8bstate_h
|
||||
#define r8bstate_h
|
||||
|
||||
#include "CDSPResampler.h"
|
||||
#include <Accelerate/Accelerate.h>
|
||||
|
||||
#include "r8bbase.h"
|
||||
|
||||
#include "CDSPResampler.h"
|
||||
|
||||
struct r8bstate {
|
||||
int channelCount;
|
||||
int bufferCapacity;
|
||||
|
@ -53,6 +56,7 @@ struct r8bstate {
|
|||
}
|
||||
remainder -= blockCount;
|
||||
output += channelCount * blockCount;
|
||||
outProcessed += blockCount;
|
||||
outMax -= blockCount;
|
||||
ret += blockCount;
|
||||
if(!outMax)
|
||||
|
@ -78,13 +82,15 @@ struct r8bstate {
|
|||
}
|
||||
}
|
||||
}
|
||||
size_t outputActual = outputDone - remainder;
|
||||
input += channelCount * blockCount;
|
||||
output += channelCount * outputDone;
|
||||
output += channelCount * outputActual;
|
||||
inCount -= blockCount;
|
||||
if(inDone) *inDone += blockCount;
|
||||
inProcessed += blockCount;
|
||||
outProcessed += outputDone;
|
||||
ret += outputDone;
|
||||
outProcessed += outputActual;
|
||||
outMax -= outputActual;
|
||||
ret += outputActual;
|
||||
if(remainder)
|
||||
break;
|
||||
}
|
||||
|
@ -103,6 +109,7 @@ struct r8bstate {
|
|||
}
|
||||
remainder -= blockCount;
|
||||
output += channelCount * blockCount;
|
||||
outProcessed += blockCount;
|
||||
outMax -= blockCount;
|
||||
ret += blockCount;
|
||||
if(!outMax)
|
||||
|
@ -118,12 +125,23 @@ struct r8bstate {
|
|||
if(outputDone) {
|
||||
if(outputDone > (outputWanted - outProcessed))
|
||||
outputDone = (int)(outputWanted - outProcessed);
|
||||
vDSP_vdpsp(outputPointer, 1, output + i, channelCount, outputDone);
|
||||
if(outputDone > outMax) {
|
||||
vDSP_vdpsp(outputPointer, 1, output + i, channelCount, outMax);
|
||||
remainder = outputDone - outMax;
|
||||
OutBufs[i].alloc((int)remainder);
|
||||
memcpy(&OutBufs[i][0], outputPointer + outMax, remainder);
|
||||
} else {
|
||||
vDSP_vdpsp(outputPointer, 1, output + i, channelCount, outputDone);
|
||||
}
|
||||
}
|
||||
}
|
||||
outProcessed += outputDone;
|
||||
output += channelCount * outputDone;
|
||||
ret += outputDone;
|
||||
size_t outputActual = outputDone - remainder;
|
||||
outProcessed += outputActual;
|
||||
output += channelCount * outputActual;
|
||||
outMax -= outputActual;
|
||||
ret += outputActual;
|
||||
if(remainder)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue