libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::WavWriter< transfer_size > Class Template Reference

Detailed Description

template<size_t transfer_size>
class daisy::WavWriter< transfer_size >

Audio Recording Module

Record audio into a working buffer that is gradually written to a WAV file on an SD Card.

Recordings are made with floating point input, and will be converted to the specified bits per sample internally

For now only 16-bit and 32-bit (signed int) formats are supported f32 and s24 formats will be added next

The transfer size determines the amount of internal memory used, and can have an effect on the performance of the streaming behavior of the WavWriter. Memory use can be calculated as: (2 * transfer_size) bytes Performance optimal with sizes: 16384, 32768

To use:

  1. Create a WavWriter<size> object (e.g. WavWriter<32768> writer)
  2. Configure the settings as desired by creating a WavWriter<32768>::Config struct and setting the settings.
  3. Initialize the object with the configuration struct.
  4. Open a new file for writing with: writer.OpenFile("FileName.wav")
  5. Write to it within your audio callback using: writer.Sample(value)
  6. Fill the Wav File on the SD Card with data from your main loop by running: writer.Write()
  7. When finished with the recording finalize, and close the file with: writer.SaveFile();

#include <WavWriter.h>

Classes

struct  Config
 

Public Types

enum class  Result { OK , ERROR }
 
enum class  BufferState { IDLE , FLUSH0 , FLUSH1 }
 

Public Member Functions

 WavWriter ()
 
 ~WavWriter ()
 
void Init (const Config &cfg)
 
void Sample (const float *in)
 
void Write ()
 
void SaveFile ()
 
void OpenFile (const char *name)
 
bool IsRecording () const
 
uint32_t GetLengthSamps ()
 
float GetLengthSeconds ()
 

Member Enumeration Documentation

◆ BufferState

template<size_t transfer_size>
enum class daisy::WavWriter::BufferState
strong

State of the internal Writing mechanism. When the buffer is a certain amount full one section will write its contents while the other is still being written to. This is performed circularly so that audio will be uninterrupted during writing.

Enumerator
IDLE 
FLUSH0 
FLUSH1 

◆ Result

template<size_t transfer_size>
enum class daisy::WavWriter::Result
strong

Return values for write related functions

Enumerator
OK 
ERROR 

Constructor & Destructor Documentation

◆ WavWriter()

template<size_t transfer_size>
daisy::WavWriter< transfer_size >::WavWriter ( )
inline

◆ ~WavWriter()

template<size_t transfer_size>
daisy::WavWriter< transfer_size >::~WavWriter ( )
inline

Member Function Documentation

◆ GetLengthSamps()

template<size_t transfer_size>
uint32_t daisy::WavWriter< transfer_size >::GetLengthSamps ( )
inline

Returns the current length in samples of the recording.

◆ GetLengthSeconds()

template<size_t transfer_size>
float daisy::WavWriter< transfer_size >::GetLengthSeconds ( )
inline

Returns the current length of the recording in seconds.

◆ Init()

template<size_t transfer_size>
void daisy::WavWriter< transfer_size >::Init ( const Config cfg)
inline

Initializes the WavFile header, and prepares the object for recording.

"RIFF"

"WAVE"

"fmt "

"data"

Also calcs SubChunk2Size

◆ IsRecording()

template<size_t transfer_size>
bool daisy::WavWriter< transfer_size >::IsRecording ( ) const
inline

Returns whether recording is currently active or not.

◆ OpenFile()

template<size_t transfer_size>
void daisy::WavWriter< transfer_size >::OpenFile ( const char name)
inline

Opens a file for writing. Writes the initial WAV Header, and gets ready for stream-based recording.

◆ Sample()

template<size_t transfer_size>
void daisy::WavWriter< transfer_size >::Sample ( const float in)
inline

Records the current sample into the working buffer, queues writes to media when necessary.

Parameters
inshould be a pointer to an array of samples

◆ SaveFile()

template<size_t transfer_size>
void daisy::WavWriter< transfer_size >::SaveFile ( )
inline

Finalizes the writing of the WAV file. This overwrites the WAV Header with the correct final size, and closes the fptr.

◆ Write()

template<size_t transfer_size>
void daisy::WavWriter< transfer_size >::Write ( )
inline

Check buffer state and write


The documentation for this class was generated from the following file: