// SPDX-License-Identifier: GPL-3.0-only // microSD storage: a streaming WAV writer plus sidecar JSON metadata. #pragma once #include #include #include namespace storage { // Mount the microSD card over SPI using the pins in pins.h. Creates OSC_REC_DIR. bool begin(); uint64_t totalBytes(); uint64_t freeBytes(); // Streaming writer for a canonical 16-bit PCM WAV file. Writes a placeholder header on // open(), appends PCM with write(), and patches the RIFF/data sizes on close(). class WavWriter { public: bool open(const String &path, uint32_t sampleRate, uint16_t bitsPerSample, uint16_t channels); size_t write(const uint8_t *data, size_t len); bool close(); uint32_t dataBytes() const { return dataBytes_; } bool isOpen() const { return (bool)file_; } private: File file_; uint32_t dataBytes_ = 0; uint32_t sampleRate_ = 0; uint16_t bits_ = 0; uint16_t channels_ = 0; }; // Write a sidecar JSON metadata file next to a recording. bool writeMetadata(const String &path, const String &json); // Path helpers for a recording id. String recWavPath(const String &id); String recMetaPath(const String &id); // Read a whole (small) file into a String; empty String if it does not exist. String readFile(const String &path); // Delete a recording's audio + metadata. Returns true if anything was removed. bool removeRecording(const String &id); // Count recordings (by .wav files) currently on the card. uint32_t countRecordings(); // Build the RecordingPage JSON by concatenating every sidecar metadata object. This is // the body for GET /recordings and matches api/openapi.yaml. String listRecordingsJson(); } // namespace storage