예제 #1
0
파일: dsp_process.c 프로젝트: kerichsen/asf
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();
}
예제 #2
0
파일: tpa6130.c 프로젝트: InSoonPark/asf
/*! \brief Decreases the output volume of the amplifier by one step.
 *
 * Stops at the lowest possible volume.
 */
void tpa6130_dac_decrease_volume(void)
{
  int8_t volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));;
  if( volume > TPA6130_VOL_MIN )
    --volume;
  tpa6130_set_volume( volume );
}
예제 #3
0
파일: tpa6130.c 프로젝트: InSoonPark/asf
/*! \brief Increases the output volume of the amplifier by one step.
 * Stops at the maximum volume and thus does not wrap to the
 * lowest volume.
 */
void tpa6130_dac_increase_volume(void)
{
  int8_t volume = tpa6130_get_volume()& (~(MUTE_L | MUTE_R));
  if( volume < TPA6130_VOL_MIN )
    volume = TPA6130_VOL_MIN;
  tpa6130_set_volume(volume+1);
}
예제 #4
0
파일: demo.c 프로젝트: kerichsen/asf
static bool state_machine_idle(enum state_function *state)
{
  uint32_t frame_rate_ms;
  S8 volume;
  const S8 volume_inc = (TPA6130_VOL_MAX - TPA6130_VOL_MIN) / 20;

  switch (*state)
  {
  case STATE_FCT_IDLE:
    if (new_state_fct)
    {
      gui_set_selection(GUI_NO_SEL);
      gui_text_print(GUI_COMMENT_ID, TEXT_IDLE);
    }
    else
    {
      if (controller_wheel_right(1) || controller_wheel_left(1))
        switch_state(STATE_SOURCE1);
      return false;
    }
    break;
  // Frame rate
  case STATE_FCT_FUNCTION1:
    frame_rate_ms = gui_get_update_fs();
    if (controller_wheel_left(1) && frame_rate_ms < 1000)
    {
      if (!frame_rate_ms)
        frame_rate_ms = 40;
      else
        frame_rate_ms = 1000 / ((1000 / frame_rate_ms) - 1);
      new_state_fct = true;
    }
    else if (controller_wheel_right(1))
    {
      if (frame_rate_ms <= 40)
        frame_rate_ms = 0;
      else
        frame_rate_ms = 1000 / ((1000 / frame_rate_ms) + 1);
      new_state_fct = true;
    }
    if (new_state_fct)
    {
      gui_change_update_fs(frame_rate_ms);
      if (frame_rate_ms)
      {
        gui_text_printf(GUI_COMMENT_ID, TEXT_FUNC1 "\n%i Frame(s)/s\n\n\n\n" TEXT_WHEEL, (1000 / frame_rate_ms));
      }
      else
        gui_text_print(GUI_COMMENT_ID, TEXT_FUNC1 "\nMAX Frame(s)/s\n\n\n\n" TEXT_WHEEL);
    }
    break;
  // Volume
  case STATE_FCT_FUNCTION2:
    volume = tpa6130_get_volume();
    if (volume < TPA6130_VOL_MIN)
      volume = TPA6130_VOL_MIN;
    if (controller_wheel_right(1))
    {
      if (volume < TPA6130_VOL_MAX - volume_inc)
        volume += volume_inc;
      else
        volume = TPA6130_VOL_MAX;
      new_state_fct = true;
    }
    else if (controller_wheel_left(1))
    {
      if (volume > TPA6130_VOL_MIN + volume_inc)
        volume -= volume_inc;
      else
        volume = TPA6130_VOL_MIN;
      new_state_fct = true;
    }
    if (new_state_fct)
    {
      tpa6130_set_volume(volume);
      gui_text_printf(GUI_COMMENT_ID, TEXT_FUNC2 "\nVolume %i%%\n\n\n\n" TEXT_WHEEL, ((int) volume * 100) / (TPA6130_VOL_MAX - TPA6130_VOL_MIN));
    }
    break;
  /*
extern U8 tpa6130_get_volume(void);
extern void tpa6130_set_volume(U8 volume);
  */
  case STATE_FCT_FUNCTION3:
    if (new_state_fct)
      gui_text_print(GUI_COMMENT_ID, TEXT_FUNC_NOT_IMPLEMENTED);
    else if (controller_wheel_right(1) || controller_wheel_left(1)) {
      switch_state(STATE_SOURCE1);
      return false;
    }
    break;
  case STATE_FCT_ZOOM:
    break;
  }
  return true;
}
예제 #5
0
파일: tpa6130.c 프로젝트: InSoonPark/asf
/*! \brief Set the volume of the DAC.
 */
void tpa6130_dac_set_volume(uint8_t volume)
{
   tpa6130_set_volume(volume);
}
예제 #6
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));
  }
}