예제 #1
0
파일: dsp_process.c 프로젝트: kerichsen/asf
void dac_reload_callback(void)
{
	int i;

	if (current_stereo_out_buf == stereo_out_buf1)
		current_stereo_out_buf = stereo_out_buf2;
	else
		current_stereo_out_buf = stereo_out_buf1;

	generate_signal(signal1_buf, &signal1_generator);
	generate_signal(signal2_buf, &signal2_generator);

	/* In order for the FIR filter to work correctly we need to keep
	 * the last part of the previous buffer */
	for (i = 0; i < FIR_NUM_COEF; i++) {
		signal_pre_filter_buf[i] =
				signal_pre_filter_buf[BUFFER_LENGTH + i];
	}

	/* New data is put in the signal_in_buf which points behind the data
	 * kept from the previous buffer */
	dsp16_vect_add_and_sat(signal_in_buf, signal1_buf, signal2_buf,
			BUFFER_LENGTH);

	/* Run the FIR filter; the input buffer will be ... longer then the
	 * output buffer, which has normal length */
	if (active_filter > 0) {
		dsp16_filt_fir(signal_out_buf, signal_pre_filter_buf,
				BUFFER_LENGTH + FIR_NUM_COEF - 1,
				filter_coef[active_filter - 1], FIR_NUM_COEF);
	} else {
		for (i = 0; i < BUFFER_LENGTH; i++)
			signal_out_buf[i] = signal_in_buf[i];
	}

	for (i = 0; i < BUFFER_LENGTH; i++) {
		current_stereo_out_buf[i*2] = signal_out_buf[i];
		current_stereo_out_buf[i*2+1] = signal_out_buf[i];
	}

	signals_are_updated = 1;

	/* Update PDCA buffer */
	tpa6130_dac_output(current_stereo_out_buf, BUFFER_LENGTH);
}
예제 #2
0
/*! main function */
int main(void)
{
  init_sys_clocks();

  // Initialize RS232 debug text output.
  init_dbg_rs232(FOSC0);

  print_dbg(MSG_WELCOME);

  // Enable LED0 and LED1
  gpio_enable_gpio_pin(LED0_GPIO);
  gpio_enable_gpio_pin(LED1_GPIO);

  // Configure TWI as master
  twi_init();

  // Initialize TPA6130
  tpa6130_init();

  // Initialize DAC that send audio to TPA6130
  tpa6130_dac_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                    DEFAULT_DAC_NUM_CHANNELS,
                    DEFAULT_DAC_BITS_PER_SAMPLE,
                    DEFAULT_DAC_SWAP_CHANNELS,
                    master_callback,
                      AUDIO_DAC_OUT_OF_SAMPLE_CB
                    | AUDIO_DAC_RELOAD_CB,
                    FOSC0);

  tpa6130_set_volume(0x2F);
  tpa6130_get_volume();

  int count = 0;
  int i=0;

  while(true)
  {
    count = 0;

    // Store sample from the sound_table array
    while(count < (SOUND_SAMPLES)){
      samples[count++] = ((uint8_t)sound_table[i]+0x80) << 8;
      samples[count++] = ((uint8_t)sound_table[i]+0x80) << 8;
      i++;
      if (i >= sizeof(sound_table)) i = 0;
    }

    gpio_set_gpio_pin(LED0_GPIO);
    gpio_clr_gpio_pin(LED1_GPIO);

    // Play buffer
    tpa6130_dac_output((void *) samples,SOUND_SAMPLES/2);

    gpio_clr_gpio_pin(LED0_GPIO);
    gpio_set_gpio_pin(LED1_GPIO);

    /* Wait until the reload register is empty.
     * This means that one transmission is still ongoing
     * but we are already able to set up the next transmission
     */
     while(!tpa6130_dac_output(NULL, 0));
  }
}