📄 spectrum_analyser.c
字号:
/* Result greater than or equal power_spectrum[i]*/
}
}
return ( result );
}
/*****************************************************************************/
/* */
/* For compatibility with pcm3002 read / write, these variables must */
/* be declared as Int16 or short int, rather than int. */
/* */
/*****************************************************************************/
Int16 left_input;
Int16 left_output;
Int16 right_input;
Int16 right_output;
Int16 mono_input;
/*****************************************************************************/
/* UserTask() */
/*---------------------------------------------------------------------------*/
/* */
/* The main user task. */
/* */
/* Note that this task is not called by main(). It is scheduled by DSP/BIOS */
/* */
/*****************************************************************************/
void UserTask()
{
DSK5416_PCM3002_CodecHandle hCodec;
long i;
unsigned int j;
unsigned int switch_value;
unsigned int temp;
/* Start the codec */
hCodec = DSK5416_PCM3002_openCodec(0, &setup);
/* Display project details on StdOut. \n is important. */
puts("TMS320C5416 DSK: Fast Fourier Transform to determine power spectrum of signal.\n");
buffers_initialize();
for ( i = 0 ; i < 12000000 ; i++ )
{
/* Read input multiple times and put into receive buffer */
for ( j = 0 ; j < N ; j++)
{
/* Read left input channel */
while (!DSK5416_PCM3002_read16(hCodec, &left_input));
/* Output to left output channel */
while (!DSK5416_PCM3002_write16(hCodec, left_output));
/* Read right input channel */
while (!DSK5416_PCM3002_read16(hCodec, &right_input));
/* Output to right output channel */
while (!DSK5416_PCM3002_write16(hCodec, right_output));
/* Read user switches on DSK and display their meaning on Stdout. */
switch_value = switch_status_display();
/* Copy inputs straight to outputs */
left_output = left_input;
right_output = right_input;
/* Generate mono signal from two input signals */
mono_input = stereo_to_mono(left_input, right_input);
/* Read next value into straight buffer */
shuffle_and_read (mono_input);
}
/* Copy input samples from receive buffer to y[] */
copy_input_to_complex();
/* Perforn FFT for specified number of points */
FFT( y, N );
/* Determine power of outputs in y[] */
calculate_output_power( y, &power_spectrum[0]);
if ( 0 == switch_value)
{
/* Use largest power spectrum to indicate output of CD player */
temp = calculate_maximum_output_power();
/* Display on bargraph */
bargraph_6dB ( temp, temp );
}
else if ( 1 == switch_value)
{
/* Display lowest frequency components */
spectrum_analyser_display( power_spectrum[1], power_spectrum[2],
power_spectrum[3], power_spectrum[4] );
}
else if ( 2 == switch_value)
{
/* Display lowest frequency components */
spectrum_analyser_display( power_spectrum[5], power_spectrum[6],
power_spectrum[7], power_spectrum[8] );
}
else if ( 3 == switch_value)
{
/* Display lowest frequency components */
spectrum_analyser_display( power_spectrum[9], power_spectrum[10],
power_spectrum[11], power_spectrum[12] );
}
else if ( 4 == switch_value)
{
bargraph_3dB ( power_spectrum[1], power_spectrum[1] );
}
else if ( 5 == switch_value)
{
bargraph_3dB ( power_spectrum[2], power_spectrum[2] );
}
else if ( 6 == switch_value)
{
bargraph_3dB ( power_spectrum[3], power_spectrum[3] );
}
else if ( 7 == switch_value)
{
bargraph_3dB ( power_spectrum[4], power_spectrum[4] );
}
else if ( 8 == switch_value)
{
bargraph_3dB ( power_spectrum[5], power_spectrum[5] );
}
else if ( 9 == switch_value)
{
bargraph_3dB ( power_spectrum[6], power_spectrum[6] );
}
else if ( 10 == switch_value)
{
bargraph_3dB ( power_spectrum[7], power_spectrum[7] );
}
else if ( 11 == switch_value)
{
bargraph_3dB ( power_spectrum[8], power_spectrum[8] );
}
else if ( 12 == switch_value)
{
bargraph_3dB ( power_spectrum[9], power_spectrum[9] );
}
else if ( 13 == switch_value)
{
bargraph_3dB ( power_spectrum[10], power_spectrum[10] );
}
else if ( 14 == switch_value)
{
bargraph_3dB ( power_spectrum[11], power_spectrum[11] );
}
else if ( 15 == switch_value)
{
bargraph_3dB ( power_spectrum[12], power_spectrum[12] );
}
}
/* Finished processing. Close the codec */
DSK5416_PCM3002_closeCodec(hCodec);
puts("TMS320C5416 DSK has terminated\n");
}
/*****************************************************************************/
/* main() */
/*****************************************************************************/
void main()
{
/* Initialize the board support library */
/* There is no need to initialize the DIP switches and the LEDs */
DSK5416_init();
/* All other functions are scheduled by DSP/BIOS */
}
/******************************************************************************/
/* End of spectrum_analyser.c */
/******************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -