12#include <juce_audio_basics/juce_audio_basics.h>
14namespace zrythm::utils::audio
32constexpr std::array<std::pair<int, BitDepth>, 4> bit_depth_map = {
33 std::pair{ 8, BitDepth::BIT_DEPTH_8 },
34 std::pair{ 16, BitDepth::BIT_DEPTH_16 },
35 std::pair{ 24, BitDepth::BIT_DEPTH_24 },
36 std::pair{ 32, BitDepth::BIT_DEPTH_32 }
40bit_depth_enum_to_int (BitDepth depth)
43 std::ranges::find (bit_depth_map, depth, &std::pair<int, BitDepth>::second);
44 assert (it != bit_depth_map.end ());
49bit_depth_int_to_enum (
int depth)
52 std::ranges::find (bit_depth_map, depth, &std::pair<int, BitDepth>::first);
53 assert (it != bit_depth_map.end ());
62get_num_frames (
const std::filesystem::path &filepath);
69 std::span<const float> src1,
70 std::span<const float> src2,
90frames_silent (std::span<const float> src);
101 unsigned int samplerate,
102 std::vector<float> &candidates);
105audio_file_is_silent (
const std::filesystem::path &filepath);
113class AudioBuffer :
public juce::AudioSampleBuffer
116 AudioBuffer () =
default;
117 AudioBuffer (
int num_channels,
int num_frames_per_channel)
118 : juce::AudioSampleBuffer (num_channels, num_frames_per_channel)
131 static std::unique_ptr<AudioBuffer>
150 void invert_phase ();
151 void normalize_peak ();
159 const juce::AudioSampleBuffer &buffer,
162 float threshold = 1e-6f);
168DEFINE_ENUM_FORMATTER (
169 zrythm::utils::audio::BitDepth,
171 QT_TR_NOOP_UTF8 (
"8 bit"),
172 QT_TR_NOOP_UTF8 (
"16 bit"),
173 QT_TR_NOOP_UTF8 (
"24 bit"),
174 QT_TR_NOOP_UTF8 (
"32 bit"));
void deinterleave_samples(size_t num_channels)
De-interleaves the samples in this buffer from interleaved format to non-interleaved (planar) format.
static std::unique_ptr< AudioBuffer > from_interleaved(const float *src, size_t num_frames, size_t num_channels)
Creates an AudioBuffer from interleaved audio data.
void interleave_samples()
Interleaves the samples in this buffer from non-interleaved (planar) format to interleaved format.