MayaFlux 0.4.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 std::unique_lock lock(m_data_mutex);
18
19 m_num_frames = num_frames;
20 m_sample_rate = sample_rate;
21 m_num_channels = num_channels;
22
25}
26
27void SoundFileContainer::set_raw_data(const std::vector<DataVariant>& data)
28{
29 std::unique_lock lock(m_data_mutex);
30
31 m_data.resize(data.size());
32 std::ranges::copy(data, m_data.begin());
33
34 if (!m_data.empty()) {
35 auto elements = std::visit([](const auto& vec) { return vec.size(); }, m_data[0]);
37 ? elements / m_num_channels
38 : elements;
39 }
40
42 m_double_extraction_dirty.store(true, std::memory_order_release);
43}
44
49
50std::shared_ptr<SoundFileContainer> make_sound_file_container(
51 std::vector<std::vector<double>> channel_data,
52 uint32_t num_channels,
53 uint32_t sample_rate,
55{
56 if (channel_data.empty() || channel_data[0].size() == 0 || num_channels != channel_data.size()) {
57 error<std::invalid_argument>(
59 std::source_location::current(),
60 "build_sound_file_container: channel_data must be non-empty and match num_channels");
61 }
62
63 auto sc = std::make_shared<SoundFileContainer>();
64 sc->setup(channel_data[0].size(), sample_rate, num_channels);
65 sc->get_structure().organization = org;
66
67 std::vector<DataVariant> variants;
68 variants.reserve(num_channels);
69 for (auto& ch : channel_data)
70 variants.emplace_back(std::move(ch));
71
72 sc->set_raw_data(variants);
73 sc->create_default_processor();
74 sc->mark_ready_for_processing(true);
75 return sc;
76}
77
78} // namespace MayaFlux::Kakshya
Range size
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.
void lock() override
Acquire a lock for thread-safe access.
Concrete base implementation for streaming audio containers.
@ 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:49
@ INTERLEAVED
Single DataVariant with interleaved data (LRLRLR for stereo)