Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
audio_file.h
1// SPDX-FileCopyrightText: © 2023-2024, 2026 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
4#pragma once
5
6#include <memory>
7
8#include "utils/audio.h"
9
10namespace zrythm::utils::audio
11{
12
13struct AudioFileMetadata
14{
15 /* Rule of 0 */
16 AudioFileMetadata () = default;
17
18 AudioFileMetadata (const std::string &path);
19
20 int samplerate = 0;
21 int channels = 0;
22
24 int64_t length = 0;
25
28 int64_t num_frames = 0;
29
30 int bit_rate = 0;
31 int bit_depth = 0;
32
34 float bpm = 0.f;
35
37 bool filled = false;
38};
39
43class AudioFile
44{
45public:
46 AudioFile ();
47
54 AudioFile (std::filesystem::path filepath, bool for_writing = false);
55
56 AudioFile (AudioFile &&other) noexcept;
57 AudioFile &operator= (AudioFile &&other) noexcept;
58
59 ~AudioFile ();
60
67
81 bool in_parts,
82 float * samples,
83 size_t start_from,
84 size_t num_frames_to_read);
85
98 void read_full (
100 std::optional<size_t> samplerate);
101
102private:
103 struct Impl;
104 std::unique_ptr<Impl> impl_;
105};
106
107}; // namespace zrythm::utils::audio
AudioFileMetadata read_metadata()
Reads the metadata for the specified file.
void read_samples_interleaved(bool in_parts, float *samples, size_t start_from, size_t num_frames_to_read)
Reads the file into an internal float array (interleaved).
AudioFile(std::filesystem::path filepath, bool for_writing=false)
Creates a new instance of an AudioFile for the given path.
void read_full(zrythm::utils::audio::AudioBuffer &buffer, std::optional< size_t > samplerate)
Simple blocking API for reading and optionally resampling audio files.
bool filled
Whether metadata are already filled (valid).
Definition audio_file.h:37
int64_t num_frames
Total number of frames (eg.
Definition audio_file.h:28
float bpm
BPM if detected, or 0.
Definition audio_file.h:34