Quisk version 4.2.43
This commit is contained in:
+35
-27
@@ -2,60 +2,68 @@
|
||||
|
||||
#include <Python.h>
|
||||
#include <stdlib.h>
|
||||
#include <complex.h>
|
||||
|
||||
#define CLIP32 2147483647
|
||||
#define CLIP16 32767
|
||||
|
||||
#define MAX_CHANNELS 32
|
||||
#define SAMPLE_BYTES (sizeof(double) * 2)
|
||||
|
||||
static struct _channel {
|
||||
double * cBuf; // save samples until nBuf reaches in_size
|
||||
int sizeBuf; // current size of cBuf in count of complex samples
|
||||
int nBuf; // current number of complex samples in cBuf
|
||||
int in_size; // count of complex samples needed for wdsp_fexchange0
|
||||
int in_use; // is this channel being used?
|
||||
complex double * cBuf; // circular sample buffer; save samples until nBuf reaches in_size
|
||||
int sizeBuf; // current size of cBuf in complex samples; a multiple of in_size
|
||||
int nBuf; // current number of complex samples in cBuf
|
||||
int in_size; // count of complex samples needed for wdsp_fexchange0
|
||||
int in_use; // is this channel being used?
|
||||
int Windex; // index of write
|
||||
int Rindex; // index of read
|
||||
} wdspChannel[MAX_CHANNELS];
|
||||
|
||||
static void (*wdsp_fexchange0) (int channel, double * in, double * out, int * error);
|
||||
|
||||
int wdspFexchange0(int channel, double * cSamples, int nSamples)
|
||||
int wdspFexchange0(int channel, complex double * cSamples, int nSamples)
|
||||
{
|
||||
// Call with an arbitrary number of input samples nSamples. cSamples is scaled to CLIP32.
|
||||
// When we have enough samples process the samples by calling wdsp. Return the samples in the same array.
|
||||
// cSamples is complex double. We treat it as interleaved Real/Imag doubles twice as long.
|
||||
// nSamples is the count of complex samples.
|
||||
// When we have enough samples process the samples by calling wdsp. Return the samples in cSamples.
|
||||
// cSamples is complex double. nSamples is the count of complex samples.
|
||||
struct _channel * ptChannel = wdspChannel + channel;
|
||||
int i, error;
|
||||
double * ptD, * ptS;
|
||||
int i, error, in_size;
|
||||
|
||||
if ( ! ptChannel->in_use)
|
||||
if ( ! ptChannel->in_use) {
|
||||
ptChannel->Windex = 0;
|
||||
ptChannel->Rindex = 0;
|
||||
ptChannel->nBuf = 0;
|
||||
return nSamples;
|
||||
}
|
||||
if ( ! wdsp_fexchange0)
|
||||
return nSamples;
|
||||
if (nSamples <= 0)
|
||||
return nSamples;
|
||||
if (ptChannel->nBuf + nSamples >= ptChannel->sizeBuf) {
|
||||
ptChannel->sizeBuf = ptChannel->nBuf + nSamples * 3;
|
||||
ptChannel->cBuf = (double *)realloc(ptChannel->cBuf, ptChannel->sizeBuf * SAMPLE_BYTES);
|
||||
in_size = ptChannel->in_size;
|
||||
i = nSamples / in_size + 3; // blocks need for samples plus a partial block
|
||||
if (i * in_size > ptChannel->sizeBuf) {
|
||||
i *= in_size;
|
||||
ptChannel->sizeBuf = i;
|
||||
ptChannel->cBuf = (complex double *)realloc(ptChannel->cBuf, i * sizeof(complex double));
|
||||
}
|
||||
ptS = cSamples; // Copy samples from cSamples to cBuf
|
||||
ptD = ptChannel->cBuf + ptChannel->nBuf * 2;
|
||||
for (i = 0; i < nSamples; i++) {
|
||||
*ptD++ = *ptS++ / CLIP32;
|
||||
*ptD++ = *ptS++ / CLIP32;
|
||||
for (i = 0; i < nSamples; i++) { // Copy samples from cSamples to cBuf
|
||||
ptChannel->cBuf[ptChannel->Windex++] = cSamples[i] / CLIP32;
|
||||
if (ptChannel->Windex >= ptChannel->sizeBuf)
|
||||
ptChannel->Windex = 0;
|
||||
}
|
||||
ptChannel->nBuf += nSamples;
|
||||
nSamples = 0;
|
||||
while (ptChannel->nBuf >= ptChannel->in_size) {
|
||||
(*wdsp_fexchange0)(channel, ptChannel->cBuf, cSamples + nSamples * 2, &error);
|
||||
while (ptChannel->nBuf >= in_size) {
|
||||
(*wdsp_fexchange0)(channel, (double *)(ptChannel->cBuf + ptChannel->Rindex), (double *)(cSamples + nSamples), &error);
|
||||
if (error)
|
||||
printf("WDSP: wdsp_fexchange0 error %d\n", error);
|
||||
nSamples += ptChannel->in_size;
|
||||
ptChannel->nBuf -= ptChannel->in_size;
|
||||
memmove(ptChannel->cBuf, ptChannel->cBuf + ptChannel->in_size * 2, ptChannel->nBuf * SAMPLE_BYTES);
|
||||
ptChannel->Rindex += in_size;
|
||||
if (ptChannel->Rindex >= ptChannel->sizeBuf)
|
||||
ptChannel->Rindex = 0;
|
||||
nSamples += in_size;
|
||||
ptChannel->nBuf -= in_size;
|
||||
}
|
||||
for (i = 0; i < nSamples * 2; i++)
|
||||
for (i = 0; i < nSamples; i++)
|
||||
cSamples[i] *= CLIP32;
|
||||
return nSamples;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user