Пример #1
0
void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
{
  /* Calculate the remaining audio data in the file and the new size
  for the DMA transfer. If the Audio files size is less than the DMA max
  data transfer size, so there is no calculation to be done, just restart
  from the beginning of the file ... */
  /* Check if the end of file has been reached */

#ifdef AUDIO_MAL_MODE_NORMAL
//  XferCplt = 1;
//  if (WaveDataLength) WaveDataLength -= _MAX_SS;
//  if (WaveDataLength < _MAX_SS) WaveDataLength = 0;
  if(fifoBufferFullness < 1) {
	  /* play padding instead of real stream */
	  Audio_MAL_Play((uint32_t)padBuffer, (SPEAKER_FREQ/MIC_FREQ)*320*2*sizeof(short));
	  //EVAL_AUDIO_Play(padBuffer, (320*(SPEAKER_FREQ/MIC_FREQ))*2*sizeof(short));
	  //STM_EVAL_LEDToggle(LED4);
	  //printf("!");
  } else {
	  Audio_MAL_Play((uint32_t)fifoBuffer[fifoBufferCurrent], (SPEAKER_FREQ/MIC_FREQ)*320*2*sizeof(short));
	  //EVAL_AUDIO_Play(fifoBuffer[fifoBufferCurrent], (SPEAKER_FREQ/MIC_FREQ)*320*2*sizeof(short));
	  fifoBufferFullness--;
	  fifoBufferCurrent++;
	  if(fifoBufferCurrent >= MODULATOR_QUEUE_SIZE)
		  fifoBufferCurrent=0;

	  if(volume_set==0)
		  volume_set=1;
  }

#else /* #ifdef AUDIO_MAL_MODE_CIRCULAR */


#endif /* AUDIO_MAL_MODE_CIRCULAR */
}
Пример #2
0
void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
{

    STM_EVAL_LEDOn(LED4);
    if(nextbuf == 0) { ;
        Audio_MAL_Play((uint32_t)buf0, MY_BUFSIZE);
        nextbuf = 1;
    } else {
        Audio_MAL_Play((uint32_t)buf1, MY_BUFSIZE);
        nextbuf = 0;
    }
}
Пример #3
0
//-------------------------------------------------------------------
// Musicplayer_Init
//-------------------------------------------------------------------
void vInitMusicplayer (void)
{
  // Initialize Audio interface
  EVAL_AUDIO_SetAudioInterface( AUDIO_INTERFACE_I2S );
  EVAL_AUDIO_Init( OUTPUT_DEVICE_BOTH, 60, I2S_AudioFreq_48k );    // Volume 80%, 44Khz samplefrequentie
  Audio_MAL_Play((uint32_t)AUDIO_SAMPLE, sizeof(AUDIO_SAMPLE) );  // Speel stilte, waarover de toongenerator de toon speelt
  EVAL_AUDIO_PauseResume(AUDIO_RESUME);                            // Start met spelen
  
  // Motor init
  motor_init();
  
  // User button init
  GPIO_InitTypeDef GPIO_InitStructure;
  
#if 0
  EXTI_InitTypeDef EXTI_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
#endif 
  
  /* Enable the BUTTON Clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  /* Configure Button pin as input */
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

#if 0
    /* Connect Button EXTI Line to Button GPIO Pin */
    SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

    /* Configure Button EXTI line */
    EXTI_InitStructure.EXTI_Line = EXTI_Line2;
    EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
    EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;  
    EXTI_InitStructure.EXTI_LineCmd = ENABLE;
    EXTI_Init(&EXTI_InitStructure);

    /* Enable and set Button EXTI Interrupt to the lowest priority */
    NVIC_InitStructure.NVIC_IRQChannel = EXTI2_IRQn;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

    NVIC_Init(&NVIC_InitStructure); 
#endif
  
  
  // Motor test
  // Dit staat hier omdat een van de andere init's niet werkt zonder evdk
  //motor_init();
  //setLedBlink();
  //{int i; for(i=0;i<1000000;i++);}  // Small delay for the motor control board to accept the previous command
  //// Motor ייn rondje
  //SMC_step(1600,1,1000,1);

  
}
Пример #4
0
uint32_t AUDIO_Play(u16* pBuffer, u32 Size)
{
  	AudioTotalSize=Size; 
  	Audio_MAL_Play((u32)pBuffer,(u32)(DMA_MAX(Size/4)));//??????????
  	AudioRemSize=(Size/2)-DMA_MAX(AudioTotalSize);//???????
  	CurrentPos=pBuffer+DMA_MAX(AudioTotalSize);//???????? 
  	return 0;
}
Пример #5
0
void Wavplay(void)
{
	FATFS fatfs;            
	FIL fileR;
	UINT BytesRead;	
	u8 i=0;

  	f_mount(0, &fatfs);
 
	f_open(&fileR, "0:/wav/1.wav" , FA_READ);
	f_read(&fileR, buffer1, 1024, &BytesRead);
	while(WaveParsing()) printf("file read error");

  	WaveLen = WAVE_Format.DataSize;
  	AUDIO_Init(WAVE_Format.SampleRate);
  	f_lseek(&fileR, WaveCounter);//跳过文件头
  	f_read(&fileR, buffer1, 1024, &BytesRead); 
  	f_read(&fileR, buffer2, 1024, &BytesRead);
  	Audio_MAL_Play((u32)buffer1, 1024);
  	buffer_switch=1;
  	XferCplt=0;  
  	while(WaveLen!=0)
  	{ 
      	while(XferCplt==0);
      	XferCplt=0;
      	if(buffer_switch==0)
      	{
        	Audio_MAL_Play((u32)buffer1,1024);//从buffer1播放
        	f_read(&fileR,buffer2,1024,&BytesRead);//填充buffer2
        	buffer_switch=1;
      	}
      	else 
      	{   
        	Audio_MAL_Play((u32)buffer2,1024);//从buffer2播放
        	f_read(&fileR,buffer1,1024,&BytesRead);//填充buffer1
        	buffer_switch=0;
      	} 
		i++;
		if(i==100)
		{
			i=0;
		}
  	}
}
Пример #6
0
void wav_play(void)
{
	u32 index = 0;
	u8 i=0;
	
	WaveLen = 0;
	XferCplt = 0;
	DataOffset = 0;
	buffer_switch = 1;
	
	index = DataOffset;
	
	flash_bytes_read(index, (u8 *)buffer1, 1024);
	index += 1024;
	flash_bytes_read(index, (u8 *)buffer2, 1024);
	
  	Audio_MAL_Play((u32)buffer1, 1024);
  	buffer_switch=1;
  	XferCplt=0;  
  	while(WaveLen!=0)
  	{ 
	      	while(XferCplt==0);//??DMA????
	      	XferCplt=0;
	      	if(buffer_switch==0)
	      	{
		        	Audio_MAL_Play((u32)buffer1,1024);//?buffer1??
					index += 1024;
		        	flash_bytes_read(index, (u8 *)buffer2, 1024);
		        	buffer_switch=1;
	      	}
	      	else 
	      	{   
		        	Audio_MAL_Play((u32)buffer2,1024);//?buffer2??
					index += 1024;
		        	flash_bytes_read(index, (u8 *)buffer1, 1024);
		        	buffer_switch=0;
	      	} 
		i++;
  	}
}
Пример #7
0
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);
    };

}
Пример #8
0
/**
  * @brief Starts playing audio stream from a data buffer for a determined size. 
  * @param pBuffer: Pointer to the buffer 
  * @param Size: Number of audio data BYTES.
  * @retval o if correct communication, else wrong communication
  */
