Definition in file dsp_process.c.
#include "dsp_process.h"
#include "dsp.h"
#include "tpa6130.h"
#include "abdac.h"
#include "audio.h"
#include "conf_demo.h"
Go to the source code of this file.
Functions | |
void | audio_callback (U32 arg) |
void | dac_overrun_callback (void) |
void | dac_reload_callback (void) |
static void | dsp_calculate_fft (dsp16_t *fft, dsp16_t *signal) |
void | dsp_process_init (int cpu_hz, int hsb_hz, int pba_hz, int pbb_hz) |
void | dsp_process_task (void) |
const char * | filter_active_get_description () |
const char * | filter_get_description (unsigned int num) |
void | filter_restore_default () |
void | filter_set_active (unsigned int num) |
void | generate_signal (dsp16_t *signal, struct signal_source *source) |
unsigned int | signal_source_get_freq (struct signal_source *source) |
dsp16_t | signal_source_get_volume (struct signal_source *source) |
void | signal_source_init (struct signal_source *source, unsigned int frequency, dsp16_t volume) |
void | signal_source_restore_defaults (struct signal_source *source) |
void | signal_source_set_freq (struct signal_source *source, unsigned int frequency) |
void | signal_source_set_volume (struct signal_source *source, dsp16_t volume) |
Variables | |
unsigned int | active_filter |
dsp16_t * | current_stereo_out_buf |
static dsp16_t | fft_window [BUFFER_LENGTH] |
A_ALIGNED dsp16_t | filter_coef [NUM_FILTERS-1][FIR_NUM_COEF] |
const char * | filter_description [NUM_FILTERS] |
A_ALIGNED dsp16_t | signal1_buf [BUFFER_LENGTH] |
struct signal_source | signal1_generator |
A_ALIGNED dsp16_t | signal2_buf [BUFFER_LENGTH] |
struct signal_source | signal2_generator |
dsp16_t * | signal_in_buf |
A_ALIGNED dsp16_t | signal_in_fft [BUFFER_LENGTH] |
A_ALIGNED dsp16_t | signal_out_buf [BUFFER_LENGTH+4] |
A_ALIGNED dsp16_t | signal_out_fft [BUFFER_LENGTH] |
A_ALIGNED dsp16_t | signal_pre_filter_buf [FIR_NUM_COEF+BUFFER_LENGTH] |
bool | signals_are_updated |
dsp16_t | stereo_out_buf1 [BUFFER_LENGTH *2] |
dsp16_t | stereo_out_buf2 [BUFFER_LENGTH *2] |
void audio_callback | ( | U32 | arg | ) |
Definition at line 231 of file dsp_process.c.
References dac_overrun_callback(), and dac_reload_callback().
Referenced by dsp_process_init().
00232 { 00233 if( arg == AUDIO_DAC_OUT_OF_SAMPLE_CB ) 00234 { 00235 dac_overrun_callback(); 00236 } 00237 00238 else if( arg == AUDIO_DAC_RELOAD_CB ) 00239 { 00240 dac_reload_callback(); 00241 } 00242 00243 else if( arg == AUDIO_ADC_OUT_OF_SAMPLE_CB ) 00244 { 00245 } 00246 00247 else if( arg == AUDIO_ADC_RELOAD_CB ) 00248 { 00249 } 00250 }
void dac_overrun_callback | ( | void | ) |
void dac_reload_callback | ( | void | ) |
Definition at line 252 of file dsp_process.c.
References active_filter, BUFFER_LENGTH, current_stereo_out_buf, dsp16_filt_fir(), dsp16_vect_add_and_sat(), filter_coef, FIR_NUM_COEF, generate_signal(), signal1_buf, signal1_generator, signal2_buf, signal2_generator, signal_in_buf, signal_out_buf, signal_pre_filter_buf, signals_are_updated, stereo_out_buf1, and stereo_out_buf2.
Referenced by audio_callback(), and dsp_process_init().
00253 { 00254 int i; 00255 00256 if (current_stereo_out_buf == stereo_out_buf1) 00257 current_stereo_out_buf = stereo_out_buf2; 00258 else 00259 current_stereo_out_buf = stereo_out_buf1; 00260 00261 generate_signal(signal1_buf, &signal1_generator); 00262 generate_signal(signal2_buf, &signal2_generator); 00263 00264 /* In order for the FIR filter to work correctly we need to keep 00265 * the last part of the previous buffer */ 00266 for (i = 0; i < FIR_NUM_COEF; i++) { 00267 signal_pre_filter_buf[i] = 00268 signal_pre_filter_buf[BUFFER_LENGTH + i]; 00269 } 00270 00271 /* New data is put in the signal_in_buf which points behind the data 00272 * kept from the previous buffer */ 00273 dsp16_vect_add_and_sat(signal_in_buf, signal1_buf, signal2_buf, 00274 BUFFER_LENGTH); 00275 00276 /* Run the FIR filter; the input buffer will be ... longer then the 00277 * output buffer, which has normal length */ 00278 if (active_filter > 0) { 00279 dsp16_filt_fir(signal_out_buf, signal_pre_filter_buf, 00280 BUFFER_LENGTH + FIR_NUM_COEF - 1, 00281 filter_coef[active_filter - 1], FIR_NUM_COEF); 00282 } else { 00283 for (i = 0; i < BUFFER_LENGTH; i++) 00284 signal_out_buf[i] = signal_in_buf[i]; 00285 } 00286 00287 for (i = 0; i < BUFFER_LENGTH; i++) { 00288 current_stereo_out_buf[i*2] = signal_out_buf[i]; 00289 current_stereo_out_buf[i*2+1] = signal_out_buf[i]; 00290 } 00291 00292 signals_are_updated = 1; 00293 00294 /* Update PDCA buffer */ 00295 tpa6130_dac_output(current_stereo_out_buf, BUFFER_LENGTH); 00296 }
Definition at line 330 of file dsp_process.c.
References BUFFER_LENGTH, BUFFER_LENGTH_LOG, dsp16_trans_realcomplexfft(), dsp16_vect_complex_abs(), dsp16_vect_dotmul(), dsp16_vect_max(), dsp16_vect_realdiv(), FFT_LENGTH, and fft_window.
Referenced by dsp_process_task().
00331 { 00332 int i; 00333 dsp16_t max_value; 00334 dsp16_t temp[BUFFER_LENGTH]; 00335 dsp16_complex_t temp_res[BUFFER_LENGTH]; 00336 00337 dsp16_vect_dotmul(temp, signal, fft_window, BUFFER_LENGTH); 00338 dsp16_trans_realcomplexfft(temp_res, temp, BUFFER_LENGTH_LOG); 00339 dsp16_vect_complex_abs(fft, temp_res, BUFFER_LENGTH); 00340 00341 for (i = 0; i < FFT_LENGTH; i++) 00342 fft[i] += fft[BUFFER_LENGTH - i - 1]; 00343 00344 max_value = dsp16_vect_max(fft, FFT_LENGTH); 00345 dsp16_vect_realdiv(fft, fft, FFT_LENGTH, max_value + 1); 00346 }
void dsp_process_init | ( | int | cpu_hz, | |
int | hsb_hz, | |||
int | pba_hz, | |||
int | pbb_hz | |||
) |
Definition at line 303 of file dsp_process.c.
References audio_callback(), BUFFER_LENGTH, current_stereo_out_buf, DAC_BITS_PER_SAMPLE, DAC_NUM_CHANNELS, dac_reload_callback(), DAC_SAMPLING_RATE, DAC_SWAP_CHANNELS, dsp16_win_hamm(), fft_window, filter_restore_default(), FIR_NUM_COEF, signal1_generator, signal2_generator, signal_in_buf, signal_pre_filter_buf, signal_source_init(), and stereo_out_buf1.
Referenced by main().
00304 { 00305 // Initialize TPA6130 00306 tpa6130_init(); 00307 00308 // Initialize DAC that send audio to TPA6130 00309 tpa6130_dac_start(DAC_SAMPLING_RATE, DAC_NUM_CHANNELS, 00310 DAC_BITS_PER_SAMPLE, DAC_SWAP_CHANNELS, 00311 audio_callback, AUDIO_DAC_RELOAD_CB, 00312 FOSC0); 00313 00314 tpa6130_set_volume(0x20); 00315 tpa6130_get_volume(); 00316 00317 signal_source_init(&signal1_generator, 433, 20000); 00318 signal_source_init(&signal2_generator, 2000, 10000); 00319 00320 current_stereo_out_buf = stereo_out_buf1; 00321 signal_in_buf = signal_pre_filter_buf + FIR_NUM_COEF; 00322 filter_restore_default(); 00323 00324 dsp16_win_hamm(fft_window, BUFFER_LENGTH); 00325 00326 /* Run the interrupt handler manually once to start the ABDAC */ 00327 dac_reload_callback(); 00328 }
void dsp_process_task | ( | void | ) |
Definition at line 348 of file dsp_process.c.
References dsp_calculate_fft(), signal_in_buf, signal_in_fft, signal_out_buf, and signal_out_fft.
Referenced by main().
00349 { 00350 dsp_calculate_fft(signal_in_fft, signal_in_buf); 00351 dsp_calculate_fft(signal_out_fft, signal_out_buf); 00352 }
const char* filter_active_get_description | ( | ) |
Definition at line 226 of file dsp_process.c.
References active_filter, and filter_get_description().
Referenced by main(), state_machine_filter(), and state_machine_task().
00227 { 00228 return filter_get_description(active_filter); 00229 }
const char* filter_get_description | ( | unsigned int | num | ) |
Definition at line 218 of file dsp_process.c.
References filter_description, and NUM_FILTERS.
Referenced by filter_active_get_description().
00219 { 00220 if (num >= NUM_FILTERS) 00221 return ""; 00222 00223 return filter_description[num]; 00224 }
void filter_restore_default | ( | ) |
Definition at line 213 of file dsp_process.c.
References active_filter.
Referenced by dsp_process_init().
00214 { 00215 active_filter = 0; 00216 }
void filter_set_active | ( | unsigned int | num | ) |
Definition at line 205 of file dsp_process.c.
References active_filter, and NUM_FILTERS.
Referenced by state_machine_filter().
00206 { 00207 if (num >= NUM_FILTERS) 00208 active_filter = 0; 00209 00210 active_filter = num; 00211 }
void generate_signal | ( | dsp16_t * | signal, | |
struct signal_source * | source | |||
) |
Definition at line 198 of file dsp_process.c.
References BUFFER_LENGTH, DAC_SAMPLING_RATE, dsp16_gen_sin(), dsp16_vect_realmul(), signal_source::frequency, signal_source::phase, and signal_source::volume.
Referenced by dac_reload_callback().
00199 { 00200 source->phase = dsp16_gen_sin(signal, BUFFER_LENGTH, 00201 source->frequency, DAC_SAMPLING_RATE, source->phase); 00202 dsp16_vect_realmul(signal, signal, BUFFER_LENGTH, source->volume); 00203 }
unsigned int signal_source_get_freq | ( | struct signal_source * | source | ) |
Definition at line 162 of file dsp_process.c.
References signal_source::frequency.
Referenced by state_machine_source().
00163 { 00164 return source->frequency; 00165 }
dsp16_t signal_source_get_volume | ( | struct signal_source * | source | ) |
Definition at line 175 of file dsp_process.c.
References signal_source::volume.
Referenced by state_machine_source().
00176 { 00177 return source->volume; 00178 }
void signal_source_init | ( | struct signal_source * | source, | |
unsigned int | frequency, | |||
dsp16_t | volume | |||
) |
Definition at line 186 of file dsp_process.c.
References signal_source::default_freq, signal_source::default_volume, and signal_source_restore_defaults().
Referenced by dsp_process_init().
00188 { 00189 if (volume < 0) 00190 volume = 0; 00191 00192 source->default_volume = volume; 00193 source->default_freq = frequency; 00194 00195 signal_source_restore_defaults(source); 00196 }
void signal_source_restore_defaults | ( | struct signal_source * | source | ) |
Definition at line 180 of file dsp_process.c.
References signal_source::default_freq, signal_source::default_volume, signal_source::frequency, and signal_source::volume.
Referenced by signal_source_init().
00181 { 00182 source->volume = source->default_volume; 00183 source->frequency = source->default_freq; 00184 }
void signal_source_set_freq | ( | struct signal_source * | source, | |
unsigned int | frequency | |||
) |
Definition at line 156 of file dsp_process.c.
References signal_source::frequency.
Referenced by state_machine_source().
void signal_source_set_volume | ( | struct signal_source * | source, | |
dsp16_t | volume | |||
) |
Definition at line 167 of file dsp_process.c.
References signal_source::volume.
Referenced by state_machine_source().
unsigned int active_filter |
Definition at line 78 of file dsp_process.c.
Referenced by dac_reload_callback(), filter_active_get_description(), filter_restore_default(), and filter_set_active().
Definition at line 71 of file dsp_process.c.
Referenced by dac_reload_callback(), and dsp_process_init().
dsp16_t fft_window[BUFFER_LENGTH] [static] |
Definition at line 76 of file dsp_process.c.
Referenced by dsp_calculate_fft(), and dsp_process_init().
A_ALIGNED dsp16_t filter_coef[NUM_FILTERS-1][FIR_NUM_COEF] |
const char* filter_description[NUM_FILTERS] |
Initial value:
{ "No filtering", "High-pass filter,\n1000Hz cut-off", "Low-pass filter,\n1000Hz cut-off", }
Definition at line 80 of file dsp_process.c.
Referenced by filter_get_description().
A_ALIGNED dsp16_t signal1_buf[BUFFER_LENGTH] |
struct signal_source signal1_generator |
Definition at line 56 of file dsp_process.c.
Referenced by dac_reload_callback(), dsp_process_init(), and state_machine_source().
A_ALIGNED dsp16_t signal2_buf[BUFFER_LENGTH] |
struct signal_source signal2_generator |
Definition at line 57 of file dsp_process.c.
Referenced by dac_reload_callback(), dsp_process_init(), and state_machine_source().
Definition at line 63 of file dsp_process.c.
Referenced by dac_reload_callback(), dsp_process_init(), dsp_process_task(), and gui_task().
A_ALIGNED dsp16_t signal_in_fft[BUFFER_LENGTH] |
A_ALIGNED dsp16_t signal_out_buf[BUFFER_LENGTH+4] |
Definition at line 64 of file dsp_process.c.
Referenced by dac_reload_callback(), dsp_process_task(), and gui_task().
A_ALIGNED dsp16_t signal_out_fft[BUFFER_LENGTH] |
A_ALIGNED dsp16_t signal_pre_filter_buf[FIR_NUM_COEF+BUFFER_LENGTH] |
Definition at line 62 of file dsp_process.c.
Referenced by dac_reload_callback(), and dsp_process_init().
bool signals_are_updated |
Definition at line 55 of file dsp_process.c.
Referenced by dac_reload_callback(), and gui_print_signal_box().
dsp16_t stereo_out_buf1[BUFFER_LENGTH *2] |
Definition at line 69 of file dsp_process.c.
Referenced by dac_reload_callback(), and dsp_process_init().
dsp16_t stereo_out_buf2[BUFFER_LENGTH *2] |