La reproducción simple de audio con FFT no funciona (dsPic33F)

1

Escribí una aplicación de audio de reproducción simple (hablas en el micrófono, se reproduce en los altavoces, solo para probar), funciona. Sin embargo, cuando agregué una FFT + FFT inversa, no es así, solo escucho una reacción sin ruido cuando hablo en el micrófono.

Por favor, ¿alguien ve un error?

#include<ADCChannelDrv.h>
#include<OCPWMDrv.h>
#include<sask.h>
#include<ex_sask_led.h>
#include<ex_sask_generic.h>
#include<dsp.h>


int AdcBuffer[ ADC_CHANNEL_DMA_BUFSIZE ] __attribute__((space(dma)));
int DacBuffer[ OCPWM_DMA_BUFSIZE ] __attribute__((space(dma)));

int main(void) {
ex_sask_init();

fractcomplex Frame[ 128 ];
fractional Output[ 128 ];
fractcomplex twiddleFactors[128/2];


/* FFT config */
int i = 0;
fractional *p_real;
fractcomplex *p_cmpx;

TwidFactorInit (7, &twiddleFactors[0], 0);  /* We need to do this only once at start-up */






/* Instantiate the drivers  */
ADCChannelHandle adcChannelHandle;
OCPWMHandle     ocPWMHandle;

/* Create the driver handles    */
ADCChannelHandle *MyADCHandle   = &adcChannelHandle;
OCPWMHandle     *MyDACHandle        = &ocPWMHandle;

ADCChannelInit (MyADCHandle, AdcBuffer);
OCPWMInit (MyDACHandle, DacBuffer);
ADCChannelStart(MyADCHandle);
OCPWMStart(MyDACHandle);

while (1) {
while (ADCChannelIsBusy(MyADCHandle));
ADCChannelRead  (MyADCHandle, (fractional*)Frame, ADC_BUFFER_SIZE);

p_real = &Frame[0].real ;
p_cmpx = &Frame[0] ;


for ( i = 0; i < 128; i++ )/* The FFT function requires input data */
{                   /* to be in the fractional fixed-point range [-0.5, +0.5]*/
        *p_real = *p_real >>1 ;     /* So, we shift all data samples by 1 bit to the right. */
        *p_real++;          /* Should you desire to optimize this process, perform */
}                   /* data scaling when first obtaining the time samples */
                        /* Or within the BitReverseComplex function source code */

p_real = &Frame[(128/2)-1].real ;   /* Set up pointers to convert real array */
p_cmpx = &Frame[128-1] ; /* to a complex array. The input array initially has all */
                        /* the real input samples followed by a series of zeros */


for ( i = 128; i > 0; i-- ) /* Convert the Real input sample array */
{                   /* to a Complex input sample array  */
        (*p_cmpx).real = (*p_real--);   /* We will simpy zero out the imaginary  */
        (*p_cmpx--).imag = 0x0000;  /* part of each data sample */
}





FFTComplexIP (7, &Frame[0], &twiddleFactors[0], COEFFS_IN_DATA);
IFFTComplexIP (7, &Frame[0], &twiddleFactors[0], COEFFS_IN_DATA);


for ( i = 0; i < 128; i++ )  /*Convert back */
{
        Output[i]=Frame[i].real;
}


OCPWMWrite  (MyDACHandle,Output, OCPWM_FRAME_SIZE);

}
return 0;
}
    
pregunta user40200

0 respuestas

Lea otras preguntas en las etiquetas