Skip to content

daisy::WavWriter

More...

#include <WavWriter.h>

Public Classes

Name
struct Config

Public Types

Name
enum class Result
enum class BufferState

Public Functions

Name
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()

Detailed Description

template <size_t transfer_size>
class daisy::WavWriter;

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 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();

Public Types Documentation

enum Result

Enumerator Value Description
OK
ERROR

Return values for write related functions

enum BufferState

Enumerator Value Description
IDLE
FLUSH0
FLUSH1

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.

Public Functions Documentation

function WavWriter

inline WavWriter()

function ~WavWriter

inline ~WavWriter()

function Init

inline void Init(
    const Config & cfg
)

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

"RIFF"

"WAVE"

"fmt "

"data"

Also calcs SubChunk2Size


function Sample

inline void Sample(
    const float * in
)

Parameters:

  • in should be a pointer to an array of samples

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


function Write

inline void Write()

Check buffer state and write


function SaveFile

inline void SaveFile()

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


function OpenFile

inline void OpenFile(
    const char * name
)

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


function IsRecording

inline bool IsRecording() const

Returns whether recording is currently active or not.


function GetLengthSamps

inline uint32_t GetLengthSamps()

Returns the current length in samples of the recording.


function GetLengthSeconds

inline float GetLengthSeconds()

Returns the current length of the recording in seconds.

---

Updated on 2024-01-03 at 19:41:01 +0000