add stride
This commit is contained in:
Binary file not shown.
@@ -35,6 +35,16 @@ int resample_process(void *handle,
|
|||||||
float *outBuffer,
|
float *outBuffer,
|
||||||
int outBufferLen);
|
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);
|
void resample_close(void *handle);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
@@ -3,4 +3,5 @@ EXPORTS
|
|||||||
resample_dup
|
resample_dup
|
||||||
resample_get_filter_width
|
resample_get_filter_width
|
||||||
resample_process
|
resample_process
|
||||||
|
resample_process_stride
|
||||||
resample_close
|
resample_close
|
||||||
|
|||||||
Binary file not shown.
@@ -175,6 +175,21 @@ int resample_process(void *handle,
|
|||||||
int *inBufferUsed, /* output param */
|
int *inBufferUsed, /* output param */
|
||||||
float *outBuffer,
|
float *outBuffer,
|
||||||
int outBufferLen)
|
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;
|
rsdata *hp = (rsdata *)handle;
|
||||||
float *Imp = hp->Imp;
|
float *Imp = hp->Imp;
|
||||||
@@ -182,18 +197,19 @@ int resample_process(void *handle,
|
|||||||
float LpScl = hp->LpScl;
|
float LpScl = hp->LpScl;
|
||||||
UWORD Nwing = hp->Nwing;
|
UWORD Nwing = hp->Nwing;
|
||||||
BOOL interpFilt = FALSE; /* TRUE means interpolate filter coeffs */
|
BOOL interpFilt = FALSE; /* TRUE means interpolate filter coeffs */
|
||||||
int outSampleCount;
|
int inSampleCount, outSampleCount;
|
||||||
UWORD Nout, Ncreep, Nreuse;
|
UWORD Nout, Ncreep, Nreuse;
|
||||||
int Nx;
|
int Nx;
|
||||||
int i, len;
|
int i, len;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
fprintf(stderr, "resample_process: in=%d, out=%d lastFlag=%d\n",
|
fprintf(stderr, "resample_process: in=%d, out=%d stride=%d lastFlag=%d\n",
|
||||||
inBufferLen, outBufferLen, lastFlag);
|
inBufferLen, outBufferLen, lastFlag, 1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize inBufferUsed and outSampleCount to 0 */
|
/* Initialize inBufferUsed and outSampleCount to 0 */
|
||||||
*inBufferUsed = 0;
|
*inBufferUsed = 0;
|
||||||
|
inSampleCount = 0;
|
||||||
outSampleCount = 0;
|
outSampleCount = 0;
|
||||||
|
|
||||||
if (factor < hp->minFactor || factor > hp->maxFactor) {
|
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
|
/* Start by copying any samples still in the Y buffer to the output
|
||||||
buffer */
|
buffer */
|
||||||
if (hp->Yp && (outBufferLen-outSampleCount)>0) {
|
if (hp->Yp && outBufferLen>0) {
|
||||||
len = MIN(outBufferLen-outSampleCount, hp->Yp);
|
len = MIN(outBufferLen/BufferStride, hp->Yp); // in samples
|
||||||
for(i=0; i<len; i++)
|
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++)
|
for(i=0; i<hp->Yp-len; i++)
|
||||||
hp->Y[i] = hp->Y[i+len];
|
hp->Y[i] = hp->Y[i+len];
|
||||||
hp->Yp -= 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 */
|
/* Copy as many samples as we can from the input buffer into X */
|
||||||
len = hp->XSize - hp->Xread;
|
len = hp->XSize - hp->Xread;
|
||||||
|
|
||||||
if (len >= (inBufferLen - (*inBufferUsed)))
|
if (len >= inBufferLen/BufferStride)
|
||||||
len = (inBufferLen - (*inBufferUsed));
|
len = inBufferLen/BufferStride;
|
||||||
|
|
||||||
for(i=0; i<len; i++)
|
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;
|
hp->Xread += len;
|
||||||
|
|
||||||
if (lastFlag && (*inBufferUsed == inBufferLen)) {
|
if (lastFlag && (inSampleCount == inBufferLen)) {
|
||||||
/* If these are the last samples, zero-pad the
|
/* If these are the last samples, zero-pad the
|
||||||
end of the input buffer and make sure we process
|
end of the input buffer and make sure we process
|
||||||
all the way to the end */
|
all the way to the end */
|
||||||
@@ -316,11 +341,16 @@ int resample_process(void *handle,
|
|||||||
hp->Yp = Nout;
|
hp->Yp = Nout;
|
||||||
|
|
||||||
/* Copy as many samples as possible to the output buffer */
|
/* Copy as many samples as possible to the output buffer */
|
||||||
if (hp->Yp && (outBufferLen-outSampleCount)>0) {
|
if (hp->Yp && outBufferLen>0) {
|
||||||
len = MIN(outBufferLen-outSampleCount, hp->Yp);
|
len = MIN(outBufferLen/BufferStride, hp->Yp);
|
||||||
for(i=0; i<len; i++)
|
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++)
|
for(i=0; i<hp->Yp-len; i++)
|
||||||
hp->Y[i] = hp->Y[i+len];
|
hp->Y[i] = hp->Y[i+len];
|
||||||
hp->Yp -= len;
|
hp->Yp -= len;
|
||||||
@@ -332,6 +362,7 @@ int resample_process(void *handle,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*inBufferUsed = inSampleCount;
|
||||||
return outSampleCount;
|
return outSampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user