void dsp_process_init(int cpu_hz, int hsb_hz, int pba_hz, int pbb_hz) { // Initialize TPA6130 tpa6130_init(); // Initialize DAC that send audio to TPA6130 tpa6130_dac_start(DAC_SAMPLING_RATE, DAC_NUM_CHANNELS, DAC_BITS_PER_SAMPLE, DAC_SWAP_CHANNELS, audio_callback, AUDIO_DAC_RELOAD_CB, FOSC0); tpa6130_set_volume(0x20); tpa6130_get_volume(); signal_source_init(&signal1_generator, 433, 20000); signal_source_init(&signal2_generator, 2000, 10000); current_stereo_out_buf = stereo_out_buf1; signal_in_buf = signal_pre_filter_buf + FIR_NUM_COEF; filter_restore_default(); /* Fill the initial buffer for the hamming window with ones. This buffer * will then be multiplied by the hamming window. */ dsp16_gen_step(fft_window, BUFFER_LENGTH, DSP16_Q(1.), DSP16_Q(1.), 0); dsp16_win_hamm(fft_window, fft_window, BUFFER_LENGTH); /* Run the interrupt handler manually once to start the ABDAC */ dac_reload_callback(); }
void dsp16_gen_dcomb(dsp16_t *vect1, int size, int f, int fs, dsp16_t delay) { int i; int t_inc, t_low, cp; int t_delay; // Number of sample per period t_inc = fs / f; // Number of sample for the delay t_delay = (((S32) delay) * ((S32) t_inc)) >> DSP16_QB; // Number of sample per low signal t_inc--; i = 0; t_low = t_delay; // Main loop while(i < size) { // Low part cp = MIN(t_low, size); for(; i<cp; i++) vect1[i] = DSP16_Q(0.); // High part if (i < size) vect1[i++] = DSP16_Q(1.); t_low = t_inc + i; } }
//see header rc_value_t delta_ramp(rc_value_t y1, rc_value_t y0, dsp16_t t) { if(t < DSP16_Q(0.5f)) { //original formula is : y0 + (y1-y0)*t/(dT/2) //it has been tweaked a little to avoid overflow return 2*(y0/2 + 2*dsp16_op_mul((y1/2-y0/2),t) ); } else { //y1 - (y1-y0)*(t-dT/2)/(dT/2) return 2*(y1/2 - 2*dsp16_op_mul((y1/2-y0/2),(t-DSP16_Q(0.5f))) ); } }
void dsp16_gen_rect(dsp16_t *vect1, int size, int f, int fs, dsp16_t duty, dsp16_t delay) { int i = 0; int t_low_inc, t_high_inc, cp; int t_low, t_high, t_delay; // Number of sample per period t_low_inc = fs / f; // Number of sample per high signal t_high_inc = (((S32) duty) * ((S32) t_low_inc)) >> DSP16_QB; // Number of sample for the delay t_delay = (((S32) delay) * ((S32) t_low_inc)) >> DSP16_QB; // Number of sample per low signal t_low_inc -= t_high_inc; i = 0; // For the delay t_high = MIN(t_high_inc, t_delay - t_low_inc); t_low = MIN(t_low_inc, t_delay); if (t_high > 0) t_low += t_high; // Main loop while(i < size) { // High part cp = MIN(t_high, size); for(; i<cp; i++) vect1[i] = DSP16_Q(1.); // Low part cp = MIN(t_low, size); for(; i<cp; i++) vect1[i] = DSP16_Q(-1.); t_high = t_high_inc + i; t_low = t_high + t_low_inc; } }
dsp16_t dsp16_gen_saw(dsp16_t *vect1, int size, int f, int fs, dsp16_t duty, dsp16_t delay) { int i = 0; S32 t_low_inc, t_high_inc, t; dsp16_t delta_rise, delta_decrease, delta; // Number of sample per period t_low_inc = fs / f; // Number of sample per high signal t_high_inc = (((S32) duty) * ((S32) t_low_inc)) >> DSP16_QB; // Number of sample for the delay t = (((S32) delay) * ((S32) t_low_inc)) >> DSP16_QB; // Number of sample per low signal t_low_inc -= t_high_inc; // Calculate the delta coefficient of the rising edge of the saw tooth delta_rise = (DSP16_Q(1.) / t_high_inc) * 2; // Calculate the delta coefficient of the decreasing edge of the saw tooth delta_decrease = (DSP16_Q(1.) / t_low_inc) * 2; // Compute the initial value if (t < t_high_inc) delta = DSP16_Q(-1.) + t * delta_rise; else delta = DSP16_Q(1.) - (t - t_high_inc) * delta_decrease; while(i < size) { int lim, j; if (i) t = 0; lim = Max(0, Min(t_high_inc - t, size - i)); for(j=0; j<lim; j++) vect1[i++] = (delta += delta_rise); t += lim; if (j) delta = DSP16_Q(1.); lim = Min(t_high_inc + t_low_inc - t, size - i); for(j=0; j<lim; j++) vect1[i++] = (delta -= delta_decrease); t += lim; delta = DSP16_Q(-1.); } return (t << DSP16_QB) / (t_high_inc + t_low_inc); }
//! The main function int main(int argc, char *argv[]) { unsigned int cycle_count; int i; short predicted_value, step_index; int diff; dsp16_t ratio; // Switch to external Oscillator 0. pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP); // Initialize the DSP debug module dsp_debug_initialization(FOSC0); // Get the actual cycle count cycle_count = Get_sys_count(); predicted_value = 0; step_index = 0; // Encode dsp_adpcm_ima_encode(cbuf, sbuf, NSAMPLES, &step_index, &predicted_value); predicted_value = 0; step_index = 0; // Decode dsp_adpcm_ima_decode(new_sbuf, cbuf, NSAMPLES, &step_index, &predicted_value); // Calculate the number of cycles cycle_count = Get_sys_count() - cycle_count; // Error calculation diff = 0; for(i=0; i<NSAMPLES; i++) diff += ((new_sbuf[i]-sbuf[i]) > 0)?(new_sbuf[i]-sbuf[i]):(sbuf[i]-new_sbuf[i]); ratio = DSP16_Q((diff/NSAMPLES)/(((float) (1 << 15)))); // Print the number of cycles dsp16_debug_printf("Cycle count: %d\n", cycle_count); // Print the error average dsp16_debug_printf("Error average ratio: %f\n", ratio); while(1); }
/* * Output range = [-1; 1] corresponding to [-pi; pi] */ dsp16_t dsp16_op_asin(dsp16_t num) { S32 num_sqr, res; dsp16_t num_abs; num_abs = dsp16_op_abs(num); #if DSP16_QB < 15 // Limits if (((S32) num) >= ((S32) DSP16_Q(1.))) return DSP16_Q(0.5); if (((S32) num) <= ((S32) DSP16_Q(-1.))) return DSP16_Q(-0.5); #endif // If |num| > 0.5 if (num_abs > DSP16_Q(0.5)) { num_abs = dsp16_op_sqrt((DSP16_Q(1.)-num_abs) >> 1); num_abs = DSP16_Q(0.5) - (dsp16_op_asin(num_abs) << 1); return (num < 0)?-num_abs:num_abs; }
#include "compiler.h" #include "board.h" #include "dsp.h" #include "dsp_debug.h" #include "pm.h" #include "cycle_counter.h" #include "gpio.h" //! \brief The size of the input signal #define SIZE 64 //! \brief Buffer containing input data A_ALIGNED dsp16_t input_x[SIZE] = { DSP16_Q(0.00000000000), DSP16_Q(0.03718075139), DSP16_Q(0.07131184859), DSP16_Q(0.09963983090), DSP16_Q(0.11997464035), DSP16_Q(0.13090169944), DSP16_Q(0.13191810690), DSP16_Q(0.12347962859), DSP16_Q(0.10695389264), DSP16_Q(0.08448437894), DSP16_Q(0.05877852523), DSP16_Q(0.03284069954), DSP16_Q(0.00967618536), DSP16_Q(-0.00800483670), DSP16_Q(-0.01805432735), DSP16_Q(-0.01909830056),
//! The size of the input signal #define SIZE 48 // A High-pass IIR Filter // Butterworth model // Fsample = 48 KHz // Fcut-off = 2000 Hz // Order 5 #define NUM_SIZE 6 #define NUM_PREDIV 3 #define DEN_SIZE 5 #define DEN_PREDIV 3 A_ALIGNED dsp16_t num[NUM_SIZE] = { DSP16_Q(0.6537018 / (1 << NUM_PREDIV)), DSP16_Q(-3.2685088 / (1 << NUM_PREDIV)), DSP16_Q(6.5370176 / (1 << NUM_PREDIV)), DSP16_Q(-6.5370176 / (1 << NUM_PREDIV)), DSP16_Q(3.2685088 / (1 << NUM_PREDIV)), DSP16_Q(-0.6537018 / (1 << NUM_PREDIV)) }; A_ALIGNED dsp16_t den[DEN_SIZE] = { DSP16_Q(-4.1534907 / (1 << DEN_PREDIV)), DSP16_Q(6.9612765 / (1 << DEN_PREDIV)), DSP16_Q(-5.877997 / (1 << DEN_PREDIV)), DSP16_Q(2.498365 / (1 << DEN_PREDIV)), DSP16_Q(-0.427326 / (1 << DEN_PREDIV)) };
#if defined(FORCE_ALL_GENERICS) || \ defined(FORCE_GENERIC_OP16_SIN) || \ !defined(TARGET_SPECIFIC_OP16_SIN) #define DSP16_MODULO_1_MASK (((U16) -1) >> (16 - (DSP16_QB+1))) extern dsp16_t dsp16_op_kernel_cosfix(dsp16_t angle); extern dsp16_t dsp16_op_kernel_sinfix(dsp16_t angle); /* * Input range = [-1; 1] corresponding to [-pi; pi] */ dsp16_t dsp16_op_sin(dsp16_t angle) { #if DSP16_QA > 1 U16 n = ((angle + DSP16_Q(0.25)) & DSP16_MODULO_1_MASK) >> (DSP16_QB-1); #else U16 n = ((U16) (angle + DSP16_Q(0.25))) >> (DSP16_QB-1); #endif // Translate input down to +/- pi/4 angle -= n*DSP16_Q(0.5); #if DSP16_QA > 1 // angle modulo 1 (signed values) angle <<= (16 - (DSP16_QB+1)); angle >>= (16 - (DSP16_QB+1)); #endif switch(n) {
static bool state_machine_source(int source_id, enum state_function *state) { static dsp16_t volume; static unsigned int frequency; struct signal_source *source = NULL; if (source_id == 1) source = &signal1_generator; else if (source_id == 2) source = &signal2_generator; switch (*state) { case STATE_FCT_IDLE: if (source_id == 1) { if (new_state_fct) { gui_set_selection(GUI_SOURCE1_ID); gui_text_print(GUI_COMMENT_ID, TEXT_SOURCE1); } else { if (controller_wheel_right(2)) switch_state(STATE_SOURCE2); return false; } } else if (source_id == 2) { if (new_state_fct) { gui_set_selection(GUI_SOURCE2_ID); gui_text_print(GUI_COMMENT_ID, TEXT_SOURCE2); } else { if (controller_wheel_left(2)) switch_state(STATE_SOURCE1); else if (controller_wheel_right(2)) switch_state(STATE_INPUT); return false; } } break; // Amplitude case STATE_FCT_FUNCTION1: volume = signal_source_get_volume(source); if (controller_wheel_right(1) && volume < DSP16_Q(1.)) { if (volume < DSP16_Q(1.) - DSP16_Q(1./16)) volume += DSP16_Q(1./16); else volume = DSP16_Q(1.); new_state_fct = true; } else if (controller_wheel_left(1)) { if (volume > DSP16_Q(1./16)) volume -= DSP16_Q(1./16); else volume = 0; new_state_fct = true; } if (new_state_fct) { signal_source_set_volume(source, volume); gui_text_printf(GUI_COMMENT_ID, "Source%i - " TEXT_FUNC1 "\nAmplitude %f\n\n\n\n" TEXT_WHEEL, source_id, volume); } break; // Frequency case STATE_FCT_FUNCTION2: frequency = signal_source_get_freq(source); if (controller_wheel_right(1) && frequency < 10000) { frequency *= 1.1; new_state_fct = true; } else if (controller_wheel_left(1) && frequency > 100) { frequency *= 0.9; new_state_fct = true; } if (new_state_fct) { signal_source_set_freq(source, frequency); gui_text_printf(GUI_COMMENT_ID, "Source%i - " TEXT_FUNC2 "\nFrequency %iHz\n\n\n\n" TEXT_WHEEL, source_id, frequency); } break; case STATE_FCT_FUNCTION3: break; // Zoom case STATE_FCT_ZOOM: if (new_state_fct) { zoom_view = true; if (source_id == 1) zoom_view_id = GUI_SOURCE1_ID; else if (source_id == 2) zoom_view_id = GUI_SOURCE2_ID; controller_reset(); } break; } return true; }
#include "pm.h" #include "cycle_counter.h" // Length of the output signal #define VECT1_SIZE 11 // Length of the first input signal #define VECT2_SIZE 11 // Length of the second input signal #define VECT3_SIZE 11 // The output signal A_ALIGNED dsp16_t vect1[VECT1_SIZE]; // The first input signal A_ALIGNED dsp16_t vect2[VECT2_SIZE] = { DSP16_Q(0.012010), DSP16_Q(0.059717), DSP16_Q(0.101397), DSP16_Q(0.0583150), DSP16_Q(0.0000000), DSP16_Q(0.0921177), DSP16_Q(0.0951057), DSP16_Q(0.0884270), DSP16_Q(0.0716020), DSP16_Q(0.515080), DSP16_Q(0.0583150) }; // The second input signal A_ALIGNED dsp16_t vect3[VECT3_SIZE] = { DSP16_Q(0.5), DSP16_Q(0.101397),
DSP32_Q(-0.01913417162), DSP32_Q(-0.05000000000), DSP32_Q(-0.07373934164), DSP32_Q(-0.08535533906), DSP32_Q(-0.08296893720), DSP32_Q(-0.06830127019), DSP32_Q(-0.04619397663), DSP32_Q(-0.02329629131), DSP32_Q(-0.00627097288), DSP32_Q(0.00000000000), DSP32_Q(-0.00627097288), DSP32_Q(-0.02329629131), DSP32_Q(-0.04619397663), DSP32_Q(-0.06830127019), DSP32_Q(-0.08296893720), DSP16_Q(-0.08535533906), DSP32_Q(-0.07373934164), DSP32_Q(-0.05000000000), DSP32_Q(-0.01913417162), DSP32_Q(0.01205904774), DSP32_Q(0.03677496058), DSP32_Q(0.05000000000), DSP32_Q(0.04982757980), DSP32_Q(0.03794095226), DSP32_Q(0.01913417162), DSP32_Q(0.00000000000), DSP32_Q(-0.01286319874), DSP32_Q(-0.01464466094), DSP32_Q(-0.00363360317), DSP32_Q(0.01830127019), DSP32_Q(0.04619397663),
void dac_overrun_callback(void); void dac_reload_callback(void); static A_ALIGNED dsp16_t fft_window[BUFFER_LENGTH]; unsigned int active_filter; const char * filter_description[NUM_FILTERS] = { "No filtering", "High-pass filter,\n1000Hz cut-off", "Low-pass filter,\n1000Hz cut-off", }; A_ALIGNED dsp16_t filter_coef[NUM_FILTERS - 1][FIR_NUM_COEF] = { { DSP16_Q(-0.0184183), DSP16_Q(-0.0207874), DSP16_Q(-0.0231255), DSP16_Q(-0.0254103), DSP16_Q(-0.0276199), DSP16_Q(-0.0297327), DSP16_Q(-0.0317281), DSP16_Q(-0.0335863), DSP16_Q(-0.0352887), DSP16_Q(-0.0368182), DSP16_Q(-0.0381593), DSP16_Q(-0.0392986), DSP16_Q(-0.0402242), DSP16_Q(-0.0409269), DSP16_Q(-0.0413995), DSP16_Q(0.9583631),
DSP16_Q(0.261138916015625), DSP16_Q(0.3179931640625), DSP16_Q(0.261138916015625), DSP16_Q(0.127838134765625), DSP16_Q(0), DSP16_Q(-0.05859375), DSP16_Q(-0.043792724609375), DSP16_Q(0), DSP16_Q(0.025848388671875), DSP16_Q(0.0198974609375) }; */ // calculated by Torsten Schultze DG1HT A_ALIGNED const dsp16_t RXLowPassCoeff[] = { DSP16_Q(0.019823264989714), DSP16_Q(0.025848388671875), DSP16_Q(0), DSP16_Q(-0.043792724609375), DSP16_Q(-0.05859375), DSP16_Q(0), DSP16_Q(0.127838134765625), DSP16_Q(0.261138916015625), DSP16_Q(0.3179931640625), DSP16_Q(0.261138916015625), DSP16_Q(0.127838134765625), DSP16_Q(0), DSP16_Q(-0.058593752349941), DSP16_Q(-0.041093832349941), DSP16_Q(0), DSP16_Q(0.026812695985862),
#include "dsp.h" #include "dsp_debug.h" #include "pm.h" #include "cycle_counter.h" //! The size of the input signal #define SIZE 72 //! The output buffer A_ALIGNED dsp16_t vect1[SIZE]; //! The input signal A_ALIGNED dsp16_t vect2[SIZE] = { DSP16_Q(0.10000000000), DSP16_Q(-0.06909830056), DSP16_Q(0.15877852523), DSP16_Q(-0.01909830056), DSP16_Q(0.19510565163), DSP16_Q(0.00000000000), DSP16_Q(0.19510565163), DSP16_Q(-0.01909830056), DSP16_Q(0.15877852523), DSP16_Q(-0.06909830056), DSP16_Q(0.10000000000), DSP16_Q(-0.13090169944), DSP16_Q(0.04122147477), DSP16_Q(-0.18090169944), DSP16_Q(0.00489434837), DSP16_Q(-0.20000000000),
#include "pm.h" #include "cycle_counter.h" //! Sampling rate of the original signal #define F_INPUT 22050 //! Sampling rate of the output signal #define F_OUTPUT 48510 //! Number of point to process #define N 200 #define NB_CUTS 40 //! Filter order #define FILTER_ORDER 6 A_ALIGNED dsp16_t s[N] = { DSP16_Q(0.00000000000), DSP16_Q(0.28111111333), DSP16_Q(0.53955074319), DSP16_Q(0.75447585092), DSP16_Q(0.90855282432), DSP16_Q(0.98935542552), DSP16_Q(0.99036696149), DSP16_Q(0.91150585231), DSP16_Q(0.75913221057), DSP16_Q(0.54553490121), DSP16_Q(0.28794045010), DSP16_Q(0.00712373261), DSP16_Q(-0.27426751067), DSP16_Q(-0.53353920393), DSP16_Q(-0.74978120297), DSP16_Q(-0.90555368889),
#include "dsp_debug.h" #include "pm.h" #include "cycle_counter.h" //! The size of the input signal #define SIZE 64 //! The number of tap #define FIR_COEF_SIZE 25 //! The output buffer A_ALIGNED dsp16_t y[SIZE - FIR_COEF_SIZE + 1 + 4]; // <- "+4" for avr32-uc3 optimized FIR version //! The input signal A_ALIGNED dsp16_t x[SIZE] = { DSP16_Q(0.00000000000), DSP16_Q(0.05971733276), DSP16_Q(0.10139671591), DSP16_Q(0.11013997327), DSP16_Q(0.07684940146), DSP16_Q(0.00000000000), DSP16_Q(-0.11375674283), DSP16_Q(-0.25026678831), DSP16_Q(-0.38974690945), DSP16_Q(-0.50960156497), DSP16_Q(-0.58778525229), DSP16_Q(-0.60622623909), DSP16_Q(-0.55381024215), DSP16_Q(-0.42847700858), DSP16_Q(-0.23810168641), DSP16_Q(-0.00000000000),