Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
streaming_writer.hpp
Go to the documentation of this file.
1#pragma once
2
3// StreamingAudioFormatWriter — chunked write interface for audio files.
4// Allows writing audio in blocks without holding the entire file in memory.
5
7#include <string>
8#include <string_view>
9#include <vector>
10#include <cstdint>
11#include <fstream>
12#include <functional>
13
14namespace pulp::audio {
15
19public:
20 StreamingWriter() = default;
22
25 bool open(std::string_view path, uint32_t sample_rate, uint32_t num_channels,
26 uint32_t bits_per_sample = 16);
27
29 int write_frames(const float* interleaved_data, int num_frames);
30
32 int write_frames(const float* const* channels, int num_channels, int num_frames);
33
35 void close();
36
38 bool is_open() const { return file_.is_open(); }
39
41 uint64_t frames_written() const { return frames_written_; }
42
43 // No copy
46
47private:
48 std::ofstream file_;
49 uint32_t sample_rate_ = 0;
50 uint32_t num_channels_ = 0;
51 uint32_t bits_per_sample_ = 16;
52 uint64_t frames_written_ = 0;
53 size_t data_start_pos_ = 0;
54};
55
56} // namespace pulp::audio
uint64_t frames_written() const
Total frames written so far.
Definition streaming_writer.hpp:41
bool is_open() const
Whether the writer is currently open.
Definition streaming_writer.hpp:38
bool open(std::string_view path, uint32_t sample_rate, uint32_t num_channels, uint32_t bits_per_sample=16)
Open a file for streaming write.
int write_frames(const float *const *channels, int num_channels, int num_frames)
Write deinterleaved channel data.
void close()
Close the file (finalizes the WAV header with correct sizes).
int write_frames(const float *interleaved_data, int num_frames)
Write interleaved frames. Returns number of frames written.
StreamingWriter(const StreamingWriter &)=delete
StreamingWriter & operator=(const StreamingWriter &)=delete
Definition analyzer_provider.hpp:12