void WavePlayBack(uint32_t AudioFreq)
{ 
    /* note: these mallocs are NOT freed at the moment */
    sp_create(&sp);
    sp->sr = AudioFreq;

    sp_ftbl_create(sp, &ft, 8192);
    sp_gen_sine(sp, ft);

    sp_osc_create(&osc);

    sp_osc_init(sp, osc, ft, 0);
    osc->freq = 0.2f;
    osc->amp = 1.f;
    uint32_t i;

    for(i = 0; i < NOSCS; i++) {
        sp_fosc_create(&fosc[i]);
        sp_fosc_init(sp, fosc[i], ft);
        fosc[i]->freq = sp_midi2cps(scale[i]);
        fosc[i]->amp = 0.1f;
    }

    for(i = 0; i < MY_BUFSIZE; i++) {
        buf0[i] = 0;
        buf1[i] = 0;
    }

    sp_revsc_create(&revsc);
    sp_revsc_init(sp, revsc);

    /* Initialize wave player (Codec, DMA, I2C) */
    WavePlayerInit(AudioFreq);
    nextbuf = 1;

    compute_buffer(buf1, MY_BUFSIZE);
    Audio_MAL_Play((uint32_t)buf0, MY_BUFSIZE / 2);

    EVAL_AUDIO_Mute(AUDIO_MUTE_ON);
    while(1) {
        while(nextbuf == 1);
        if(please_play == 0) {
            EVAL_AUDIO_Mute(AUDIO_MUTE_OFF);
            please_play = 1;
        }
        compute_buffer(buf0, MY_BUFSIZE);
        while(nextbuf == 0);
        compute_buffer(buf1, MY_BUFSIZE);
    };

}
示例#2
0
void WavePlayBack(uint32_t AudioFreq)
{ 
  /* 
  Normal mode description:
  Start playing the audio file (using DMA stream) .
  Using this mode, the application can run other tasks in parallel since 
  the DMA is handling the Audio Transfer instead of the CPU.
  The only task remaining for the CPU will be the management of the DMA 
  Transfer Complete interrupt or the Half Transfer Complete interrupt in 
  order to load again the buffer and to calculate the remaining data.  
  Circular mode description:
  Start playing the file from a circular buffer, once the DMA is enabled it 
  always run. User has to fill periodically the buffer with the audio data 
  using Transfer complete and/or half transfer complete interrupts callbacks 
  (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
  In this case the audio data file is smaller than the DMA max buffer 
  size 65535 so there is no need to load buffer continuously or manage the 
  transfer complete or Half transfer interrupts callbacks. */  
  
  /* Start playing */
  AudioPlayStart = 1;
  
  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);
  
  /* Play on */
  AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS), AUDIO_FILE_SZE, AUDIO_START_ADDRESS);
  
  /* Infinite loop */
  while(1)
  {
		if (PauseResumeStatus != 2)
		{
			WavePlayerPauseResume(PauseResumeStatus);
			PauseResumeStatus = 2;
		}
	}
}
void WavePlayBack(uint32_t AudioFreq)
{ 
  /*
  Normal mode description:
  Start playing the audio file (using DMA stream) .
  Using this mode, the application can run other tasks in parallel since 
  the DMA is handling the Audio Transfer instead of the CPU.
  The only task remaining for the CPU will be the management of the DMA 
  Transfer Complete interrupt or the Half Transfer Complete interrupt in 
  order to load again the buffer and to calculate the remaining data.  
  Circular mode description:
  Start playing the file from a circular buffer, once the DMA is enabled it 
  always run. User has to fill periodically the buffer with the audio data 
  using Transfer complete and/or half transfer complete interrupts callbacks 
  (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
  In this case the audio data file is smaller than the DMA max buffer 
  size 65535 so there is no need to load buffer continuously or manage the 
  transfer complete or Half transfer interrupts callbacks. */  

  AUDIO_PlaybackBuffer_Status Sound_BufferStatus;

  printf("WavePlayBack start\n");
  /* Start playing */

  audioBuffer = Sound_Get_AudioBuffer();
  Sound_Init();
  AudioPlayStart = 1;
  RepeatState =0;

  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);
  AudioRemSize   = 0;

  STOPWATCH_START
  /* Get Data from USB Key */
  f_lseek(&fileR, WaveCounter);
  //f_read (&fileR, audioBuffer, _MAX_SS, &BytesRead);
  STOPWATCH_STOP
  CycleCounter_Print(0,0,0);

  /* Start playing wave */
  Audio_MAL_Play((uint32_t)audioBuffer, 2*_MAX_SS);
  LED_Toggle = 6;
  PauseResumeStatus = 2;
  Count = 0;

  while(HCD_IsDeviceConnected(&USB_OTG_Core))
  {
    /* Test on the command: Playing */
    if (Command_index == 0)
    {

      /* wait for DMA transfer complete */
      while((AUDIO_PlaybackBuffer_GetStatus(0) == FULL) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
      {
#ifdef WAV_OLDCODE
        if (PauseResumeStatus == 0)
        {
          /* Pause Playing wave */
          LED_Toggle = 0;
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
        else if (PauseResumeStatus == 1)
        {
          LED_Toggle = 6;
          /* Resume Playing wave */
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
#else
        if(PauseResumeStatus != 2)
        {
          WAV_OpenNextFile();
          f_lseek(&fileR, WaveCounter);
          Sound_Init();
          PauseResumeStatus = 2;
        }
#endif
      }

      //#define SOUND_DIRECT_TEST
#ifndef	SOUND_DIRECT_TEST
      Sound_FillBuffer(&fileR);
#else
      Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(0);
      if(Sound_BufferStatus & LOW_EMPTY)
      {
        f_read (&fileR, audioBuffer, _MAX_SS, &BytesRead);
        Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(LOW_EMPTY);
      }
      if(Sound_BufferStatus & HIGH_EMPTY)
      {
        f_read (&fileR, audioBuffer+_MAX_SS/2, _MAX_SS, &BytesRead);
        Sound_BufferStatus = AUDIO_PlaybackBuffer_GetStatus(HIGH_EMPTY);
      }
#endif
    }
    else
    {
      WavePlayerStop();
      WaveDataLength = 0;
      RepeatState =0;
      break;
    }
    if(WaveDataLength == 0) {
      WaveDataLength = WAVE_Format.DataSize;
      f_lseek(&fileR, 44);
    }
  }
#if defined PLAY_REPEAT_OFF 
  RepeatState = 1;
  WavePlayerStop();
  if (Command_index == 0)
    LED_Toggle = 4;
#else 
  LED_Toggle = 7;
  RepeatState = 0;
  AudioPlayStart = 0;
  WavePlayerStop();
#endif

}
/**
  * @brief  Plays Wave from a mass storage.
  * @param  AudioFreq: Audio Sampling Frequency
  * @retval None
*/
void WavePlayBack(uint32_t AudioFreq)
{
  UINT bytesread = 0;

  /* Start playing */
  AudioPlayStart = 1;
  RepeatState = REPEAT_ON;

  /* Initialize Wave player (Codec, DMA, I2C) */
  if(WavePlayerInit(AudioFreq) != 0)
  {
    Error_Handler();
  }

  /* Get Data from USB Flash Disk */
  f_lseek(&FileRead, 0);
  f_read (&FileRead, &Audio_Buffer[0], AUDIO_BUFFER_SIZE, &bytesread);
  AudioRemSize = WaveDataLength - bytesread;

  /* Start playing Wave */
  BSP_AUDIO_OUT_Play((uint16_t*)&Audio_Buffer[0], AUDIO_BUFFER_SIZE);
  LEDsState = LED6_TOGGLE;
  PauseResumeStatus = RESUME_STATUS;
  PressCount = 0;

  /* Check if the device is connected.*/
  while((AudioRemSize != 0) && (AppliState != APPLICATION_IDLE))
  {
    /* Test on the command: Playing */
    if(CmdIndex == CMD_PLAY)
    {
      if(PauseResumeStatus == PAUSE_STATUS)
      {
        /* Stop Toggling LED2 to signal Pause */
        LEDsState = STOP_TOGGLE;
        /* Pause playing Wave */
        WavePlayerPauseResume(PauseResumeStatus);
        PauseResumeStatus = IDLE_STATUS;
      }
      else if(PauseResumeStatus == RESUME_STATUS)
      {
        /* Toggling LED6 to signal Play */
        LEDsState = LED6_TOGGLE;
        /* Resume playing Wave */
        WavePlayerPauseResume(PauseResumeStatus);
        PauseResumeStatus = IDLE_STATUS;
      }

      bytesread = 0;

      if(buffer_offset == BUFFER_OFFSET_HALF)
      {

        f_read(&FileRead,
               &Audio_Buffer[0],
               AUDIO_BUFFER_SIZE/2,
               (void *)&bytesread);

          buffer_offset = BUFFER_OFFSET_NONE;
      }

      if(buffer_offset == BUFFER_OFFSET_FULL)
      {
        f_read(&FileRead,
               &Audio_Buffer[AUDIO_BUFFER_SIZE/2],
               AUDIO_BUFFER_SIZE/2,
               (void *)&bytesread);

          buffer_offset = BUFFER_OFFSET_NONE;
      }
      if(AudioRemSize > (AUDIO_BUFFER_SIZE / 2))
      {
        AudioRemSize -= bytesread;
      }
      else
      {
        AudioRemSize = 0;
      }
    }
    else
    {
      /* Stop playing Wave */
      WavePlayerStop();
      /* Close file */
      f_close(&FileRead);
      AudioRemSize = 0;
      RepeatState = REPEAT_ON;
      break;
    }
  }
#ifdef PLAY_REPEAT_DISABLED
  RepeatState = REPEAT_OFF;
  /* Stop playing Wave */
  WavePlayerStop();
  /* Close file */
  f_close(&FileRead);
  /* Test on the command: Playing */
  if(CmdIndex == CMD_PLAY)
  {
    LEDsState = LED4_TOGGLE;
  }
#else
  LEDsState = LEDS_OFF;
  RepeatState = REPEAT_ON;
  AudioPlayStart = 0;
  /* Stop playing Wave */
  WavePlayerStop();
  /* Close file */
  f_close(&FileRead);
#endif /* PLAY_REPEAT_DISABLED */
}
示例#5
0
文件: test.c 项目: yallawalla/stm32
void WavePlayBack(uint32_t AudioFreq)
{ 
  /* Start playing */
  AudioPlayStart = 1;
  RepeatState =0;

  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);
  AudioRemSize   = 0; 

  /* Get Data from USB Key */
  f_lseek(&fileR, WaveCounter);
  f_read (&fileR, buffer1, _MAX_SS, &BytesRead); 
  f_read (&fileR, buffer2, _MAX_SS, &BytesRead);
 
  /* Start playing wave */
  Audio_MAL_Play((uint32_t)buffer1, _MAX_SS);
  buffer_switch = 1;
  XferCplt = 0;
  LED_Toggle = 6;
  PauseResumeStatus = 1;
  Count = 0;
 
  while((WaveDataLength != 0) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
  { 
    /* Test on the command: Playing */
    if (Command_index == 0)
    { 
      /* wait for DMA transfert complete */
      while((XferCplt == 0) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
      {
        if (PauseResumeStatus == 0)
        {
          /* Pause Playing wave */
          LED_Toggle = 0;
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
        else if (PauseResumeStatus == 1)
        {
          LED_Toggle = 6;
          /* Resume Playing wave */
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }  
      }
      XferCplt = 0;

      if(buffer_switch == 0)
      {
        /* Play data from buffer1 */
        Audio_MAL_Play((uint32_t)buffer1, _MAX_SS);
        /* Store data in buffer2 */
        f_read (&fileR, buffer2, _MAX_SS, &BytesRead);
        buffer_switch = 1;
      }
      else 
      {   
        /* Play data from buffer2 */
        Audio_MAL_Play((uint32_t)buffer2, _MAX_SS);
        /* Store data in buffer1 */
        f_read (&fileR, buffer1, _MAX_SS, &BytesRead);
        buffer_switch = 0;
      } 
    }
    else 
    {
      WavePlayerStop();
      WaveDataLength = 0;
      RepeatState =0;
      break;
    }
  }
#if defined PLAY_REPEAT_OFF 
  RepeatState = 1;
  WavePlayerStop();
  if (Command_index == 0)
    LED_Toggle = 4;
#else 
  LED_Toggle = 7;
  RepeatState = 0;
  AudioPlayStart = 0;
  WavePlayerStop();
#endif
}
示例#6
0
void WavePlayBack(uint32_t AudioFreq)
{
  /*
  Normal mode description:
  Start playing the audio file (using DMA stream) .
  Using this mode, the application can run other tasks in parallel since
  the DMA is handling the Audio Transfer instead of the CPU.
  The only task remaining for the CPU will be the management of the DMA
  Transfer Complete interrupt or the Half Transfer Complete interrupt in
  order to load again the buffer and to calculate the remaining data.
  Circular mode description:
  Start playing the file from a circular buffer, once the DMA is enabled it
  always run. User has to fill periodically the buffer with the audio data
  using Transfer complete and/or half transfer complete interrupts callbacks
  (EVAL_AUDIO_TransferComplete_CallBack() or EVAL_AUDIO_HalfTransfer_CallBack()...
  In this case the audio data file is smaller than the DMA max buffer
  size 65535 so there is no need to load buffer continuously or manage the
  transfer complete or Half transfer interrupts callbacks. */

  /* Start playing */
  AudioPlayStart = 1;
  RepeatState =0;
#if defined MEDIA_IntFLASH

  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);

  /* Play on */
  AudioFlashPlay((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS),AUDIO_FILE_SZE,AUIDO_START_ADDRESS);

  /* LED Blue Start toggling */
  LED_Toggle = 6;

  /* Infinite loop */
  while(1)
  {
    /* check on the repeate status */
    if (RepeatState == 0)
    {
      if (PauseResumeStatus == 0)
      {
        /* LED Blue Stop Toggling */
        LED_Toggle = 0;
        /* Pause playing */
        WavePlayerPauseResume(PauseResumeStatus);
        PauseResumeStatus = 2;
      }
      else if (PauseResumeStatus == 1)
      {
        /* LED Blue Toggling */
        LED_Toggle = 6;
        /* Resume playing */
        WavePlayerPauseResume(PauseResumeStatus);
        PauseResumeStatus = 2;
      }
    }
    else
    {
      /* Stop playing */
      WavePlayerStop();
      /* Green LED toggling */
      LED_Toggle = 4;
    }
  }

#elif defined MEDIA_USB_KEY
  /* Initialize wave player (Codec, DMA, I2C) */
  WavePlayerInit(AudioFreq);
  AudioRemSize   = 0;

  /* Get Data from USB Key */
  f_lseek(&fileR, WaveCounter);
  f_read (&fileR, buffer1, _MAX_SS, &BytesRead);
  f_read (&fileR, buffer2, _MAX_SS, &BytesRead);

  /* Start playing wave */
  Audio_MAL_Play((uint32_t)buffer1, _MAX_SS);
  buffer_switch = 1;
  XferCplt = 0;
  LED_Toggle = 6;
  PauseResumeStatus = 1;
  Count = 0;

  while((WaveDataLength != 0) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
  {
    /* Test on the command: Playing */
    if (Command_index == 0)
    {
      /* wait for DMA transfert complete */
      while((XferCplt == 0) &&  HCD_IsDeviceConnected(&USB_OTG_Core))
      {
        if (PauseResumeStatus == 0)
        {
          /* Pause Playing wave */
          LED_Toggle = 0;
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
        else if (PauseResumeStatus == 1)
        {
          LED_Toggle = 6;
          /* Resume Playing wave */
          WavePlayerPauseResume(PauseResumeStatus);
          PauseResumeStatus = 2;
        }
      }
      XferCplt = 0;

      if(buffer_switch == 0)
      {
        /* Play data from buffer1 */
        Audio_MAL_Play((uint32_t)buffer1, _MAX_SS);
        /* Store data in buffer2 */
        f_read (&fileR, buffer2, _MAX_SS, &BytesRead);
        buffer_switch = 1;
      }
      else
      {
        /* Play data from buffer2 */
        Audio_MAL_Play((uint32_t)buffer2, _MAX_SS);
        /* Store data in buffer1 */
        f_read (&fileR, buffer1, _MAX_SS, &BytesRead);
        buffer_switch = 0;
      }
    }
    else
    {
      WavePlayerStop();
      WaveDataLength = 0;
      RepeatState =0;
      break;
    }
  }
#if defined PLAY_REPEAT_OFF
  RepeatState = 1;
  WavePlayerStop();
  if (Command_index == 0)
    LED_Toggle = 4;
#else
  LED_Toggle = 7;
  RepeatState = 0;
  AudioPlayStart = 0;
  WavePlayerStop();
#endif
#endif

}
示例#7
0
void BSP_Start_Audio(uint8_t filename[255])
{
  UINT bytesread = 0;
  char path[] = "0:/";
  char* wavefilename = NULL;
  WAVE_FormatTypeDef waveformat;
  uint32_t WaveDataLength = 0;

  /* Get the read out protection status */
  if(f_opendir(&Directory, path) == FR_OK)
  {
    wavefilename = filename;

    /* Open the Wave file to be played */
    if(f_open(&FileRead, wavefilename , FA_READ) == FR_OK)
    {
      HAL_Delay(1);
      /* Read sizeof(WaveFormat) from the selected file */
      f_read (&FileRead, &waveformat, sizeof(waveformat), &bytesread);

      /* Set WaveDataLenght to the Speech Wave length */
      WaveDataLength = waveformat.FileSize;

      /* Play */

      /* Initialize  I2S */
      I2S3_Init(waveformat.SampleRate);
      /* Initialize Wave player (Codec, DMA, I2C) */
      if(WavePlayerInit(waveformat.SampleRate) != 0)
      {
        while(1);
      }
      /* Get Data from USB Flash Disk */
      f_lseek(&FileRead, 0);
      f_read (&FileRead, &Audio_Buffer[0], AUDIO_BUFFER_SIZE, &bytesread);
      AudioRemSize = WaveDataLength - bytesread;

      /* Start playing Wave */
      BSP_AUDIO_OUT_Play((uint16_t*)&Audio_Buffer[0], AUDIO_BUFFER_SIZE);
      PauseResumeStatus = RESUME_STATUS;
      PressCount = 0;

      /* Check if the device is connected.*/
      while((AudioRemSize != 0) && (Appli_state != APPLICATION_IDLE))
      {
        /* Test on the command: Playing */
        if(CmdIndex == CMD_PLAY)
        {
          if(PauseResumeStatus == PAUSE_STATUS)
          {
            /* Stop Toggling LED2 to signal Pause */
            /* Pause playing Wave */
            WavePlayerPauseResume(PauseResumeStatus);
            PauseResumeStatus = IDLE_STATUS;
          }
          else if(PauseResumeStatus == RESUME_STATUS)
          {
            /* Toggling LED6 to signal Play */
            /* Resume playing Wave */
            WavePlayerPauseResume(PauseResumeStatus);
            PauseResumeStatus = IDLE_STATUS;
          }

          bytesread = 0;

          if(buffer_offset == BUFFER_OFFSET_HALF)
          {
            f_read(&FileRead,&Audio_Buffer[0],
                   AUDIO_BUFFER_SIZE/2,(void *)&bytesread);
            buffer_offset = BUFFER_OFFSET_NONE;
          }

          if(buffer_offset == BUFFER_OFFSET_FULL)
          {
            f_read(&FileRead,&Audio_Buffer[AUDIO_BUFFER_SIZE/2],
                   AUDIO_BUFFER_SIZE/2,(void *)&bytesread);
            buffer_offset = BUFFER_OFFSET_NONE;
          }
          if(AudioRemSize > (AUDIO_BUFFER_SIZE / 2))
          {
            AudioRemSize -= bytesread;
          }
          else
          {
            /* Stop playing Wave */
            WavePlayerStop();
            f_close(&FileRead);
            HAL_I2S_DeInit(&hAudioOutI2s);
            break;
          }
        }
      }
    }
  }
}
示例#8
0
文件: main.c 项目: phaltness/32f4
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
//	int c;
   /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */     
    SystemInit();
	RCC_GetClocksFreq(&RCC_Clocks);
    SysTick_Config(SystemCoreClock / SYSTICK_FREQUENCY_HZ);

#ifdef TRACEUART
    TRACEUART_Configuration();
#endif //TRACEUART
	UART_Configuration();

	LED_Init();

	/* Output a message on Hyperterminal using printf function */
	printf("\n\r\n\r");
	printf("*** LATTICE FW LOADER V1.00 Build by phalt on ("__DATE__ "-" __TIME__ ")\n\r");
	printf("*** LATTICE FW LOADER V1.00 Rebooting ...\n\r");

	/*
     * wait for a keystroke (or a button press if you want.)
	*/
//    printf("\n\rPress Return to start, any other key To Enter the Console ...\n\r");
//	c = awaitkey(DEFAULT_BOOT_DELAY);
	if(1) 			//(((c != '\r') && (c != '\n') && (c != '\0')))
    {
		Delay(500);
		GPIO_ResetBits(BLINK_PORT, (0xF << LED1));
//		traceprintf("\rtrace start OK\n\r");
//		Codec_GPIO_Init();
//		Delay(1);
//		/* Reset the Codec Registers */
//		Codec_Reset();
//		Delay(1);
//		/* Initialize the Control interface of the Audio Codec */
//		Codec_CtrlInterface_Init();
//		Delay(1);
		if(1)
		{
	        GPIO_SetBits(BLINK_PORT, (0xF << LED1));
//	        WavePlayBack(AUDIOFREQ, 1);
	        WavePlayerInit(AUDIOFREQ);
	        GPIO_ResetBits(BLINK_PORT, (0xF << LED1));
		}
		while(1)						//eugene loop
		{
//			Codec_CtrlInterface_Init();
			GPIO_SetBits(BLINK_PORT, (0x1 << LED1));
//			Codec_Write();
			Codec_ReadRegister(0x00); //test read of codec
			GPIO_ResetBits(BLINK_PORT, (0x1 << LED1));
			Delay(1000);
		}

		if(1)									//test
		{
			init_builtin_cmds();
			serial_term();
		}


    }
	printf("*** JUMP to Application now ...\n\r");
    run_app(0x08000000);



    /* Infinite loop */
	while (1);
}