Exemplo n.º 1
0
// ------------------------------------------------------
// Convert a selection into a whole sample
int Sample_Crop(int32 range_start, int32 range_end)
{
    int32 i;
    short *NewBuffer[2];
    char nc;
    long p_s;
    long cropsize = (range_end - range_start);

    if(cropsize)
    {
        Stop_Current_Instrument();
        AUDIO_Stop();

        nc = Sample_Channels[Current_Instrument][Current_Instrument_Split];

        NewBuffer[0] = (short *) malloc(cropsize * 2 + 8);
        if(!NewBuffer[0]) return 0;
        memset(NewBuffer[0], 0, cropsize * 2 + 8);
        if(nc == 2)
        {
            NewBuffer[1] = (short *) malloc(cropsize * 2 + 8);
            if(!NewBuffer[1])
            {
                free(NewBuffer[0]);
                return 0;
            }
            memset(NewBuffer[1], 0, cropsize * 2 + 8);
        }

        p_s = 0;

        // Copy the selection
        for(i = range_start; i < range_end; i++)
        {
            *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i);
            if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i);
            p_s++;
        }

        // Set the new buffer as current sample
        if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]);
        RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0];
        Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0];
        if(nc == 2)
        {
            if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]);
            RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1];
            Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1];
        }
        Sample_Length[Current_Instrument][Current_Instrument_Split] = cropsize;

        Status_Box("Crop done.");
        AUDIO_Play();
        return 1;
    }
    return 0;
}
Exemplo n.º 2
0
/**
  * @brief  Changes the selection mode.
  * @param  select_mode: Selection mode
  * @retval None
  */
