MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SoundFileBridge.hpp
Go to the documentation of this file.
1#pragma once
2
4
5namespace MayaFlux::Kakshya {
6class SoundFileContainer;
7class DynamicSoundStream;
8}
9
10namespace MayaFlux::Buffers {
11
12class SoundStreamWriter;
13class SoundStreamReader;
14
15/**
16 * @brief An audio buffer that reads from a file container and writes to a dynamic stream.
17 *
18 * SoundFileBridge is a SoundContainerBuffer with built-in output streaming.
19 * It automatically sets up:
20 * - Default processor: Reads from file container (inherited)
21 * - Main chain: User processors (e.g., filters, effects)
22 * - Postprocessor: Writes transformed audio to output stream
23 *
24 * Usage:
25 * auto file_buf = std::make_shared<SoundFileBridge>(0, file_container);
26 * file_buf->setup_chain();
27 *
28 * // Optionally add processing
29 * auto filter = std::make_shared<FilterProcessor>(...);
30 * file_buf->get_processing_chain()->add_processor(filter, file_buf);
31 *
32 * // Process for N cycles
33 * for (int i = 0; i < 100; ++i) {
34 * file_buf->get_processing_chain()->process_complete(file_buf);
35 * }
36 *
37 * // Get the accumulated result
38 * auto result = file_buf->get_capture_stream();
39 */
40class MAYAFLUX_API SoundFileBridge : public SoundContainerBuffer {
41public:
42 /**
43 * @brief Construct a file-to-stream bridge
44 * @param channel_id Channel identifier for this buffer
45 * @param file_container Audio file to read from
46 * @param source_channel Which channel in the file to read (default: 0)
47 */
48 SoundFileBridge(uint32_t channel_id,
49 const std::shared_ptr<Kakshya::SoundFileContainer>& file_container,
50 uint32_t source_channel = 0);
51
52 /**
53 * @brief Get the output stream accumulating processed audio
54 * @return DynamicSoundStream containing all written samples
55 */
56 inline std::shared_ptr<Kakshya::DynamicSoundStream> get_capture_stream() const
57 {
58 return m_capture_stream;
59 }
60
61 /**
62 * @brief Setup the processing chain with automatic input/output
63 *
64 * Configures:
65 * - Default processor: SoundStreamReader (inherited, reads from file)
66 * - Postprocessor: SoundStreamWriter (writes to stream)
67 *
68 * User processors can be inserted into the main chain between these stages.
69 *
70 * After calling setup_chain(), the buffer is ready for process_complete() cycles.
71 */
72 void setup_processors(Buffers::ProcessingToken token) override;
73
74 /**
75 * @brief Get the stream writer processor
76 * @return SoundStreamWriter used for output
77 */
78 std::shared_ptr<SoundStreamWriter> get_stream_writer() const { return m_stream_writer; }
79
80private:
81 std::shared_ptr<Kakshya::DynamicSoundStream> m_capture_stream;
82 std::shared_ptr<SoundStreamWriter> m_stream_writer;
83};
84
85} // namespace MayaFlux::Buffers
static MayaFlux::Nodes::ProcessingToken token
Definition Timers.cpp:8
AudioBuffer implementation backed by a StreamContainer.
std::shared_ptr< SoundStreamWriter > m_stream_writer
std::shared_ptr< SoundStreamWriter > get_stream_writer() const
Get the stream writer processor.
std::shared_ptr< Kakshya::DynamicSoundStream > m_capture_stream
std::shared_ptr< Kakshya::DynamicSoundStream > get_capture_stream() const
Get the output stream accumulating processed audio.
An audio buffer that reads from a file container and writes to a dynamic stream.
ProcessingToken
Bitfield enum defining processing characteristics and backend requirements for buffer operations.