add stride

This commit is contained in:
Glenn Maynard
2004-01-14 08:24:08 +00:00
parent 431917de92
commit d4fb83773b
5 changed files with 58 additions and 16 deletions
Binary file not shown.
@@ -35,6 +35,16 @@ int resample_process(void *handle,
float *outBuffer,
int outBufferLen);
int resample_process_stride(void *handle,
double factor,
float *inBuffer,
int inBufferLen,
int lastFlag,
int *inBufferUsed,
float *outBuffer,
int outBufferLen,
int BufferStride);
void resample_close(void *handle);
#ifdef __cplusplus
+1
View File
@@ -3,4 +3,5 @@ EXPORTS
resample_dup
resample_get_filter_width
resample_process
resample_process_stride
resample_close
Binary file not shown.
+47 -16
View File
@@ -175,6 +175,21 @@ int resample_process(void *handle,
int *inBufferUsed, /* output param */
float *outBuffer,
int outBufferLen)
{
return resample_process_stride( handle,
factor,inBuffer, inBufferLen,
lastFlag, inBufferUsed, outBuffer, outBufferLen, 1);
}
int resample_process_stride(void *handle,
double factor,
float *inBuffer,
int inBufferLen,
int lastFlag,
int *inBufferUsed, /* output param */
float *outBuffer,
int outBufferLen,
int BufferStride)
{
rsdata *hp = (rsdata *)handle;
float *Imp = hp->Imp;
@@ -182,18 +197,19 @@ int resample_process(void *handle,
float LpScl = hp->LpScl;
UWORD Nwing = hp->Nwing;
BOOL interpFilt = FALSE; /* TRUE means interpolate filter coeffs */
int outSampleCount;
int inSampleCount, outSampleCount;
UWORD Nout, Ncreep, Nreuse;
int Nx;
int i, len;
#if DEBUG
fprintf(stderr, "resample_process: in=%d, out=%d lastFlag=%d\n",
inBufferLen, outBufferLen, lastFlag);
fprintf(stderr, "resample_process: in=%d, out=%d stride=%d lastFlag=%d\n",
inBufferLen, outBufferLen, lastFlag, 1);
#endif
/* Initialize inBufferUsed and outSampleCount to 0 */
*inBufferUsed = 0;
inSampleCount = 0;
outSampleCount = 0;
if (factor < hp->minFactor || factor > hp->maxFactor) {
@@ -208,11 +224,16 @@ int resample_process(void *handle,
/* Start by copying any samples still in the Y buffer to the output
buffer */
if (hp->Yp && (outBufferLen-outSampleCount)>0) {
len = MIN(outBufferLen-outSampleCount, hp->Yp);
if (hp->Yp && outBufferLen>0) {
len = MIN(outBufferLen/BufferStride, hp->Yp); // in samples
for(i=0; i<len; i++)
outBuffer[outSampleCount+i] = hp->Y[i];
outSampleCount += len;
{
*outBuffer = hp->Y[i];
outBuffer += BufferStride;
}
outSampleCount += len*BufferStride;
outBufferLen -= len*BufferStride;
for(i=0; i<hp->Yp-len; i++)
hp->Y[i] = hp->Y[i+len];
hp->Yp -= len;
@@ -240,16 +261,20 @@ int resample_process(void *handle,
/* Copy as many samples as we can from the input buffer into X */
len = hp->XSize - hp->Xread;
if (len >= (inBufferLen - (*inBufferUsed)))
len = (inBufferLen - (*inBufferUsed));
if (len >= inBufferLen/BufferStride)
len = inBufferLen/BufferStride;
for(i=0; i<len; i++)
hp->X[hp->Xread + i] = inBuffer[(*inBufferUsed) + i];
{
hp->X[hp->Xread + i] = *inBuffer;
inBuffer += BufferStride;
}
*inBufferUsed += len;
inSampleCount += len*BufferStride;
inBufferLen -= len*BufferStride;
hp->Xread += len;
if (lastFlag && (*inBufferUsed == inBufferLen)) {
if (lastFlag && (inSampleCount == inBufferLen)) {
/* If these are the last samples, zero-pad the
end of the input buffer and make sure we process
all the way to the end */
@@ -316,11 +341,16 @@ int resample_process(void *handle,
hp->Yp = Nout;
/* Copy as many samples as possible to the output buffer */
if (hp->Yp && (outBufferLen-outSampleCount)>0) {
len = MIN(outBufferLen-outSampleCount, hp->Yp);
if (hp->Yp && outBufferLen>0) {
len = MIN(outBufferLen/BufferStride, hp->Yp);
for(i=0; i<len; i++)
outBuffer[outSampleCount+i] = hp->Y[i];
outSampleCount += len;
{
*outBuffer = hp->Y[i];
outBuffer += BufferStride;
}
outSampleCount += len*BufferStride;
outBufferLen -= len*BufferStride;
for(i=0; i<hp->Yp-len; i++)
hp->Y[i] = hp->Y[i+len];
hp->Yp -= len;
@@ -332,6 +362,7 @@ int resample_process(void *handle,
break;
}
*inBufferUsed = inSampleCount;
return outSampleCount;
}