Esempio n. 1
0
//--------------------------------- toggle ON/OFF volume ------------------------------------------
void toggleSound(void)
{
	if ( ! sound )
	{
		//pitchGenResetPhase();
		EVAL_AUDIO_VolumeCtl(volume);
		sound = true;
	}
	else
	{
		EVAL_AUDIO_VolumeCtl(0);
		sound = false;
	}
}
Esempio n. 2
0
//-------------------------------- decrease output DAC volume ------------------------------------------
void decVol(void)
{
	if (volume > 0)
	{
		volume--;
		EVAL_AUDIO_VolumeCtl(volume);
	}
}
Esempio n. 3
0
//------------------------------- increase output DAC volume --------------------------------------------
void incVol(void)
{
	if (volume < MAXVOL)
	{
		volume++;
		EVAL_AUDIO_VolumeCtl(volume);
	}
}
/**
  * @brief  VolumeCtl
  *         Set the volume level in %
  * @param  vol: volume level to be set in % (from 0% to 100%)
  * @retval AUDIO_OK if all operations succeed, AUDIO_FAIL else.
  */
static uint8_t  VolumeCtl    (uint8_t vol)
{
  /* Call low layer volume setting function */  
  if (EVAL_AUDIO_VolumeCtl(vol) != 0)
  {
    AudioState = AUDIO_STATE_ERROR;
    return AUDIO_FAIL;
  }
  
  return AUDIO_OK;
}
Esempio n. 5
0
// little function to handle arturia minilab rotary encoder relative mode 2 midi data
// it's quick and dirty, should probably write a function to handle all 3 types of encoder data
void inc_dec_volume(uint8_t val){
  if (val <= 0x0F){
           volume = volume + val;
           if (volume > MAXVOL){
     volume = MAXVOL;
     }
  }

if (val >= 0x70){
    val=128-val; // to get a value between 0-15
    int minVol = volume-val; // couldn't think of a name for minvol!
    volume=volume-val;

  if (minVol < 0 || volume > 100){ // minimum volume?
    volume = 0; // set it to the minimum volume
    }
  }

if (lastvol != volume){ // don't keep spamming the synth engine if it's the same value
EVAL_AUDIO_VolumeCtl(volume);
lastvol = volume;
}
}
Esempio n. 6
0
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{ 
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f4xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f4xx.c file
     */
  
  /* Initialize LEDs, Key Button, LCD available on
     STM324xG-EVAL board ******************************************************/
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);
  STM_EVAL_LEDInit(LED3);
  STM_EVAL_LEDInit(LED4);

  /* Initialize the Push buttons */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);     /* Key button for Pause/Resume */
  STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO);  /* Key button for Volume High */
  STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_GPIO);  /* Key button for Volume Low */
    
  /* Initialize the LCD */
  STM324xG_LCD_Init();
  
  /* Display message on STM324xG-EVAL LCD *************************************/
  /* Clear the LCD */ 
  LCD_Clear(LCD_COLOR_BLUE);  

  /* Set the LCD Back Color */
  LCD_SetBackColor(Blue);
  /* Set the LCD Text Color */
  LCD_SetTextColor(White);
  LCD_DisplayStringLine(Line0, MESSAGE1);
  LCD_DisplayStringLine(Line1, MESSAGE2);
  LCD_DisplayStringLine(Line2, MESSAGE3);

  /* Turn on leds available on STM324xG-EVAL **********************************/
  STM_EVAL_LEDOn(LED1);
  STM_EVAL_LEDOn(LED2);
  STM_EVAL_LEDOn(LED3);
  STM_EVAL_LEDOn(LED4);

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

  /* Initialize the Audio codec and all related peripherals (I2S, I2C, IOExpander, IOs...) */  
  if (EVAL_AUDIO_Init(OUTPUT_DEVICE_AUTO, volume, I2S_AudioFreq_48k) == 0)
  {
    LCD_DisplayStringLine(Line3, "====================");
    LCD_DisplayStringLine(Line4, "Key   : Play/Pause ");
    LCD_DisplayStringLine(Line5, "Tamper: Vol+/Headph");
    LCD_DisplayStringLine(Line6, "Wakeup: Vol-/Spkr  ");
    LCD_DisplayStringLine(Line7, "====================");
    LCD_DisplayStringLine(Line8, "  AUDIO CODEC   OK  ");    
  }
  else
  {
    LCD_DisplayStringLine(Line4, "  AUDIO CODEC  FAIL ");
    LCD_DisplayStringLine(Line5, " Try to reset board ");
  }
  
  
  /* 
  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. */
  EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUIDO_START_ADDRESS), (AUDIO_FILE_SZE - AUIDO_START_ADDRESS));
 
  /* Display the state on the screen */
  LCD_DisplayStringLine(Line8, "       PLAYING      ");
  
  /* Infinite loop */
  while (1)
  {    
    /* Check on the Pause/Resume button */
    if (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET)
    {
      /* wait to avoid rebound */
      while (STM_EVAL_PBGetState(BUTTON_KEY) != Bit_SET);
      
      EVAL_AUDIO_PauseResume(cmd);
      if (cmd == AUDIO_PAUSE)
      {
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line8, "       PAUSED       ");
        
        /* Next time Resume command should be processed */
        cmd = AUDIO_RESUME;
        
        /* Push buttons will be used to switch between Speaker and Headphone modes */
        SpHpSwitch = 1;
      }
      else
      {
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line8, "       PLAYING      ");
        
        /* Next time Pause command should be processed */
        cmd = AUDIO_PAUSE;
        
        /* Push buttons will be used to control volume level */
        SpHpSwitch = 0;
      }
    }
    
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET)
    {
      /* Check if the current state is paused (push buttons are used for volume control or for 
         speaker/headphone mode switching) */
      if (SpHpSwitch)
      {
        /* Set output to Speaker */
        Codec_SwitchOutput(OUTPUT_DEVICE_SPEAKER);
        
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line9, "       SPEAKER      ");
      }
      else
      {
        /* wait to avoid rebound */
        while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET);
        
        /* Decrease volume by 5% */
        if (volume > 5)
          volume -= 5; 
        else
          volume = 0; 
        
        /* Apply the new volume to the codec */
        EVAL_AUDIO_VolumeCtl(volume);
        LCD_DisplayStringLine(Line9, "       VOL:   -     ");
      }
    }    
    
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET)
    {
      /* Check if the current state is paused (push buttons are used for volume control or for 
         speaker/headphone mode switching) */
      if (SpHpSwitch)
      {
        /* Set output to Headphone */
        Codec_SwitchOutput(OUTPUT_DEVICE_HEADPHONE);
        
        /* Display the current state of the player */
        LCD_DisplayStringLine(Line9, "      HEADPHONE     ");
      }
      else
      {
        /* wait to avoid rebound */
        while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET);
        
        /* Increase volume by 5% */
        if (volume < 95)
          volume += 5; 
        else
          volume = 100; 
        
        /* Apply the new volume to the codec */
        EVAL_AUDIO_VolumeCtl(volume);
        LCD_DisplayStringLine(Line9, "       VOL:   +     ");  
      }
    }  
    
    /* Toggle LD4 */
    STM_EVAL_LEDToggle(LED3);

    /* Insert 50 ms delay */
    Delay(5);

    /* Toggle LD2 */
    STM_EVAL_LEDToggle(LED2);

    /* Insert 50 ms delay */
    Delay(5);
  }
}
/**
 * @brief  Configure the volune
 * @param  vol: volume value
 * @retval None
 */
