libgroove  5.0.0
groove.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Andrew Kelley
3  *
4  * This file is part of libgroove, which is MIT licensed.
5  * See http://opensource.org/licenses/MIT
6  */
7 
8 #ifndef GROOVE_GROOVE_H
9 #define GROOVE_GROOVE_H
10 
11 #include <stdint.h>
12 #include <soundio/soundio.h>
13 
15 #ifdef __cplusplus
16 #define GROOVE_EXTERN_C extern "C"
17 #else
18 #define GROOVE_EXTERN_C
19 #endif
20 
21 #if defined(_WIN32)
22 #if defined(GROOVE_BUILDING_LIBRARY)
23 #define GROOVE_EXPORT GROOVE_EXTERN_C __declspec(dllexport)
24 #else
25 #define GROOVE_EXPORT GROOVE_EXTERN_C __declspec(dllimport)
26 #endif
27 #else
28 #define GROOVE_EXPORT GROOVE_EXTERN_C __attribute__((visibility ("default")))
29 #endif
30 
66 enum GrooveError {
71 };
72 
83 };
84 
85 #define GROOVE_LOG_QUIET -8
86 #define GROOVE_LOG_ERROR 16
87 #define GROOVE_LOG_WARNING 24
88 #define GROOVE_LOG_INFO 32
89 
91 #define GROOVE_TAG_MATCH_CASE 1
92 #define GROOVE_TAG_DONT_OVERWRITE 16
93 
96 #define GROOVE_TAG_APPEND 32
97 
98 
99 
100 #define GROOVE_BUFFER_NO 0
101 #define GROOVE_BUFFER_YES 1
102 #define GROOVE_BUFFER_END 2
103 
106  struct SoundIoChannelLayout layout;
107  enum SoundIoFormat format;
108  bool is_planar;
109 };
110 
111 struct GrooveFile {
112  int dirty;
113  const char *filename;
114 };
115 
116 struct GrooveTag;
117 
120  struct GrooveFile *file;
121 
126  double gain;
127 
134  double peak;
135 
142 };
143 
153 
157  double gain;
158 };
159 
160 struct GrooveBuffer {
165  uint8_t **data;
166 
169 
174 
181  double pos;
182 
185  int size;
186 
189  uint64_t pts;
190 };
191 
195 struct GrooveSink {
206 
210 
217  double gain;
218 
220  void *userdata;
223  void (*flush)(struct GrooveSink *);
226  void (*purge)(struct GrooveSink *, struct GroovePlaylistItem *);
228  void (*pause)(struct GrooveSink *);
230  void (*play)(struct GrooveSink *);
231 
235 
239 };
240 
241 
244 GROOVE_EXPORT int groove_init(void);
247 GROOVE_EXPORT void groove_finish(void);
248 
249 GROOVE_EXPORT const char *groove_strerror(int error);
250 
252 GROOVE_EXPORT void groove_set_logging(int level);
253 
254 
257 GROOVE_EXPORT int groove_audio_formats_equal(
258  const struct GrooveAudioFormat *a,
259  const struct GrooveAudioFormat *b);
260 
261 GROOVE_EXPORT int groove_version_major(void);
262 GROOVE_EXPORT int groove_version_minor(void);
263 GROOVE_EXPORT int groove_version_patch(void);
264 GROOVE_EXPORT const char *groove_version(void);
265 
270 GROOVE_EXPORT char *groove_create_rand_name(int *out_len, const char *file, int file_len);
271 
272 GROOVE_EXPORT const char *groove_tag_key(struct GrooveTag *tag);
273 GROOVE_EXPORT const char *groove_tag_value(struct GrooveTag *tag);
274 
277 GROOVE_EXPORT struct GrooveFile *groove_file_open(const char *filename);
278 GROOVE_EXPORT void groove_file_close(struct GrooveFile *file);
279 
280 GROOVE_EXPORT struct GrooveTag *groove_file_metadata_get(struct GrooveFile *file,
281  const char *key, const struct GrooveTag *prev, int flags);
282 
289 GROOVE_EXPORT int groove_file_metadata_set(struct GrooveFile *file, const char *key,
290  const char *value, int flags);
291 
293 GROOVE_EXPORT const char *groove_file_short_names(struct GrooveFile *file);
294 
297 GROOVE_EXPORT int groove_file_save(struct GrooveFile *file);
298 GROOVE_EXPORT int groove_file_save_as(struct GrooveFile *file, const char *filename);
299 
305 GROOVE_EXPORT double groove_file_duration(struct GrooveFile *file);
306 
308 GROOVE_EXPORT void groove_file_audio_format(struct GrooveFile *file,
309  struct GrooveAudioFormat *audio_format);
310 
311 
313 GROOVE_EXPORT struct GroovePlaylist *groove_playlist_create(void);
316 GROOVE_EXPORT void groove_playlist_destroy(struct GroovePlaylist *playlist);
317 
318 
319 GROOVE_EXPORT void groove_playlist_play(struct GroovePlaylist *playlist);
320 GROOVE_EXPORT void groove_playlist_pause(struct GroovePlaylist *playlist);
321 
322 GROOVE_EXPORT void groove_playlist_seek(struct GroovePlaylist *playlist,
323  struct GroovePlaylistItem *item, double seconds);
324 
331 GROOVE_EXPORT struct GroovePlaylistItem *groove_playlist_insert(
332  struct GroovePlaylist *playlist, struct GrooveFile *file,
333  double gain, double peak,
334  struct GroovePlaylistItem *next);
335 
338 GROOVE_EXPORT void groove_playlist_remove(struct GroovePlaylist *playlist,
339  struct GroovePlaylistItem *item);
340 
349 GROOVE_EXPORT void groove_playlist_position(struct GroovePlaylist *playlist,
350  struct GroovePlaylistItem **item, double *seconds);
351 
353 GROOVE_EXPORT int groove_playlist_playing(struct GroovePlaylist *playlist);
354 
355 
357 GROOVE_EXPORT void groove_playlist_clear(struct GroovePlaylist *playlist);
358 
360 GROOVE_EXPORT int groove_playlist_count(struct GroovePlaylist *playlist);
361 
362 GROOVE_EXPORT void groove_playlist_set_gain(struct GroovePlaylist *playlist, double gain);
363 
364 GROOVE_EXPORT void groove_playlist_set_item_gain_peak(
365  struct GroovePlaylist *playlist, struct GroovePlaylistItem *item,
366  double gain, double peak);
367 
369 GROOVE_EXPORT void groove_playlist_set_fill_mode(struct GroovePlaylist *playlist,
370  enum GrooveFillMode mode);
371 
372 GROOVE_EXPORT void groove_buffer_ref(struct GrooveBuffer *buffer);
373 GROOVE_EXPORT void groove_buffer_unref(struct GrooveBuffer *buffer);
374 
375 GROOVE_EXPORT struct GrooveSink *groove_sink_create(void);
376 GROOVE_EXPORT void groove_sink_destroy(struct GrooveSink *sink);
377 
380 GROOVE_EXPORT int groove_sink_attach(struct GrooveSink *sink, struct GroovePlaylist *playlist);
382 GROOVE_EXPORT int groove_sink_detach(struct GrooveSink *sink);
383 
388 GROOVE_EXPORT int groove_sink_buffer_get(struct GrooveSink *sink,
389  struct GrooveBuffer **buffer, int block);
390 
393 GROOVE_EXPORT int groove_sink_buffer_peek(struct GrooveSink *sink, int block);
394 
398 GROOVE_EXPORT int groove_sink_set_gain(struct GrooveSink *sink, double gain);
399 
401 GROOVE_EXPORT int groove_sink_get_fill_level(struct GrooveSink *sink);
402 
404 GROOVE_EXPORT int groove_sink_contains_end_of_playlist(struct GrooveSink *sink);
405 
406 
407 #endif
struct GroovePlaylistItem * next
Definition: groove.h:141
double gain
This volume adjustment only applies to this sink.
Definition: groove.h:217
Definition: groove.h:104
void(* pause)(struct GrooveSink *)
called when the playlist is paused
Definition: groove.h:228
void groove_finish(void)
call at the end of your program to clean up.
double pos
read-only
Definition: groove.h:181
struct GroovePlaylistItem * item
read-only when encoding, if item is NULL, this is a format header or trailer.
Definition: groove.h:179
int groove_file_metadata_set(struct GrooveFile *file, const char *key, const char *value, int flags)
key entry to add to metadata.
struct GrooveFile * file
read-only
Definition: groove.h:120
int groove_file_save_as(struct GrooveFile *file, const char *filename)
void groove_playlist_seek(struct GroovePlaylist *playlist, struct GroovePlaylistItem *item, double seconds)
void groove_playlist_position(struct GroovePlaylist *playlist, struct GroovePlaylistItem **item, double *seconds)
Get the position of the decode head both the current playlist item and the position in seconds in the...
int groove_sink_buffer_peek(struct GrooveSink *sink, int block)
returns < 0 on error, 0 on no buffer ready, 1 on buffer ready if block is 1, block until buffer is re...
struct GroovePlaylistItem * tail
read-only.
Definition: groove.h:152
void groove_file_close(struct GrooveFile *file)
uint8_t ** data
read-only.
Definition: groove.h:165
const char * groove_tag_key(struct GrooveTag *tag)
void groove_playlist_set_fill_mode(struct GroovePlaylist *playlist, enum GrooveFillMode mode)
Use this to set the fill mode using the constants above.
void groove_sink_destroy(struct GrooveSink *sink)
int groove_audio_formats_equal(const struct GrooveAudioFormat *a, const struct GrooveAudioFormat *b)
returns 1 if the audio formats have the same sample rate, channel layout, and sample format...
int disable_resample
Set this flag to ignore audio_format.
Definition: groove.h:200
Definition: groove.h:69
void(* purge)(struct GrooveSink *, struct GroovePlaylistItem *)
called when a playlist item is deleted.
Definition: groove.h:226
const char * filename
read-only
Definition: groove.h:113
struct GrooveFile * groove_file_open(const char *filename)
you are responsible for calling groove_file_close on the returned GrooveFile.
double gain
Read-only.
Definition: groove.h:126
char * groove_create_rand_name(int *out_len, const char *file, int file_len)
given a file path and the length of the file path, allocates a new file path which is in the same dir...
void(* play)(struct GrooveSink *)
called when the playlist is played
Definition: groove.h:230
const char * groove_file_short_names(struct GrooveFile *file)
a comma separated list of short names for the format
struct GroovePlaylistItem * head
read-only.
Definition: groove.h:148
int sample_rate
Definition: groove.h:105
void groove_playlist_set_item_gain_peak(struct GroovePlaylist *playlist, struct GroovePlaylistItem *item, double gain, double peak)
const char * groove_strerror(int error)
struct GrooveAudioFormat audio_format
set this to the audio format you want the sink to output
Definition: groove.h:197
With this behavior, the playlist will stop decoding audio when any attached sink is full...
Definition: groove.h:78
bool is_planar
Definition: groove.h:108
struct GrooveAudioFormat format
read-only
Definition: groove.h:168
struct GroovePlaylistItem * prev
A GroovePlaylist is a doubly linked list.
Definition: groove.h:140
int groove_file_save(struct GrooveFile *file)
write changes made to metadata to disk.
int groove_sink_attach(struct GrooveSink *sink, struct GroovePlaylist *playlist)
before calling this, set audio_format returns 0 on success, < 0 on error
struct GroovePlaylistItem * groove_playlist_insert(struct GroovePlaylist *playlist, struct GrooveFile *file, double gain, double peak, struct GroovePlaylistItem *next)
Once you add a file to the playlist, you must not destroy it until you first remove it from the playl...
GrooveError
See also groove_strerror.
Definition: groove.h:67
void groove_playlist_pause(struct GroovePlaylist *playlist)
use this to get access to a realtime raw audio buffer for example you could use it to draw a waveform...
Definition: groove.h:195
int groove_sink_get_fill_level(struct GrooveSink *sink)
Returns the number of bytes contained in this sink.
int groove_sink_set_gain(struct GrooveSink *sink, double gain)
See the gain property of GrooveSink.
int groove_version_patch(void)
Definition: groove.h:70
enum SoundIoFormat format
Definition: groove.h:107
Definition: groove.h:118
int buffer_sample_count
If you leave this to its default of 0, frames pulled from the sink will have sample count determined ...
Definition: groove.h:205
int groove_playlist_playing(struct GroovePlaylist *playlist)
return 1 if the playlist is playing; 0 if it is not.
int size
read-only total number of bytes contained in this buffer
Definition: groove.h:185
int dirty
read-only
Definition: groove.h:112
int groove_sink_buffer_get(struct GrooveSink *sink, struct GrooveBuffer **buffer, int block)
returns < 0 on error, GROOVE_BUFFER_NO on aborted (block=1) or no buffer ready (block=0), GROOVE_BUFFER_YES on buffer returned, and GROOVE_BUFFER_END on end of playlist.
int frame_count
read-only number of audio frames described by this buffer for encoded audio, this is unknown and set ...
Definition: groove.h:173
const char * groove_tag_value(struct GrooveTag *tag)
int groove_playlist_count(struct GroovePlaylist *playlist)
return the count of playlist items
void(* flush)(struct GrooveSink *)
called when the audio queue is flushed.
Definition: groove.h:223
int groove_init(void)
call once at the beginning of your program from the main thread returns 0 on success, < 0 on error
int groove_sink_detach(struct GrooveSink *sink)
returns 0 on success, < 0 on error
void groove_playlist_clear(struct GroovePlaylist *playlist)
Remove all playlist items.
void groove_playlist_play(struct GroovePlaylist *playlist)
struct GroovePlaylist * groove_playlist_create(void)
A playlist keeps its sinks full.
struct GroovePlaylist * playlist
read-only.
Definition: groove.h:234
double peak
Read-only.
Definition: groove.h:134
struct SoundIoChannelLayout layout
Definition: groove.h:106
const char * groove_version(void)
Definition: groove.h:160
void groove_buffer_unref(struct GrooveBuffer *buffer)
int groove_version_minor(void)
Definition: groove.h:144
Definition: groove.h:68
struct GrooveTag * groove_file_metadata_get(struct GrooveFile *file, const char *key, const struct GrooveTag *prev, int flags)
double gain
read-only.
Definition: groove.h:157
struct GrooveSink * groove_sink_create(void)
uint64_t pts
read-only presentation time stamp of the buffer
Definition: groove.h:189
int buffer_size
how big the buffer queue should be, in sample frames.
Definition: groove.h:209
void * userdata
set to whatever you want, defaults to NULL.
Definition: groove.h:220
void groove_set_logging(int level)
enable/disable logging of errors
int groove_sink_contains_end_of_playlist(struct GrooveSink *sink)
Returns 1 if the sink contains the end of playlist sentinel, 0 otherwise.
void groove_playlist_remove(struct GroovePlaylist *playlist, struct GroovePlaylistItem *item)
This will not call groove_file_close on item->file Item is destroyed and the address it points to is ...
int groove_version_major(void)
double groove_file_duration(struct GrooveFile *file)
main audio stream duration in seconds.
void groove_buffer_ref(struct GrooveBuffer *buffer)
GrooveFillMode
Specifies when the sink will stop decoding.
Definition: groove.h:74
int bytes_per_sec
read-only.
Definition: groove.h:238
void groove_playlist_destroy(struct GroovePlaylist *playlist)
This will not call groove_file_close on any files.
Definition: groove.h:111
void groove_playlist_set_gain(struct GroovePlaylist *playlist, double gain)
With this behavior, the playlist will decode audio if any sinks are not full.
Definition: groove.h:82
void groove_file_audio_format(struct GrooveFile *file, struct GrooveAudioFormat *audio_format)
get the audio format of the main audio stream of a file