26 return static_cast<AudioReadOptions>(
static_cast<uint32_t
>(
a) |
static_cast<uint32_t
>(
b));
31 return static_cast<AudioReadOptions>(
static_cast<uint32_t
>(
a) &
static_cast<uint32_t
>(
b));
83 bool can_read(
const std::string& filepath)
const override;
118 std::shared_ptr<AudioStreamContext> audio,
119 const std::string& filepath,
125 void close()
override;
137 std::optional<FileMetadata>
get_metadata()
const override;
143 std::vector<FileRegion>
get_regions()
const override;
149 std::vector<Kakshya::DataVariant>
read_all()
override;
162 std::shared_ptr<Kakshya::SignalSourceContainer>
create_container()
override;
169 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer> container)
override;
182 bool seek(
const std::vector<uint64_t>& position)
override;
194 std::type_index
get_data_type()
const override {
return typeid(std::vector<double>); }
238 std::vector<Kakshya::DataVariant>
read_frames(uint64_t num_frames, uint64_t offset = 0);
329 const std::shared_ptr<FFmpegDemuxContext>& demux,
330 const std::shared_ptr<AudioStreamContext>& audio,
342 bool seek_internal(
const std::shared_ptr<FFmpegDemuxContext>& demux,
343 const std::shared_ptr<AudioStreamContext>& audio,
344 uint64_t frame_position);
349 void build_metadata(
const std::shared_ptr<FFmpegDemuxContext>& demux,
350 const std::shared_ptr<AudioStreamContext>& audio)
const;
355 void build_regions(
const std::shared_ptr<FFmpegDemuxContext>& demux,
356 const std::shared_ptr<AudioStreamContext>& audio)
const;
362 void set_error(
const std::string& error)
const;
Abstract interface for reading various file formats into containers.
std::vector< Kakshya::DataVariant > read_all() override
Read the entire audio file into memory.
void close() override
Close the currently open file and release resources.
void build_regions(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio) const
Build and cache FileRegion list from both contexts.
std::string get_last_error() const override
Get the last error message encountered by the reader.
uint64_t get_preferred_chunk_size() const override
Get the preferred chunk size for streaming reads.
uint32_t m_target_sample_rate
Target sample rate for resampling (0 = use source rate).
bool supports_streaming() const override
Check if the reader supports streaming access.
bool open(const std::string &filepath, FileReadOptions options=FileReadOptions::ALL) override
Open an audio file for reading.
std::mutex m_error_mutex
Mutex for thread-safe error message access.
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.
bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer > container) override
Load file data into an existing SignalSourceContainer.
std::shared_mutex m_context_mutex
Guards both context pointers.
bool seek_internal(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio, uint64_t frame_position)
Seek the demuxer and flush the codec to the given frame position.
bool can_read(const std::string &filepath) const override
Check if this reader can open the given file.
std::mutex m_metadata_mutex
Mutex for thread-safe metadata access.
std::vector< Kakshya::DataVariant > decode_frames(const std::shared_ptr< FFmpegDemuxContext > &demux, const std::shared_ptr< AudioStreamContext > &audio, uint64_t num_frames, uint64_t offset)
Decode num_frames PCM frames starting at offset.
std::string m_last_error
Last error message encountered.
std::vector< uint64_t > get_read_position() const override
Get the current read position in the file.
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.
std::type_index get_container_type() const override
Get the C++ type of the container returned by this reader.
std::vector< Kakshya::DataVariant > read_region(const FileRegion ®ion) override
Read a specific region from the file.
std::vector< Kakshya::DataVariant > read_frames(uint64_t num_frames, uint64_t offset=0)
Read a specific number of frames from the file.
AudioReadOptions m_audio_options
Audio-specific read options.
std::optional< FileMetadata > m_cached_metadata
Cached file metadata.
bool open_from_demux(std::shared_ptr< FFmpegDemuxContext > demux, std::shared_ptr< AudioStreamContext > audio, const std::string &filepath, FileReadOptions options=FileReadOptions::ALL)
Open an audio stream from an already-constructed demux and stream context.
std::vector< FileRegion > m_cached_regions
Cached file regions (markers, loops, etc.).
void clear_error() const
Clear the last error message.
~SoundFileReader() override
Destroy the SoundFileReader object.
std::type_index get_data_type() const override
Get the C++ type of the data returned by this reader.
std::string m_filepath
Path to the currently open file.
std::vector< uint64_t > get_dimension_sizes() const override
Get the size of each dimension (e.g., frames, channels).
void set_audio_options(AudioReadOptions options)
Set audio-specific read options.
std::shared_ptr< Kakshya::SignalSourceContainer > create_container() override
Create a SignalSourceContainer for this file.
bool seek(const std::vector< uint64_t > &position) override
Seek to a specific position in the file.
SoundFileReader()
Construct a new SoundFileReader object.
size_t get_num_dimensions() const override
Get the number of dimensions in the audio data (typically 2: time, channel).
std::shared_ptr< FFmpegDemuxContext > m_demux
Container / format state.
std::optional< FileMetadata > get_metadata() const override
Get metadata for the currently open file.
std::vector< FileRegion > get_regions() const override
Get all regions (markers, loops, etc.) from the file.
bool is_open() const override
Check if a file is currently open.
FileReadOptions m_options
File read options used for this session.
std::vector< std::string > get_supported_extensions() const override
Get supported file extensions for this reader.
void set_target_sample_rate(uint32_t sample_rate)
Set the target sample rate for resampling.
FFmpeg-based audio file reader for MayaFlux.
File-backed audio container with complete streaming functionality.
AudioReadOptions
Audio-specific reading options.
@ CONVERT_TO_MONO
Not implemented — placeholder for channel mixer.
@ NORMALIZE
Not implemented — placeholder for future volume filter.
@ DEINTERLEAVE
Output planar (per-channel) doubles instead of interleaved.
FileReadOptions
Generic options for file reading behavior.
@ ALL
All options enabled.
@ NONE
No special options.
FileReadOptions operator&(FileReadOptions a, FileReadOptions b)
FileReadOptions operator|(FileReadOptions a, FileReadOptions b)
Generic region descriptor for any file type.