Skip to main content
Visitor II
April 14, 2021
Question

Voice recorder with STM32F7 as .wav and on SD card

  • April 14, 2021
  • 3 replies
  • 3052 views

I want to make voice recorder with STM32F7 and save voice as .wav in SD card. before this one, i tried to save audio samples as .txt file, but during save them in sd card by FAT, some sample has been lost. therefore i try to another way. Please help me!

    This topic has been closed for replies.

    3 replies

    Graduate II
    April 14, 2021

    Files just contain collections of 8-bit bytes, FATFS/SDMMC has no interest in the content and file extensions.

    For efficiency, and due to lack of buffering/caching, you want to write large blocks of data that are naturally aligned to the sector/cluster sizes on the media.

    Some power of 2 block size in the 8KB to 32KB is suggested.

    MMosa.1Author
    Visitor II
    April 14, 2021

    can you explain more about that?

    This subject is too new for me!

    Graduate II
    April 14, 2021

    Suggest reviewing college level texts on

    Block Storage Systems

    Block based File Systems

    Data Storage methods on Magnetic, Optical and Solid State mediums

    Data Representation

    Understand

    That it's just data, the computer has no real care about what it represents, beyond how it manages bytes and word, and the forms of floating point representation other logic is managing directly, ie via a FPU

    Accessing block storage is relatively slow, as information has to be fetched or stored on a larger level. There are significant latency and response times involved, and efficiency is achieved by fetching the most amount of data in the least number of transactions. And also by avoiding crossing boundaries which instantly double the effort, which could be readily avoided with thought and planning.

    MMosa.1Author
    Visitor II
    April 14, 2021

    Previously I use FAT and store samples immediately in each sample in txt file. in this method I

    don't lost any data but because of reason that you say f_write function change my sample rate. I tried to do that with DMA but it was unsuccessful. I think DMA can help me, but DMA with FAT is not working for me. I attached my code to more information.

    uint8_t MIC_Voice_Store[200000];
     long int MIC_Store_Counter=0;
     int MIC_flag=0;
     
     
     char Name_buffer[30];
     int MIC_File_Counter=0;
     
     char buf[4];
     char try[4];
     int savecounter=0;
     extern char SDPath[4]; 
     extern FATFS SDFatFS; 
     extern FIL SDFile; 
     UINT myBytes;
     FRESULT result;
     
     
    sprintf(Name_buffer,"MIC_%d.TXT",MIC_File_Counter); 
    result=f_mount(&SDFatFS,SDPath,1);
     
     while (1)
     {
     
     if(MIC_Ready==1)
     {
     
     HAL_TIM_Base_Start_IT(&htim1);
     if(MIC_flag==1)
     { 
     if(f_open(&SDFile,Name_buffer, FA_WRITE | FA_OPEN_APPEND) == FR_OK)
     {
     for (savecounter=0; savecounter<100000; savecounter++)
     {
     buf[0]=((MIC_Voice_Store[savecounter]/100)%10)+48;
     buf[1]=((MIC_Voice_Store[savecounter]/10)%10)+48;
     buf[2]=(MIC_Voice_Store[savecounter]%10)+48;
     
     result=f_lseek(&SDFile,f_size(&SDFile));
     result=f_write(&SDFile,buf,sizeof(buf),&myBytes);
     
     }
     result=f_close(&SDFile);
     } 
     MIC_File_Counter++;
     MIC_flag=0;
     MIC_Store_Counter=0;
     }
     MIC_Ready=0;
     }
     
     
    }
     
    }
     
    void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
    {
    if(htim->Instance==TIM1)
     {
     if(MIC_Ready==0)
     {
     HAL_ADC_Start(&hadc2);
     MIC_Voice=HAL_ADC_GetValue(&hadc2);
     if(MIC_Store_Counter<100000)
     {
     MIC_Voice_Store[MIC_Store_Counter]=MIC_Voice;
     MIC_Store_Counter++;
     }
     else
     {
     
     MIC_flag=1;
     } 
     
     MIC_Ready=1;
     }
     }
    }

    Visitor II
    April 14, 2021

    Hi MMosa.1,

    Please refer to the STM32CubeF7 under the following directories:

    • Projects\$board_name$\Applications\FatFs
    • Projects\$board_name$\Applications\Audio: You can find the Audio_playback_and_record application that allows to record a .wav file, store it into a usb and play it.

    Wish these help you.

    Best Regards,

    Ons.