uint8_t WaveplayerCtrlVolume(uint8_t vol)
{ 
  EVAL_AUDIO_VolumeCtl(vol);
  return 0;
}
Esempio n. 8
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);
  }
}
Esempio n. 9
0
void Volume_set(uint8_t val)
{
	volume = (uint8_t)(MAXVOL/MIDI_MAX * val);
	EVAL_AUDIO_VolumeCtl(volume);
}
Esempio n. 10
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       files (startup_stm32f429_439xx.s) before to branch to application main.
     */ 
  
  /* SysTick end of count event each 10ms */
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);
  
  /* Initialize LEDs mounted on EVAL board */
  STM_EVAL_LEDInit(LED1);
  STM_EVAL_LEDInit(LED2);

  /* KEY button for Volume High */
  STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_GPIO);
  
  /* WAKEUP button for Volume Low */  
  STM_EVAL_PBInit(BUTTON_WAKEUP, BUTTON_MODE_GPIO); 
  
  /* Configure PLLSAI */
  PLLSAI_Config();
  
  /* Initialize the Audio codec and all related peripherals (SAI, I2C, IOs...) */  
  if (EVAL_AUDIO_Init(OUTPUT_DEVICE_BOTH, uwVolume, SAI_AudioFreq_48k) == 0)
  {
    /* AUDIO CODEC OK */
    STM_EVAL_LEDOn(LED1);
  }
  else
  {
    /* AUDIO CODEC FAIL */ 
    STM_EVAL_LEDOn(LED2);
  }
  /* Insert 50 ms delay */
  Delay(5);
  
  /* Play audio sample stored in internal FLASH */
  EVAL_AUDIO_Play((uint16_t*)(AUDIO_SAMPLE + AUDIO_START_ADDRESS), (AUDIO_FILE_SIZE - AUDIO_START_ADDRESS));
 
  /* Infinite loop */
  while(1)
  {
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET)
    {
      /* Wait to avoid rebound */
      while (STM_EVAL_PBGetState(BUTTON_TAMPER) != Bit_SET);
      
      /* Increase volume by 5% */
      if (uwVolume < 95)
      {
        uwVolume += 5;
      } 
      else
      {
        uwVolume = 100; 
      }
      /* Apply the new volume to the codec */
      EVAL_AUDIO_VolumeCtl(uwVolume);
    }
    /* Check on the Volume high button */
    if (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET)
    {
      /* Wait to avoid rebound */
      while (STM_EVAL_PBGetState(BUTTON_WAKEUP) == Bit_SET);
      
      /* Decrease volume by 5% */
      if (uwVolume > 5)
      {
        uwVolume -= 5;
      } 
      else
      {
        uwVolume = 0; 
       }
      /* Apply the new volume to the codec */
      EVAL_AUDIO_VolumeCtl(uwVolume);
    }
    
  } 
}