MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ open()

bool MayaFlux::IO::SoundFileReader::open ( const std::string &  filepath,
FileReadOptions  options = FileReadOptions::ALL 
)
overridevirtual

Open an audio file for reading.

Parameters
filepathPath to the file.
optionsFile read options.
Returns
True if the file was opened successfully.

Implements MayaFlux::IO::FileReader.

Definition at line 85 of file SoundFileReader.cpp.

86{
87 std::unique_lock<std::shared_mutex> lock(m_context_mutex);
88
89 m_demux.reset();
90 m_audio.reset();
92 {
93 std::lock_guard<std::mutex> ml(m_metadata_mutex);
94 m_cached_metadata.reset();
95 m_cached_regions.clear();
96 }
98
99 auto resolved = resolve_path(filepath);
100 m_filepath = resolved;
101 m_options = options;
102
103 auto demux = std::make_shared<FFmpegDemuxContext>();
104 if (!demux->open(resolved)) {
105 set_error(demux->last_error());
106 return false;
107 }
108
110 auto audio = std::make_shared<AudioStreamContext>();
111 if (!audio->open(*demux, planar, m_target_sample_rate)) {
112 set_error(audio->last_error());
113 return false;
114 }
115
116 m_demux = std::move(demux);
117 m_audio = std::move(audio);
118
121
124
125 return true;
126}
static std::string resolve_path(const std::string &filepath)
Resolve a filepath against the project source root if not found as-is.
void build_regions(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio) const
Build and cache FileRegion list from both contexts.
uint32_t m_target_sample_rate
Target sample rate for resampling (0 = use source rate).
void build_metadata(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio) const
Build and cache FileMetadata from both contexts.
std::shared_ptr< AudioStreamContext > m_audio
Codec + resampler state.
std::shared_mutex m_context_mutex
Guards both context pointers.
std::mutex m_metadata_mutex
Mutex for thread-safe metadata access.
void set_error(const std::string &error) const
Set the last error message.
std::atomic< uint64_t > m_current_frame_position
Current frame position for reading.
AudioReadOptions m_audio_options
Audio-specific read options.
std::optional< FileMetadata > m_cached_metadata
Cached file metadata.
std::vector< FileRegion > m_cached_regions
Cached file regions (markers, loops, etc.).
void clear_error() const
Clear the last error message.
std::string m_filepath
Path to the currently open file.
std::shared_ptr< FFmpegDemuxContext > m_demux
Container / format state.
FileReadOptions m_options
File read options used for this session.
@ DEINTERLEAVE
Output planar (per-channel) doubles instead of interleaved.
@ EXTRACT_METADATA
Extract file metadata.
@ EXTRACT_REGIONS
Extract semantic regions (format-specific)
@ NONE
No special options.

References build_metadata(), build_regions(), clear_error(), MayaFlux::IO::DEINTERLEAVE, MayaFlux::IO::EXTRACT_METADATA, MayaFlux::IO::EXTRACT_REGIONS, m_audio, m_audio_options, m_cached_metadata, m_cached_regions, m_context_mutex, m_current_frame_position, m_demux, m_filepath, m_metadata_mutex, m_options, m_target_sample_rate, MayaFlux::IO::NONE, MayaFlux::IO::FileReader::resolve_path(), and set_error().

Referenced by load_bounded().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: