cancel
Showing results for 
Search instead for 
Did you mean: 

Voice recorder with STM32F7 as .wav and on SD card

MMosa.1
Associate II

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!

6 REPLIES 6

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
MMosa.1
Associate II

can you explain more about that?

This subject is too new for me!

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

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;
        }
   }
}

Ons KOOLI
Senior III

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.

seeking and writing 4 bytes at a time will be hugely inefficient.

Seek Once

Write All the Data in a Single Action

Store the data in a binary form

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..