HDElectronics

Untitled

Oct 12th, 2020
1,095
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "dsk6713.h"
  2. #include "dsk6713_aic23.h"
  3.  
  4. volatile int data_in_Codec;
  5.  
  6. short input_buffer[N] = {0}; //to store input samples...same as x
  7. float output_buffer[7] = {0}; //to store magnitude of FFT
  8. short buffer_count, i, J;
  9. short nFlag; //indicator to begin FFT
  10. short nRow, nColumn;
  11. double delta;
  12. float tempvalue;
  13.  
  14. interrupt void c_int11(){
  15.   input_buffer[buffer_count] = data_in_Codec;
  16.   output_sample((short)input_buffer[buffer_count++]);
  17.   if(buffer_count >= N) //if accum more than N points->begin FFT
  18.   {
  19.     buffer_count = 0; //reset buffer_count
  20.     nFlag = 0; //flag to signal completion
  21.     for(i = 0; i < N; i++)
  22.     {
  23.       x[2*i] = (float)input_buffer[i]; //real part of input
  24.       x[2*i+1] = 0; //imaginary part of input
  25.     }
  26.   }
  27. }
  28.  
  29. int main(void) {
  30.   DSK6713_AIC23_setFreq(hCodec, DSK6713_FREQ_48KHZ);
  31.   DSK6713_AIC23_Config config = {
  32.     0x0017, /* 0 DSK6713_AIC23_LEFTINVOL Left line input channel volume */
  33.     0x0017, /* 1 DSK6713_AIC23_RIGHTINVOL Right line input channel volume */
  34.     0x01f9, /* 2 DSK6713_AIC23_LEFTHPVOL Left channel headphone volume */
  35.     0x01f9, /* 3 DSK6713_AIC23_RIGHTHPVOL Right channel headphone volume */
  36.     0x0011, /* 4 DSK6713_AIC23_ANAPATH Analog audio path control */
  37.     0x0000, /* 5 DSK6713_AIC23_DIGPATH Digital audio path control */
  38.     0x0000, /* 6 DSK6713_AIC23_POWERDOWN Power down control */
  39.     0x0043, /* 7 DSK6713_AIC23_DIGIF Digital audio interface format */
  40.     0x0081, /* 8 DSK6713_AIC23_SAMPLERATE Sample rate control */
  41.     0x0001 /* 9 DSK6713_AIC23_DIGACT Digital interface activation */
  42.   };
  43.   // Open codec with default settings
  44.   DSK6713_AIC23_CodecHandle hCodec;
  45.   hCodec = DSK6713_AIC23_openCodec(0, &config);
  46.   // Close codec
  47.   DSK6713_AIC23_closeCodec(hCodec);
  48.  
  49.   // Read the data from microphone
  50.   data_in_Codec = DSK6713_AIC23_read();
  51.  
  52.   nFlag = 1;
  53.   buffer_count = 0;
  54.   //generate twiddle constants, then index for digit reversal
  55.   comm_intr();
  56.  
  57.   while(1) //infinite loop
  58.   {
  59.     while(nFlag); //wait for ISR to finish buffer accum samples
  60.     nFlag = 1;
  61.     //call radix-4 FFT, then digit reverse function
  62.     output_buffer[0]=(float) sqrt(x[2*22]*x[2*22]+x[2*22+1]*x[2*22+1]);
  63.     //for weigths 25,28,31,39,43
  64.     output_buffer[6]=(float) sqrt(x[2*47]*x[2*47]+x[2*47+1]*x[2*47+1]);
  65.     tempvalue = 0; //choose largest row frequency
  66.     nRow = 0;
  67.     for(j = 0; j < 4; j++)
  68.     {
  69.       if(tempvalue < output_buffer[j])
  70.       {
  71.         if(output_buffer[j] > 0.5e4)
  72.         {
  73.           nRow = j + 1;
  74.           tempvalue = output_buffer[j];
  75.         }
  76.       }
  77.     } //end of for loop
  78.     tempvalue = 0; //choose largest column frequency
  79.     nColumn = 0;
  80.     for(j = 4; j < 7; j++) nColumn = j - 3; //as with the rows
  81.     //end of for loop
  82.     if((nRow != 0) && (nColumn != 0))
  83.     {
  84.       if((nRow==1)&&(nColumn==1)) //for button 0001 ("1")
  85.         {DSK6713_LED_off(0);DSK6713_LED_off(1);DSK6713_LED_off(2);DSK6713_LED_on(3);}
  86.       if((nRow==1)&&(nColumn==2)) //for button 0010
  87.         {DSK6713_LED_off(0);DSK6713_LED_off(1);DSK6713_LED_on(2);DSK6713_LED_off(3);}
  88.         //for button "3", "4", ..., "#"
  89.     }
  90.     else
  91.       {DSK6713_LED_off(0);DSK6713_LED_off(1);DSK6713_LED_off(2);DSK6713_LED_off(3);}
  92.   }  //end of while (1) infinite loop
  93. }
  94.  
RAW Paste Data