static void AUDIO_ChangeSelectMode(AUDIO_DEMO_SelectMode select_mode)
{
  if(select_mode == AUDIO_SELECT_MENU)
  {
    AUDIO_SelectItem(AUDIO_main_menu, 0x00);
    LCD_LOG_UpdateDisplay(); 
    AudioDemo.state = AUDIO_DEMO_IDLE; 
    AUDIO_Stop();
  }
  else if(select_mode == AUDIO_PLAYBACK_CONTROL)
  {
    LCD_ClearTextZone();
    AUDIO_SelectItem(AUDIO_main_menu, 0xFF);     
  }
  AudioSeletMode = select_mode; 
  AudioDemo.select = 0;
}
Exemplo n.º 3
0
/**
  * @brief  EXTI line detection callbacks.
  * @param  GPIO_Pin: Specifies the pins connected EXTI line
  * @retval None
  */
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
  static JOYState_TypeDef JoyState = JOY_NONE;
  static uint32_t debounce_time = 0;
  
  if(GPIO_Pin == GPIO_PIN_2)
  {    
    /* Get the Joystick State */
    JoyState = BSP_JOY_GetState();
    
    /* Clear joystick interrupt pending bits */
    BSP_IO_ITClear(JOY_ALL_PINS);
    
    if(mtp_select_mode == MTP_SELECT_MENU)
    {  
      MTP_MenuProbeKey(JoyState); 
      
      switch(JoyState)
      {
      case JOY_LEFT:
        LCD_LOG_ScrollBack();
        break;
             
      case JOY_RIGHT:
        LCD_LOG_ScrollForward();
        break;          
        
      default:
        break;           
      }
    }
    else if(mtp_select_mode == MTP_PLAYBACK_CONTROL)
    {
      AUDIO_PlaybackProbeKey(JoyState);
    }
  }

  if(mtp_demo.state == MTP_DEMO_PLAYBACK)
  {
    if(GPIO_Pin == KEY_BUTTON_PIN)
    { 
      /* Prevent debounce effect for user key */
      if((HAL_GetTick() - debounce_time) > 50)
      {
        debounce_time = HAL_GetTick();
      }
      else
      {
        return;
      }
      
      /* Change the selection type */
      if(mtp_select_mode == MTP_SELECT_MENU)
      {
        MTP_ChangeSelectMode(MTP_PLAYBACK_CONTROL); 
      }
      else if(mtp_select_mode == MTP_PLAYBACK_CONTROL)
      {       
       AUDIO_Stop();
      }
    }
  }
}
Exemplo n.º 4
0
// ------------------------------------------------------
// Insert zeroes into a sample the length of the selection buffer
int Sample_InsertZero(int32 range_start, int32 range_end)
{
    int32 i;
    short *NewBuffer[2];
    char nc;
    long p_s;
    long cutsize = range_end - range_start;
    long newsize = Sample_Length[Current_Instrument][Current_Instrument_Split] + cutsize;

    if(cutsize)
    {
        Stop_Current_Instrument();
        AUDIO_Stop();

        nc = Sample_Channels[Current_Instrument][Current_Instrument_Split];

        // Allocate the destination buffer(s)
        // (We need to clear the second one as the back buffer may not be stereo).
        NewBuffer[0] = (short *) malloc(newsize * 2 + 8);
        if(!NewBuffer[0]) return 0;
        memset(NewBuffer[0], 0, newsize * 2 + 8);

        if(nc == 2)
        {
            NewBuffer[1] = (short *) malloc(newsize * 2 + 8);
            if(!NewBuffer[1])
            {
                free(NewBuffer[0]);
                return 0;
            }
            memset(NewBuffer[1], 0, newsize * 2 + 8);
        }

        p_s = 0;
        if(range_start > 0)
        {
            // Copy the original data into the new buffer
            for(i = 0; i < range_start; i++)
            {
                *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i);
                if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i);
                p_s++;
            }
        }

        // Skip a buffer of the selection's size
        p_s += cutsize;

        if((Sample_Length[Current_Instrument][Current_Instrument_Split] - range_start) > 0)
        {
            // Add the rest of the original data
            for(i = range_start; i < (int32) Sample_Length[Current_Instrument][Current_Instrument_Split]; i++)
            {
                *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i);
                if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i);
                p_s++;
            }
        }

        // Set the new buffer as current sample
        if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]);
        RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0];
        Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0];
        if(nc == 2)
        {
            if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]);
            RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1];
            Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1];
        }
        Sample_Length[Current_Instrument][Current_Instrument_Split] = newsize;

        Status_Box("Duplicate done.");
        AUDIO_Play();
        return 1;
    }
    return 0;
}
Exemplo n.º 5
0
// ------------------------------------------------------
// Cut part of a sample
int Sample_Cut(int32 range_start, int32 range_end, int do_copy)
{
    int32 i;
    short *NewBuffer[2];
    char nc;
    long p_s;
    long cutsize = (range_end - range_start);
    long newsize = Sample_Length[Current_Instrument][Current_Instrument_Split] - cutsize;

    if(newsize)
    {
        Stop_Current_Instrument();
        AUDIO_Stop();

        nc = Sample_Channels[Current_Instrument][Current_Instrument_Split];

        // Allocate the wav with the minus the block to cut
        NewBuffer[0] = (short *) malloc(newsize * 2 + 8);
        if(!NewBuffer[0]) return 0;
        memset(NewBuffer[0], 0, newsize * 2 + 8);
        if(nc == 2)
        {
            NewBuffer[1] = (short *) malloc(newsize * 2 + 8);
            if(!NewBuffer[1])
            {
                free(NewBuffer[0]);
                return 0;
            }
            memset(NewBuffer[1], 0, newsize * 2 + 8);
        }

        if(do_copy)
        {
            if(!Sample_Copy(range_start, range_end))
            {
                free(NewBuffer[1]);
                free(NewBuffer[0]);
                return 0;
            }
        }

        p_s = 0;
        if(range_start > 0)
        {
            // Copy the data located before the range start
            for(i = 0; i < range_start; i++)
            {
                *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i);
                if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i);
                p_s++;
            }
        }

        if((Sample_Length[Current_Instrument][Current_Instrument_Split] - range_end) > 0)
        {
            // Add the data located after the range end
            for(i = range_end; i < (int32) Sample_Length[Current_Instrument][Current_Instrument_Split]; i++)
            {
                *(NewBuffer[0] + p_s) = *(RawSamples[Current_Instrument][0][Current_Instrument_Split] + i);
                if(nc == 2) *(NewBuffer[1] + p_s) = *(RawSamples[Current_Instrument][1][Current_Instrument_Split] + i);
                p_s++;
            }
        }

        // Set the new buffer as current sample
        if(RawSamples[Current_Instrument][0][Current_Instrument_Split]) free(RawSamples[Current_Instrument][0][Current_Instrument_Split]);
        RawSamples[Current_Instrument][0][Current_Instrument_Split] = NewBuffer[0];
        Player_WL[Current_Instrument][Current_Instrument_Split] = NewBuffer[0];
        if(nc == 2)
        {
            if(RawSamples[Current_Instrument][1][Current_Instrument_Split]) free(RawSamples[Current_Instrument][1][Current_Instrument_Split]);
            RawSamples[Current_Instrument][1][Current_Instrument_Split] = NewBuffer[1];
            Player_WR[Current_Instrument][Current_Instrument_Split] = NewBuffer[1];
        }
        Sample_Length[Current_Instrument][Current_Instrument_Split] = newsize;

        Status_Box("Cut done.");
        AUDIO_Play();
        return 1;
    }
    else
    {
        if(do_copy)
        {
            Status_Box("You cannot cut entire sample, use 'delete' on instrument instead.");
        }
        else
        {
            Status_Box("You cannot zap entire sample, use 'delete' on instrument instead.");
        }
        return 0;
    }
}