Skip to content

Commit

Permalink
Various fixes for R8Brain resampler wrapper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
kode54 committed Mar 5, 2022
1 parent e1fa8d1 commit ed0f7d8
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions Audio/ThirdParty/r8bstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -53,6 +56,7 @@ struct r8bstate {
}
remainder -= blockCount;
output += channelCount * blockCount;
outProcessed += blockCount;
outMax -= blockCount;
ret += blockCount;
if(!outMax)
Expand All @@ -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;
}
Expand All @@ -103,6 +109,7 @@ struct r8bstate {
}
remainder -= blockCount;
output += channelCount * blockCount;
outProcessed += blockCount;
outMax -= blockCount;
ret += blockCount;
if(!outMax)
Expand All @@ -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;
}
Expand Down

0 comments on commit ed0f7d8

Please sign in to comment.