Пример #1
0
//! The main function
int main(int argc, char *argv[])
{
  unsigned int cycle_count;

  // 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();

  // Perform a 25-taps FIR
  dsp16_filt_iirpart(vect1, vect2, SIZE, num, NUM_SIZE, den, DEN_SIZE, 0, 0);

  // Calculate the number of cycles
  cycle_count = Get_sys_count() - cycle_count;

  // Print the number of cycles
  dsp16_debug_printf("Cycle count: %d\n", cycle_count);

  // Print the  output signal
  dsp16_debug_print_vect(vect1, SIZE - NUM_SIZE + 1);

  while(1);
}
Пример #2
0
//! The main function
int main(int argc, char *argv[])
{
  A_ALIGNED static dsp16_t s_input[N/NB_CUTS];
  int f;
  dsp_resampling_t *resampling;
  dsp16_t *output;
  U32 temp;
  dsp16_resampling_options_t options;

  // Initialize options
  memset(&options, 0, sizeof(options));
  options.coefficients_generation = DSP16_RESAMPLING_OPTIONS_USE_DYNAMIC;
  options.dynamic.coefficients_normalization = true;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  dsp16_debug_printf("16-bit fixed point signal resampling\n");
  dsp16_debug_printf("Input Fs: %iHz\n", F_INPUT);
  dsp16_debug_printf("Output Fs: %iHz\n", F_OUTPUT);
  dsp16_debug_printf("%i samples to process cut into %i buffers\n", N, NB_CUTS);
  dsp16_debug_printf("Filter order used: %i\n", FILTER_ORDER);

  if (!(resampling = dsp16_resampling_setup(F_INPUT, F_OUTPUT, N/NB_CUTS, FILTER_ORDER, 1, (malloc_fct_t) malloc, &options)))
  {
    dsp16_debug_printf("Unable to allocate enough memory\n");
    return -1;
  }

  if (!(output = (dsp16_t *) malloc(dsp16_resampling_get_output_max_buffer_size(resampling)*sizeof(dsp16_t) + 4)))
  {
    dsp16_debug_printf("Unable to allocate enough memory for the output buffer\n");
    return -1;
  }

  for(f=0; f<NB_CUTS; f++)
  {
    memcpy(s_input, &s[N/NB_CUTS*f], (N/NB_CUTS)*sizeof(dsp16_t));
    temp = Get_sys_count();
    dsp16_resampling_compute(resampling, output, s_input, 0);
    temp = Get_sys_count() - temp;
    dsp16_debug_print_vect(output, dsp16_resampling_get_output_current_buffer_size(resampling));
  }
  dsp16_debug_printf(
    "Cycle count per iteration: %i\n            in total (to compute %i samples): %i\n",
    temp,
    dsp16_resampling_get_output_current_buffer_size(resampling)*NB_CUTS,
    temp*NB_CUTS);

  dsp16_resampling_free(resampling, (free_fct_t) free);

  while(1);
}
Пример #3
0
//! 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);
}
int zero_padding(int *size)
{
  int cycle_count;

  // Action
  dsp16_debug_printf("vect1 = zeros(vect1)\n");

  *size = VECT1_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_zeropad(vect1, VECT1_SIZE, VECT1_SIZE);

  return Get_sys_count() - cycle_count;
}
int copy(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)

  // Action
  dsp16_debug_printf("vect1 = vect2\n");

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_copy(vect1, vect2, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
int maximum(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE > 0)
  CHECK_CONDITIONS(VECT2_SIZE > 0)

  // Action
  dsp16_debug_printf("max(vect2)\n");

  *size = 1;

  cycle_count = Get_sys_count();
  vect1[0] = dsp16_vect_max(vect2, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
int power(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT3_SIZE > 0)

  // Action
  dsp16_debug_printf("vect1 = vect2 ^ %f\n", vect3[0]);

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_pow(vect1, vect2, VECT2_SIZE, vect3[0]);

  return Get_sys_count() - cycle_count;
}
int int_multiplication(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT3_SIZE > 0)

  // Action
  dsp16_debug_printf("vect1 = vect2 * %i\n", vect3[0]);

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_intmul(vect1, vect2, VECT2_SIZE, vect3[0]);

  return Get_sys_count() - cycle_count;
}
int dot_division(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= VECT2_SIZE)
  CHECK_CONDITIONS(VECT2_SIZE == VECT3_SIZE)

  // Action
  dsp16_debug_printf("vect1 = vect2 ./ vect3\n");

  *size = VECT2_SIZE;

  cycle_count = Get_sys_count();
  dsp16_vect_dotdiv(vect1, vect2, vect3, VECT2_SIZE);

  return Get_sys_count() - cycle_count;
}
int partial_convolution(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE - VECT3_SIZE + 4))
  CHECK_CONDITIONS(!(VECT2_SIZE&3) && VECT2_SIZE > 0)
  CHECK_CONDITIONS(VECT3_SIZE >= 8)

  // Action
  dsp16_debug_printf("vect1 = partial_conv(vect2, vect3)\n");

  *size = VECT2_SIZE - VECT3_SIZE + 1;

  cycle_count = Get_sys_count();
  // Perform a partial convolution
  dsp16_vect_convpart(vect1, vect2, VECT2_SIZE, vect3, VECT3_SIZE);
  return Get_sys_count() - cycle_count;
}
int convolution(int *size)
{
  int cycle_count;

  // Conditions
  CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE + VECT3_SIZE - 1))
  CHECK_CONDITIONS(VECT2_SIZE >= 8)
  CHECK_CONDITIONS(VECT3_SIZE >= 8)
  if (VECT2_SIZE > VECT3_SIZE)
    CHECK_CONDITIONS(VECT1_SIZE >= (VECT2_SIZE + 2*VECT3_SIZE - 2))
  else
    CHECK_CONDITIONS(VECT1_SIZE >= (VECT3_SIZE + 2*VECT2_SIZE - 2))

  // Action
  dsp16_debug_printf("vect1 = conv(vect2, vect3)\n");

  *size = VECT2_SIZE + VECT3_SIZE - 1;

  cycle_count = Get_sys_count();
  // Perform a convolution
  dsp16_vect_conv(vect1, vect2, VECT2_SIZE, vect3, VECT3_SIZE);
  return Get_sys_count() - cycle_count;
}
//! The main function
int main(int argc, char *argv[])
{
  int cycle_count, size;
  int i;

  // Switch to external Oscillator 0.
  pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);

  // Initialize the DSP debug module
  dsp_debug_initialization(FOSC0);

  dsp16_debug_printf("16-bit fixed point vectors program test\n");

  dsp16_debug_printf("Output vector 1 (size %i)\n", VECT1_SIZE);
  dsp16_debug_printf("Input vector 2 (size %i)\n", VECT2_SIZE);
  dsp16_debug_printf("Input vector 3 (size %i)\n", VECT3_SIZE);

  while(1)
  {
    // Print the menu
    dsp16_debug_printf("***** Menu *****\n");
    for(i=0; i<sizeof(item_menu)/sizeof(s_item_menu); i++)
      dsp16_debug_printf("%i:\t%s\n", i, item_menu[i].title);

    // Prompt
    dsp16_debug_printf("> ");
    i = dsp_debug_read_ui();

    if (i >= 0 && i < sizeof(item_menu)/sizeof(s_item_menu))
    {
      // Print the title
      dsp16_debug_printf("%s\n", item_menu[i].title);

      // Call the function to execute
      cycle_count = item_menu[i].action(&size);

      if (cycle_count != -1)
      {
        // Print the number of cycles
        dsp16_debug_printf("Cycle count: %d\n", cycle_count);
        // Print the result
        dsp16_debug_print_vect(vect1, size);
      }
    }
    else
      dsp16_debug_printf("!Invalid item!\n");

    dsp16_debug_printf("<Press any key to continue>\n");
    dsp_debug_read_fct();
  }
}