MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
SoundFileContainer.cpp
Go to the documentation of this file.
2
3namespace MayaFlux::Kakshya {
4
6 : SoundStreamContainer(48000, 2, 0, false) // Default: 48kHz, stereo, no initial capacity, not circular
7{
8}
9
10SoundFileContainer::SoundFileContainer(uint32_t sample_rate, uint32_t num_channels, uint64_t initial_capacity)
11 : SoundStreamContainer(sample_rate, num_channels, initial_capacity, false) // Files are not circular
12{
13}
14
15void SoundFileContainer::setup(uint64_t num_frames, uint32_t sample_rate, uint32_t num_channels)
16{
17 {
19 m_num_frames = num_frames;
20 m_sample_rate = sample_rate;
21 m_num_channels = num_channels;
23 }
25}
26
27void SoundFileContainer::set_raw_data(const std::vector<DataVariant>& data)
28{
30 m_data.resize(data.size());
31
32 std::ranges::copy(data, m_data.begin());
33 if (!m_data.empty()) {
34 auto elements = std::visit([](const auto& vec) { return vec.size(); }, m_data[0]);
36 ? elements / m_num_channels
37 : elements;
38 }
39
41 m_double_extraction_dirty.store(true, std::memory_order_release);
42}
43
48
49std::shared_ptr<SoundFileContainer> make_sound_file_container(
50 std::vector<std::vector<double>> channel_data,
51 uint32_t num_channels,
52 uint32_t sample_rate,
54{
55 if (channel_data.empty() || channel_data[0].size() == 0 || num_channels != channel_data.size()) {
56 error<std::invalid_argument>(
58 std::source_location::current(),
59 "build_sound_file_container: channel_data must be non-empty and match num_channels");
60 }
61
62 auto sc = std::make_shared<SoundFileContainer>();
63 sc->setup(channel_data[0].size(), sample_rate, num_channels);
64 sc->get_structure().organization = org;
65
66 std::vector<DataVariant> variants;
67 variants.reserve(num_channels);
68 for (auto& ch : channel_data)
69 variants.emplace_back(std::move(ch));
70
71 sc->set_raw_data(variants);
72 sc->create_default_processor();
73 sc->mark_ready_for_processing(true);
74 return sc;
75}
76
77} // namespace MayaFlux::Kakshya
void setup(uint64_t num_frames, uint32_t sample_rate, uint32_t num_channels)
Setup the container with file parameters.
SoundFileContainer()
Construct a SoundFileContainer with default parameters Uses reasonable defaults suitable for file con...
void set_raw_data(const std::vector< DataVariant > &data)
Set raw data from external source (e.g., file loading)
double get_duration_seconds() const
Enable debug output for this container.
double position_to_time(uint64_t position) const override
Convert from position units (e.g., frame/sample index) to time (seconds).
void update_processing_state(ProcessingState new_state) override
Update the processing state of the container.
Concrete base implementation for streaming audio containers.
RAII guard that brackets a Seqlock write region.
Definition SeqLock.hpp:136
@ Configuration
Configuration and parameter updates.
@ Kakshya
Containers[Signalsource, Stream, File], Regions, DataProcessors.
@ IDLE
Container is inactive with no data or not ready for processing.
std::shared_ptr< SoundFileContainer > make_sound_file_container(std::vector< std::vector< double > > channel_data, uint32_t num_channels, uint32_t sample_rate, OrganizationStrategy org)
Construct a fully populated SoundFileContainer from computed channel data.
OrganizationStrategy
Data organization strategy for multi-channel/multi-frame data.
Definition NDData.hpp:75
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)