Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
audio.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __UTILS_AUDIO_H__
11#define __UTILS_AUDIO_H__
12
13#include <stdarg.h>
14#include <stdbool.h>
15
16#include "utils/types.h"
17#include "utils/yaml.h"
18
28typedef enum BitDepth
29{
30 BIT_DEPTH_16,
31 BIT_DEPTH_24,
32 BIT_DEPTH_32
33} BitDepth;
34
35static const cyaml_strval_t bit_depth_strings[] = {
36 {"16", BIT_DEPTH_16},
37 { "24", BIT_DEPTH_24},
38 { "32", BIT_DEPTH_32},
39};
40
41static inline int
42audio_bit_depth_enum_to_int (BitDepth depth)
43{
44 switch (depth)
45 {
46 case BIT_DEPTH_16:
47 return 16;
48 case BIT_DEPTH_24:
49 return 24;
50 case BIT_DEPTH_32:
51 return 32;
52 default:
53 g_return_val_if_reached (-1);
54 }
55}
56
57static inline BitDepth
58audio_bit_depth_int_to_enum (int depth)
59{
60 switch (depth)
61 {
62 case 16:
63 return BIT_DEPTH_16;
64 case 24:
65 return BIT_DEPTH_24;
66 case 32:
67 return BIT_DEPTH_32;
68 default:
69 g_return_val_if_reached (BIT_DEPTH_16);
70 }
71}
72
74audio_bit_depth_from_pretty_str (const char * str);
75
76const char *
77audio_bit_depth_to_pretty_str (BitDepth depth);
78
82#define STRIP_SIZE 9
83
95WARN_UNUSED_RESULT bool
97 float * buff,
98 size_t frames_already_written,
99 size_t nframes,
100 uint32_t samplerate,
101 bool flac,
102 BitDepth bit_depth,
103 channels_t channels,
104 const char * filename,
105 GError ** error);
106
112audio_get_num_frames (const char * filepath);
113
117bool
119 const float * src1,
120 const float * src2,
121 size_t num_frames,
122 float epsilon);
123
130bool
132 const char * f1,
133 const char * f2,
134 size_t num_frames,
135 float epsilon);
136
140bool
141audio_frames_empty (float * src, size_t num_frames);
142
148float
150 float * src,
151 size_t num_frames,
152 unsigned int samplerate,
153 GArray * candidates);
154
155bool
156audio_file_is_silent (const char * filepath);
157
161int
163
168#endif
int audio_get_num_cores(void)
Returns the number of CPU cores.
uint_fast64_t unsigned_frame_t
Unsigned type for frame index.
Definition types.h:60
BitDepth
Bit depth.
Definition audio.h:29
bool audio_frames_equal(const float *src1, const float *src2, size_t num_frames, float epsilon)
Returns whether the frame buffers are equal.
bool audio_files_equal(const char *f1, const char *f2, size_t num_frames, float epsilon)
Returns whether the file contents are equal.
bool audio_frames_empty(float *src, size_t num_frames)
Returns whether the frame buffer is empty (zero).
unsigned_frame_t audio_get_num_frames(const char *filepath)
Returns the number of frames in the given audio file.
float audio_detect_bpm(float *src, size_t num_frames, unsigned int samplerate, GArray *candidates)
Detect BPM.
WARN_UNUSED_RESULT bool audio_write_raw_file(float *buff, size_t frames_already_written, size_t nframes, uint32_t samplerate, bool flac, BitDepth bit_depth, channels_t channels, const char *filename, GError **error)
Writes the buffer as a raw file to the given path.
unsigned int channels_t
Number of channels.
Definition types.h:44
Custom types.
YAML utils.