uint32_t EVAL_AUDIO_Play(uint16_t* pBuffer, uint32_t Size)
{
  /* Set the total number of data to be played (count in half-word) */
  AudioTotalSize = Size/2;

  /* Call the audio Codec Play function */
  Codec_Play();
  
  /* Update the Media layer and enable it for play */  
  Audio_MAL_Play((uint32_t)pBuffer, (uint32_t)(DMA_MAX(AudioTotalSize / 2)));
  
  /* Update the remaining number of data to be played */
  AudioRemSize = (Size/2) - DMA_MAX(AudioTotalSize);
  
  /* Update the current audio pointer position */
  CurrentPos = pBuffer + DMA_MAX(AudioTotalSize);
  
  return 0;
}
/**
  * @brief  AudioCmd 
  *         Play, Stop, Pause or Resume current file.
  * @param  pbuf: address from which file shoud be played.
  * @param  size: size of the current buffer/file.
  * @param  cmd: command to be executed, can be AUDIO_CMD_PLAY , AUDIO_CMD_PAUSE, 
  *              AUDIO_CMD_RESUME or AUDIO_CMD_STOP.
  * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else.
  */
static uint8_t  AudioCmd(uint8_t* pbuf, 
                         uint32_t size,
                         uint8_t cmd)
{
  /* Check the current state */
  if ((AudioState == AUDIO_STATE_INACTIVE) || (AudioState == AUDIO_STATE_ERROR))
  {
    AudioState = AUDIO_STATE_ERROR;
    return AUDIO_FAIL;
  }
  
  switch (cmd)
  {
    /* Process the PLAY command ----------------------------*/
  case AUDIO_CMD_PLAY:
    /* If current state is Active or Stopped */
    if ((AudioState == AUDIO_STATE_ACTIVE) || \
       (AudioState == AUDIO_STATE_STOPPED) || \
       (AudioState == AUDIO_STATE_PLAYING))
    {
      Audio_MAL_Play((uint32_t)pbuf, (size/2));
      AudioState = AUDIO_STATE_PLAYING;
      return AUDIO_OK;
    }
    /* If current state is Paused */
    else if (AudioState == AUDIO_STATE_PAUSED)
    {
      if (EVAL_AUDIO_PauseResume(AUDIO_RESUME /*, (uint32_t)pbuf, (size/2)*/) != 0)
      {
        AudioState = AUDIO_STATE_ERROR;
        return AUDIO_FAIL;
      }
      else
      {
        AudioState = AUDIO_STATE_PLAYING;
        return AUDIO_OK;
      } 
    } 
    else /* Not allowed command */
    {
      return AUDIO_FAIL;
    }
    
    /* Process the STOP command ----------------------------*/
  case AUDIO_CMD_STOP:
    if (AudioState != AUDIO_STATE_PLAYING)
    {
      /* Unsupported command */
      return AUDIO_FAIL;
    }
    else if (EVAL_AUDIO_Stop(CODEC_PDWN_SW) != 0)
    {
      AudioState = AUDIO_STATE_ERROR;
      return AUDIO_FAIL;
    }
    else
    {
      AudioState = AUDIO_STATE_STOPPED;
      return AUDIO_OK;
    }
  
    /* Process the PAUSE command ---------------------------*/
  case AUDIO_CMD_PAUSE:
    if (AudioState != AUDIO_STATE_PLAYING)
    {
      /* Unsupported command */
      return AUDIO_FAIL;
    }
    else if (EVAL_AUDIO_PauseResume(AUDIO_PAUSE /*, (uint32_t)pbuf, (size/2)*/) != 0)
    {
      AudioState = AUDIO_STATE_ERROR;
      return AUDIO_FAIL;
    }
    else
    {
      AudioState = AUDIO_STATE_PAUSED;
      return AUDIO_OK;
    } 
    
    /* Unsupported command ---------------------------------*/
  default:
    return AUDIO_FAIL;
  }  
}
Пример #10
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. */  

  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

}
Пример #11
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
*/
int main(void)
{
  /* Initialize LEDS */
  /* Red Led On: buffer overflow */
  STM_EVAL_LEDInit(LED3);
  /* Green Led On: fdmdv+codec2 enabled */
  STM_EVAL_LEDInit(LED4);
  STM_EVAL_LEDInit(LED5);
  /* Blue Led On: start of application */
  STM_EVAL_LEDInit(LED6);

  STM_EVAL_LEDOn(LED6);

  /* transparent mode switcher */
  STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_EXTI);

  if(Transparent_mode)
	  STM_EVAL_LEDOff(LED4);
  else
	  STM_EVAL_LEDOn(LED4);

  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  USART_InitTypeDef USART_InitStructure;
  USART_InitStructure.USART_BaudRate = 115200;
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
  USART_InitStructure.USART_Parity = USART_Parity_No;
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  STM_EVAL_USART2Init(&USART_InitStructure);

  // turn off buffers, so IO occurs immediately
  setvbuf(stdin, NULL, _IONBF, 0);
  setvbuf(stdout, NULL, _IONBF, 0);
  setvbuf(stderr, NULL, _IONBF, 0);

  /* Output a message on Hyperterminal using printf function */
  printf("\r\nFloating-Point Based Codec2 encoder for Cortex-M4F\r\n");
  /* Configure TIM4 Peripheral to manage LEDs lighting */

  unsigned int idx = 0;
  Time_Rec_Base=0;
  int i, buffId;

  codec2_initialize_all(SPEAKER_FREQ == 48000 ? 1 : 0);

  /* fill output fifo */
  fifoBufferFullness=0;
  fifoBufferCurrent=0;
  Switch = 0;

  /* modulate silence once for padding if happens */
  memset(padBuffer, 0x00, (320*(SPEAKER_FREQ/MIC_FREQ)*2)*sizeof(short));
  memset(fifoBuffer, 0x00, MODULATOR_QUEUE_SIZE * (SPEAKER_FREQ/MIC_FREQ)*320*2*sizeof(short));
  //codec2_modulate((short *) padBuffer, (short *) padBuffer, Transparent_mode);

  /* Initialize I2S interface */
  EVAL_AUDIO_SetAudioInterface(AUDIO_INTERFACE_I2S);
  /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */
  //EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 0, SPEAKER_FREQ);
  EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, 0, SPEAKER_FREQ);
  EVAL_AUDIO_PauseResume(AUDIO_PAUSE);
  Audio_MAL_Play((uint32_t) padBuffer, (320*(SPEAKER_FREQ/MIC_FREQ))*2*sizeof(short));
  EVAL_AUDIO_PauseResume(AUDIO_RESUME);

  /* Start the record */
  MicListenerInit(32000,16, 1);
  MicListenerStart(RecBuf_8Khz, PCM_OUT_SIZE);

  /* GLOBAL SCHEDULER
   * DO NOT USE LOOPS INSIDE IT!
   * */
  while(1) {
	  /* we have frame from mike */
	  if(Data_Status == 0)
		  continue;

	  /* Switch the buffers*/
	  if (Switch ==1) {
		pAudioRecBuf_8Khz = RecBuf_8Khz;
		writebuffer = RecBuf1_8Khz;
		Switch = 0;
	  } else {
		pAudioRecBuf_8Khz = RecBuf1_8Khz;
		writebuffer = RecBuf_8Khz;
		Switch = 1;
	  }

#ifdef USE_ST_FILTER
	  //Downsampling 16Khz => 8Khz (this is input for codec, it sampled with 8KHz)
	  for(i=0; i<320; i++)
	      writebuffer[i] = writebuffer[2*i];
#endif

	  //TODO: modulate, even if no data from mike!
	  if(fifoBufferFullness < MODULATOR_QUEUE_SIZE-1) {
		  /* get the next free buffer */
		  buffId = fifoBufferCurrent + fifoBufferFullness;
		  if(buffId >= MODULATOR_QUEUE_SIZE) buffId -= MODULATOR_QUEUE_SIZE;
		  assert(buffId >= 0 && buffId < MODULATOR_QUEUE_SIZE);
		  codec2_modulate((short *) writebuffer, (short *) fifoBuffer[buffId], Transparent_mode);
		  fifoBufferFullness++;
		  if(idx % 32 == 0) printf(".");
		  if(idx % (32*32) == 0) printf("\r\n");

		  /* this is hack to remove loud noise at startup */
		  if(volume_set==1) {
			  STM_EVAL_LEDOff(LED3);
			  EVAL_AUDIO_VolumeCtl(90);
			  volume_set=2;
		  }
	  } else {
		  STM_EVAL_LEDToggle(LED3);
		  printf("x");
		  if(idx % (32) == 0) printf("\r\n");
	  }

	  idx++;
      Data_Status = 0;
  }

  EVAL_AUDIO_Mute(AUDIO_MUTE_ON);
  EVAL_AUDIO_Stop(CODEC_PDWN_HW);
  MicListenerStop();

  //float samples_time = idx*samplesPerFrame/((float) WAVE_Format.NumChannels*WAVE_Format.SampleRate);
#if 0
  float samples_time = idx*mod->samplesPerFrame/((float) 1*MIC_FREQ);
  float cpu_time = Time_Rec_Base/((float ) 100);
  printf("\r\n%8.3f s audio file encoded in %8.3f s\r\n", (double) samples_time, (double) cpu_time);
#endif
  while(1) {
	STM_EVAL_LEDToggle(LED5);
    Delay(10);
  }
}
Пример #12
0
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
}
Пример #13
0
//-------------------------------------------------------------------
// Audio driver callback funtie
//-------------------------------------------------------------------
void EVAL_AUDIO_TransferComplete_CallBack(uint32_t pBuffer, uint32_t Size)
{
  Audio_MAL_Play((uint32_t)AUDIO_SAMPLE, sizeof(AUDIO_SAMPLE) );
}
Пример #14
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

}