A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 by Linus Nielsen Feltzing
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __AUDIO_H
22#define __AUDIO_H
23
24#include <stdbool.h>
25#include <string.h> /* size_t */
26#include "config.h"
27/* These must always be included with audio.h for this to compile under
28 cetain conditions. Do it here or else spread the complication around to
29 many files. */
30#include "pcm_sampr.h"
31#include "pcm.h"
32#ifdef HAVE_RECORDING
33#include "enc_base.h"
34#endif /* HAVE_RECORDING */
35
36#define AUDIO_STATUS_PLAY 0x0001
37#define AUDIO_STATUS_PAUSE 0x0002
38#define AUDIO_STATUS_RECORD 0x0004
39#define AUDIO_STATUS_PRERECORD 0x0008
40#define AUDIO_STATUS_ERROR 0x0010
41#define AUDIO_STATUS_WARNING 0x0020
42
43#define AUDIOERR_DISK_FULL 1
44
45#define AUDIO_GAIN_LINEIN 0
46#define AUDIO_GAIN_MIC 1
47
48
49void audio_init(void) INIT_ATTR;
50void audio_play(unsigned long elapsed, unsigned long offset);
51void audio_stop(void);
52/* Stops audio from serving playback and frees resources*/
53void audio_hard_stop(void);
54void audio_pause(void);
55void audio_resume(void);
56void audio_next(void);
57void audio_prev(void);
58int audio_status(void);
59/* size of the audio buffer */
60size_t audio_buffer_size(void);
61/* size of the buffer available for allocating memory from the audio buffer using core_*()
62 * returns core_available() if audio buffer is not allocated yet */
63size_t audio_buffer_available(void);
64void audio_ff_rewind(long newpos);
65void audio_flush_and_reload_tracks(void);
66struct mp3entry* audio_current_track(void);
67struct mp3entry* audio_next_track(void);
68bool audio_peek_track(struct mp3entry* id3, int offset);
69#ifdef HAVE_DISK_STORAGE
70void audio_set_buffer_margin(int seconds);
71#endif
72void audio_error_clear(void);
73int audio_get_file_pos(void);
74void audio_beep(int duration);
75
76void audio_next_dir(void);
77void audio_prev_dir(void);
78
79/* channel modes */
80enum rec_channel_modes
81{
82 __CHN_MODE_START_INDEX = -1,
83
84 CHN_MODE_STEREO,
85 CHN_MODE_MONO,
86
87 CHN_NUM_MODES
88};
89
90/* channel mode capability bits */
91#define CHN_CAP_STEREO (1 << CHN_MODE_STEREO)
92#define CHN_CAP_MONO (1 << CHN_MODE_MONO)
93#define CHN_CAP_ALL (CHN_CAP_STEREO | CHN_CAP_MONO)
94
95/* the enums below must match prestr[] in recording.c */
96enum audio_sources
97{
98 AUDIO_SRC_PLAYBACK = -1, /* Virtual source */
99 HAVE_MIC_IN_(AUDIO_SRC_MIC,)
100 HAVE_LINE_IN_(AUDIO_SRC_LINEIN,)
101 HAVE_SPDIF_IN_(AUDIO_SRC_SPDIF,)
102 HAVE_FMRADIO_IN_(AUDIO_SRC_FMRADIO,)
103 AUDIO_NUM_SOURCES,
104 AUDIO_SRC_MAX = AUDIO_NUM_SOURCES-1,
105 AUDIO_SRC_DEFAULT = AUDIO_SRC_PLAYBACK
106};
107
108extern int audio_channels;
109extern int audio_output_source;
110
111#ifdef HAVE_RECORDING
112/* Recordable source implies it has the input as well */
113
114/* For now there's no restrictions on any targets with which inputs
115 are recordable so define them as equivalent - if they do differ,
116 special handling is needed right now. */
117enum rec_sources
118{
119 __REC_SRC_FIRST = -1,
120 HAVE_MIC_REC_(REC_SRC_MIC,)
121 HAVE_LINE_REC_(REC_SRC_LINEIN,)
122 HAVE_SPDIF_REC_(REC_SRC_SPDIF,)
123 HAVE_FMRADIO_REC_(REC_SRC_FMRADIO,)
124 REC_NUM_SOURCES
125};
126#endif /* HAVE_RECORDING */
127
128/* selects a source to monitor for recording or playback */
129#define SRCF_PLAYBACK 0x0000 /* default */
130#define SRCF_RECORDING 0x1000
131#if CONFIG_TUNER
132/* for AUDIO_SRC_FMRADIO */
133#define SRCF_FMRADIO_PLAYING 0x0000 /* default */
134#define SRCF_FMRADIO_PAUSED 0x2000
135#endif
136
137#ifdef HAVE_RECORDING
138/* parameters for audio_set_recording_options */
139struct audio_recording_options
140{
141 int rec_source;
142 int rec_frequency;
143 int rec_channels;
144 int rec_prerecord_time;
145 int rec_mono_mode;
146 int rec_source_flags; /* for rec_set_source */
147 struct encoder_config enc_config;
148};
149
150/* audio recording functions */
151void audio_init_recording(void);
152void audio_close_recording(void);
153void audio_record(const char *filename);
154void audio_stop_recording(void);
155void audio_pause_recording(void);
156void audio_resume_recording(void);
157void audio_set_recording_options(struct audio_recording_options *options);
158void audio_set_recording_gain(int left, int right, int type);
159unsigned long audio_recorded_time(void);
160unsigned long audio_num_recorded_bytes(void);
161
162unsigned long audio_prerecorded_time(void);
163
164#endif /* HAVE_RECORDING */
165
166#if INPUT_SRC_CAPS != 0
167/* audio.c */
168void audio_set_input_source(int source, unsigned flags);
169/* audio_input_mux: target-specific implementation used by audio_set_source
170 to set hardware inputs and audio paths */
171void audio_input_mux(int source, unsigned flags);
172void audio_set_output_source(int source);
173#endif /* INPUT_SRC_CAPS */
174
175#ifdef HAVE_SPDIF_IN
176/* returns index into rec_master_sampr_list */
177int audio_get_spdif_sample_rate(void);
178/* > 0: monitor EBUin, 0: Monitor IISrecv, <0: reset only */
179void audio_spdif_set_monitor(int monitor_spdif);
180#endif /* HAVE_SPDIF_IN */
181
182#ifdef HAVE_SPEAKER
183/* enable/disable the speaker: 0=off, 1=on, 2=on if jack unpluged, off otherwise
184 * NOTE this is a one time thing, this function doesn't implement the logic to
185 * check for jack events, it merely changes the speaker state to the expected
186 * state based on the requested mode.
187 */
188void audio_enable_speaker(int mode);
189#endif
190
191/***********************************************************************/
192/* audio event handling */
193enum track_event_flags
194{
195 TEF_NONE = 0x0, /* no flags are set */
196 TEF_CURRENT = 0x1, /* event is for the current track */
197 TEF_AUTO_SKIP = 0x2, /* event is sent in context of auto skip */
198 TEF_REWIND = 0x4, /* interpret as rewind, id3->elapsed is the
199 position before the seek back to 0 */
200};
201
202struct track_event
203{
204 unsigned int flags; /* combo of enum track_event_flags values */
205 struct mp3entry *id3; /* pointer to mp3entry describing track */
206};
207
208#endif /* __AUDIO_H */