Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
audio_file.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2023 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __IO_AUDIO_FILE_H__
11#define __IO_AUDIO_FILE_H__
12
13#include "zrythm-config.h"
14
15#include <stdbool.h>
16
17#include "utils/types.h"
18
19#include <glib.h>
20
27typedef struct AudioFileMetadata
28{
29 int samplerate;
30 int channels;
31
33 int64_t length;
34
37 int64_t num_frames;
38
39 int bit_rate;
40 int bit_depth;
41
43 float bpm;
44
46 bool filled;
48
54typedef struct AudioFile
55{
57 char * filepath;
58
59 AudioFileMetadata metadata;
60
63} AudioFile;
64
70NONNULL AudioFile *
71audio_file_new (const char * filepath);
72
77bool audio_file_read_metadata (AudioFile * self, GError ** error);
78
91 AudioFile * self,
92 bool in_parts,
93 float * samples,
94 size_t start_from,
95 size_t num_frames_to_read,
96 GError ** error);
97
104NONNULL_ARGS (1) bool audio_file_finish (AudioFile * self, GError ** error);
105
119bool
121 const char * filepath,
122 float ** frames,
123 size_t * num_frames,
124 AudioFileMetadata * metadata,
125 size_t samplerate,
126 GError ** error);
127
128NONNULL void
129audio_file_free (AudioFile * self);
130
135#endif
NONNULL_ARGS(1) bool audio_file_finish(AudioFile *self
Must be called when done reading or writing files (or when the operation was cancelled).
bool audio_file_read_metadata(AudioFile *self, GError **error)
Reads the metadata for the given file.
bool audio_file_read_simple(const char *filepath, float **frames, size_t *num_frames, AudioFileMetadata *metadata, size_t samplerate, GError **error)
Simple blocking API for reading and optionally resampling audio files.
NONNULL AudioFile * audio_file_new(const char *filepath)
Creates a new instance of an AudioFile for the given path.
bool audio_file_read_samples(AudioFile *self, bool in_parts, float *samples, size_t start_from, size_t num_frames_to_read, GError **error)
Reads the file into an internal float array (interleaved).
int64_t length
Milliseconds.
Definition audio_file.h:33
bool filled
Whether metadata are already filled (valid).
Definition audio_file.h:46
float bpm
BPM if detected, or 0.
Definition audio_file.h:43
int64_t num_frames
Total number of frames (eg.
Definition audio_file.h:37
Audio file struct.
Definition audio_file.h:55
void * internal_data
Implemented in the source file.
Definition audio_file.h:62
char * filepath
Absolute path.
Definition audio_file.h:57
Custom types.