daisy::WavWriter¶
#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¶
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:
- Create a WavWriter
object (e.g. WavWriter<32768> writer) - Configure the settings as desired by creating a WavWriter<32768>::Config struct and setting the settings.
- Initialize the object with the configuration struct.
- Open a new file for writing with: writer.OpenFile("FileName.wav")
- Write to it within your audio callback using: writer.Sample(value)
- Fill the Wav File on the SD Card with data from your main loop by running: writer.Write()
- 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¶
function ~WavWriter¶
function Init¶
Initializes the WavFile header, and prepares the object for recording.
"RIFF"
"WAVE"
"fmt "
"data"
Also calcs SubChunk2Size
function Sample¶
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¶
Check buffer state and write
function SaveFile¶
Finalizes the writing of the WAV file. This overwrites the WAV Header with the correct final size, and closes the fptr.
function OpenFile¶
Opens a file for writing. Writes the initial WAV Header, and gets ready for stream-based recording.
function IsRecording¶
Returns whether recording is currently active or not.
function GetLengthSamps¶
Returns the current length in samples of the recording.
function GetLengthSeconds¶
Returns the current length of the recording in seconds.
---¶
Updated on 2024-01-03 at 19:41:01 +0000