예제 #1
0
/**
  * @brief  Encoder initialization.
  * @param  Freq: Sampling frequency.
  * @param  pHeader: Pointer to the WAV file header to be written.  
  * @retval 0 if success, !0 else.
  */
uint32_t WavProcess_EncInit(uint32_t Freq, uint8_t* pHeader)
{  
  if (WavEncInited)
  {
    return 1;
  }
  
  /* Initialize the encoder structure */
  EncWavFmtStruct.SampleRate = Freq;        /* Audio sampling frequency */
  EncWavFmtStruct.NumChannels = 2;          /* Number of channels: 1:Mono or 2:Stereo */
  EncWavFmtStruct.BitsPerSample = 16;       /* Number of bits per sample (16, 24 or 32) */
  EncWavFmtStruct.AudioLength = 0;          /* Total length of useful audio data (payload) */
  EncWavFmtStruct.AudioStartAddr = 44;      /* Relative start address of audio payload */
  EncWavFmtStruct.RIFFchunksize = 44;       /* The file header chunk size */
  EncWavFmtStruct.FormatTag = 1;            /* Audio file format: PCM = 1 */
  EncWavFmtStruct.ByteRate = (EncWavFmtStruct.SampleRate * \
                           (EncWavFmtStruct.BitsPerSample/8) * \
                           EncWavFmtStruct.NumChannels);            /* Number of bytes per second  (sample rate * block align)  */
  EncWavFmtStruct.BlockAlign = EncWavFmtStruct.NumChannels * \
                            (EncWavFmtStruct.BitsPerSample/8);      /* channels * bits/sample / 8 */
  EncWavFmtStruct.DataSize = 0;             /* Total length of useful audio data (payload) */
    
  /* Parse the wav file header and extract required information */
  if (WavProcess_HeaderInit(pHeader, &EncWavFmtStruct))
  {
    return 1;
  }

  WavEncInited = 1;
  
  return 0;
}
예제 #2
0
/**
  * @brief  Encoder initialization.
  * @param  Freq: Sampling frequency.
  * @param  pHeader: Pointer to the WAV file header to be written.
  * @retval 0 if success, !0 else.
  */
static uint32_t WavProcess_EncInit(uint32_t Freq, uint8_t* pHeader)
{
    /* Initialize the encoder structure */
    WaveFormat.SampleRate = Freq;        /* Audio sampling frequency */
    WaveFormat.NbrChannels = 2;          /* Number of channels: 1:Mono or 2:Stereo */
    WaveFormat.BitPerSample = 16;        /* Number of bits per sample (16, 24 or 32) */
    WaveFormat.FileSize = 0x001D4C00;    /* Total length of useful audio data (payload) */
    WaveFormat.SubChunk1Size = 44;       /* The file header chunk size */
    WaveFormat.ByteRate = (WaveFormat.SampleRate * \
                           (WaveFormat.BitPerSample/8) * \
                           WaveFormat.NbrChannels);            /* Number of bytes per second  (sample rate * block align)  */
    WaveFormat.BlockAlign = WaveFormat.NbrChannels * \
                            (WaveFormat.BitPerSample/8);      /* channels * bits/sample / 8 */

    /* Parse the wav file header and extract required information */
    if(WavProcess_HeaderInit(pHeader, &WaveFormat))
    {
        return 1;
    }
    return 0;
}