Hello matt.
Thanks again for the reply. Really appreciate it. Well… this problem is solved now!. I just removed the cutil.lib from the Linker’s input completely and included cuda.h in my source code and it worked. Now its working in Ableton Live as well.! All good so far.
What I m trying to do now is use the CUFFT library to convert from amplitude to frequency and vice versa. But I can’t understand some of the results I m getting back.
What I do first is copy the audio input array to the CUDA device and then to a cufftReal type variable. Here is some code :
[codebox]
extern “C” void
runTest(float* inL, float* inR, float* outL, float* outR, float Fc, unsigned int len)
{
cudaSetDevice( cutGetMaxGflopsDeviceId() );
const unsigned int numThreadsPerBlock = 100;
const unsigned int numBlocks = len / numThreadsPerBlock;
const unsigned int mem_size = sizeof(float) * len;
// allocate device memory
float* LEFT_IN;
cutilSafeCall(cudaMalloc((void**) &LEFT_IN, mem_size));
float* RIGHT_IN;
cutilSafeCall(cudaMalloc((void**) &RIGHT_IN, mem_size));
float* LEFT_OUT;
cutilSafeCall(cudaMalloc((void**) &LEFT_OUT, mem_size));
float* RIGHT_OUT;
cutilSafeCall(cudaMalloc((void**) &RIGHT_OUT, mem_size));
// copy host memory to device
cutilSafeCall(cudaMemcpy(LEFT_IN, inL, mem_size, // copy the audio input to a local variable
cudaMemcpyHostToDevice) );
cutilSafeCall(cudaMemcpy(RIGHT_IN, inR, mem_size,
cudaMemcpyHostToDevice) );
cufftHandle plan, plan2, plan3, plan4, plan5, plan6;
cufftReal* REAL_DATA_L;
cufftReal* REAL_DATA_R;
cufftComplex* COMPLEX_DATA, *COMPLEX_DATA2;
float *w_L, *w_R, *GAIN_L, *GAIN_R;
cutilSafeCall(cudaMalloc((void**) &w_L, mem_size));
cutilSafeCall(cudaMalloc((void**) &w_R, mem_size));
cutilSafeCall(cudaMalloc((void**) &GAIN_L, mem_size));
cutilSafeCall(cudaMalloc((void**) &GAIN_R, mem_size));
cutilSafeCall(cudaMalloc((void**) &REAL_DATA_L, mem_size));
cutilSafeCall(cudaMalloc((void**) &REAL_DATA_R, mem_size));
cutilSafeCall(cudaMalloc((void**)&COMPLEX_DATA, sizeof(cufftComplex)*len));
cutilSafeCall(cudaMalloc((void**)&COMPLEX_DATA2, sizeof(cufftComplex)*len));
for(int i = 0;i < len; i++)
{
REAL_DATA_L[i] = LEFT_IN[i]; // copy the audio input to the cufftReal type variable to pass to
// the FFT.
REAL_DATA_R[i] = RIGHT_IN[i];
}
int BATCH = len / numThreadsPerBlock;
cufftPlan1d(&plan, numThreadsPerBlock, CUFFT_R2C, BATCH);
cufftPlan1d(&plan2, numThreadsPerBlock, CUFFT_R2C, BATCH);
cufftExecR2C(plan, REAL_DATA_L, COMPLEX_DATA);
cufftExecR2C(plan2, REAL_DATA_R, COMPLEX_DATA2);
cufftPlan1d(&plan3, numThreadsPerBlock, CUFFT_C2C, BATCH);
cufftPlan1d(&plan4, numThreadsPerBlock, CUFFT_C2C, BATCH);
cufftExecC2C(plan3, COMPLEX_DATA, COMPLEX_DATA, CUFFT_FORWARD);
cufftExecC2C(plan4, COMPLEX_DATA2, COMPLEX_DATA2, CUFFT_FORWARD);
cufftPlan1d(&plan5, numThreadsPerBlock, CUFFT_C2R, BATCH);
cufftPlan1d(&plan6, numThreadsPerBlock, CUFFT_C2R, BATCH);
cufftExecC2R(plan5, COMPLEX_DATA, REAL_DATA_L);
cufftExecC2R(plan6, COMPLEX_DATA2, REAL_DATA_R);
float RC = 1 / 2 * PI * (Fc*20000.f); // RC is actually Resistance * Capacitance
// I've change d here the formula from Fc = 1 / 2*pi*R*C to
// to calculate R*C with a given cut-off frequency
for(int i = 0; i < len; i++)
{
w_L[i] = 2 / PI * REAL_DATA_L[i]; // Calculating angular frequency
w_R[i] = 2 / PI * REAL_DATA_R[i];
GAIN_L[i] = 1 / sqrt(1 + (pow(w_L[i] * RC, 2))); // Calculating gain of the signal according to cut-off freq
GAIN_R[i] = 1 / sqrt(1 + (pow(w_R[i] * RC, 2)));
}
cutilSafeCall(cudaMemcpy(outL, GAIN_L, mem_size, // Copy the gain array to the host to multiply with audio input
cudaMemcpyDeviceToHost)); // in processReplacing() VST function
cutilSafeCall(cudaMemcpy(outR, GAIN_R, mem_size,
cudaMemcpyDeviceToHost));
[/codebox]
So this is the part where I use cufft in the .cu file. I hope I didn’t miss anything as I copied and pasted parts of the code and not all of it. SO…the problem here is that I m getting half positive and half negative values from the FFT. From what I know so far a forward FFT will return an array of frequencies if you pass an array of amplitudes for an argument. SO… Iwas expecting to get that frequency array after I executed this :
[codebox]
cufftExecC2C(plan, COMPLEX_DATA, COMPLEX_DATA, CUFFT_FORWARD);
cufftExecC2R(plan, COMPLEX_DATA, REAL_DATA_L);
[/codebox]
What I think I should be getting is an array of frequencies. Right? I might be completely wrong. Honestly. I m still a bit confused with the Fourrier transforms, so please correct if i’m wrong. But what I get in the real data array at the end is something like this :
[codebox]
36.8230
-38902923
122.5556
-7.77028 // these are printed elements of the real data array
124.6875
-95.4375
343,985
-1.083464
etc etc etc
[/codebox]
Could somebody please help me out with this? What do I need to do to get the frequency array??
Cheers