31 return static_cast<AudioReadOptions>(
static_cast<uint32_t
>(a) |
static_cast<uint32_t
>(b));
36 return static_cast<AudioReadOptions>(
static_cast<uint32_t
>(a) &
static_cast<uint32_t
>(b));
118 bool can_read(
const std::string& filepath)
const override;
131 void close()
override;
143 std::optional<FileMetadata>
get_metadata()
const override;
149 std::vector<FileRegion>
get_regions()
const override;
155 std::vector<Kakshya::DataVariant>
read_all()
override;
168 std::shared_ptr<Kakshya::SignalSourceContainer>
create_container()
override;
175 bool load_into_container(std::shared_ptr<Kakshya::SignalSourceContainer> container)
override;
188 bool seek(
const std::vector<uint64_t>& position)
override;
200 std::type_index
get_data_type()
const override {
return typeid(std::vector<double>); }
244 std::vector<Kakshya::DataVariant>
read_frames(uint64_t num_frames, uint64_t offset = 0);
355 std::shared_ptr<FFmpegContext> ctx,
365 bool seek_internal(std::shared_ptr<FFmpegContext>& ctx, uint64_t frame_position);
373 std::vector<std::vector<double>>
deinterleave_data(
const std::vector<double>& interleaved, uint32_t channels);
379 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.
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.
bool load_into_container(std::shared_ptr< Kakshya::SignalSourceContainer > container) override
Load file data into an existing SignalSourceContainer.
std::shared_mutex m_context_mutex
bool can_read(const std::string &filepath) const override
Check if this reader can open the given file.
uint32_t m_target_bit_depth
Target bit depth (ignored, always outputs double).
std::mutex m_metadata_mutex
Mutex for thread-safe metadata access.
static std::atomic< bool > s_ffmpeg_initialized
True if FFmpeg has been initialized.
std::vector< Kakshya::DataVariant > decode_frames(std::shared_ptr< FFmpegContext > ctx, uint64_t num_frames, uint64_t offset)
Decode a specific number of frames from the file.
bool seek_internal(std::shared_ptr< FFmpegContext > &ctx, uint64_t frame_position)
Internal seek implementation.
std::string m_last_error
Last error message encountered.
void extract_regions(const std::shared_ptr< FFmpegContext > &ctx)
Extract region information from the file.
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.
void extract_metadata(const std::shared_ptr< FFmpegContext > &ctx)
Extract metadata from the file.
std::type_index get_container_type() const override
Get the C++ type of the container returned by this reader.
bool setup_resampler(const std::shared_ptr< FFmpegContext > &ctx)
Set up the FFmpeg resampler if needed.
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::shared_ptr< FFmpegContext > m_context
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.
~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_target_bit_depth(uint32_t bit_depth)
Set the target bit depth (ignored, always outputs double).
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.
std::vector< std::vector< double > > deinterleave_data(const std::vector< double > &interleaved, uint32_t channels)
Convert interleaved audio data to deinterleaved (planar) format.
size_t get_num_dimensions() const override
Get the number of dimensions in the audio data (typically 2: time, channel).
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.
static void initialize_ffmpeg()
Initialize FFmpeg libraries (thread-safe, called automatically).
void set_target_sample_rate(uint32_t sample_rate)
Set the target sample rate for resampling.
static std::mutex s_ffmpeg_init_mutex
Mutex for FFmpeg initialization.
FFmpeg-based audio file reader for MayaFlux.
File-backed audio container with complete streaming functionality.
AudioReadOptions
Audio-specific reading options.
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)
FFmpegContext & operator=(const FFmpegContext &)=delete
FFmpegContext & operator=(FFmpegContext &&)=delete
FFmpegContext(const FFmpegContext &)=delete
FFmpegContext(FFmpegContext &&)=delete
AVCodecContext * codec_context
AVFormatContext * format_context
RAII wrapper for FFmpeg contexts with proper cleanup.
Generic region descriptor for any file type.