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
|
#ifndef r8bstate_h
|
||||||
#define r8bstate_h
|
#define r8bstate_h
|
||||||
|
|
||||||
#include "CDSPResampler.h"
|
#include <Accelerate/Accelerate.h>
|
||||||
|
|
||||||
#include "r8bbase.h"
|
#include "r8bbase.h"
|
||||||
|
|
||||||
|
#include "CDSPResampler.h"
|
||||||
|
|
||||||
struct r8bstate {
|
struct r8bstate {
|
||||||
int channelCount;
|
int channelCount;
|
||||||
int bufferCapacity;
|
int bufferCapacity;
|
||||||
|
@ -53,6 +56,7 @@ struct r8bstate {
|
||||||
}
|
}
|
||||||
remainder -= blockCount;
|
remainder -= blockCount;
|
||||||
output += channelCount * blockCount;
|
output += channelCount * blockCount;
|
||||||
|
outProcessed += blockCount;
|
||||||
outMax -= blockCount;
|
outMax -= blockCount;
|
||||||
ret += blockCount;
|
ret += blockCount;
|
||||||
if(!outMax)
|
if(!outMax)
|
||||||
|
@ -78,13 +82,15 @@ struct r8bstate {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
size_t outputActual = outputDone - remainder;
|
||||||
input += channelCount * blockCount;
|
input += channelCount * blockCount;
|
||||||
output += channelCount * outputDone;
|
output += channelCount * outputActual;
|
||||||
inCount -= blockCount;
|
inCount -= blockCount;
|
||||||
if(inDone) *inDone += blockCount;
|
if(inDone) *inDone += blockCount;
|
||||||
inProcessed += blockCount;
|
inProcessed += blockCount;
|
||||||
outProcessed += outputDone;
|
outProcessed += outputActual;
|
||||||
ret += outputDone;
|
outMax -= outputActual;
|
||||||
|
ret += outputActual;
|
||||||
if(remainder)
|
if(remainder)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -103,6 +109,7 @@ struct r8bstate {
|
||||||
}
|
}
|
||||||
remainder -= blockCount;
|
remainder -= blockCount;
|
||||||
output += channelCount * blockCount;
|
output += channelCount * blockCount;
|
||||||
|
outProcessed += blockCount;
|
||||||
outMax -= blockCount;
|
outMax -= blockCount;
|
||||||
ret += blockCount;
|
ret += blockCount;
|
||||||
if(!outMax)
|
if(!outMax)
|
||||||
|
@ -118,12 +125,23 @@ struct r8bstate {
|
||||||
if(outputDone) {
|
if(outputDone) {
|
||||||
if(outputDone > (outputWanted - outProcessed))
|
if(outputDone > (outputWanted - outProcessed))
|
||||||
outputDone = (int)(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;
|
size_t outputActual = outputDone - remainder;
|
||||||
output += channelCount * outputDone;
|
outProcessed += outputActual;
|
||||||
ret += outputDone;
|
output += channelCount * outputActual;
|
||||||
|
outMax -= outputActual;
|
||||||
|
ret += outputActual;
|
||||||
|
if(remainder)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue