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 "utils/types.h"
16
17#include <glib.h>
18
25typedef struct AudioFileMetadata
26{
27 int samplerate;
28 int channels;
29
31 int64_t length;
32
35 int64_t num_frames;
36
37 int bit_rate;
38 int bit_depth;
39
41 float bpm;
42
44 bool filled;
46
52typedef struct AudioFile
53{
55 char * filepath;
56
57 AudioFileMetadata metadata;
58
61} AudioFile;
62
68NONNULL AudioFile *
69audio_file_new (const char * filepath);
70
75bool audio_file_read_metadata (AudioFile * self, GError ** error);
76
89 AudioFile * self,
90 bool in_parts,
91 float * samples,
92 size_t start_from,
93 size_t num_frames_to_read,
94 GError ** error);
95
102NONNULL_ARGS (1) bool audio_file_finish (AudioFile * self, GError ** error);
103
117bool
119 const char * filepath,
120 float ** frames,
121 size_t * num_frames,
122 AudioFileMetadata * metadata,
123 size_t samplerate,
124 GError ** error);
125
126NONNULL void
127audio_file_free (AudioFile * self);
128
133#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:31
bool filled
Whether metadata are already filled (valid).
Definition audio_file.h:44
float bpm
BPM if detected, or 0.
Definition audio_file.h:41
int64_t num_frames
Total number of frames (eg.
Definition audio_file.h:35
Audio file struct.
Definition audio_file.h:53
void * internal_data
Implemented in the source file.
Definition audio_file.h:60
char * filepath
Absolute path.
Definition audio_file.h:55
Custom types.