RetroArch
audio_driver.h
Go to the documentation of this file.
1 /* RetroArch - A frontend for libretro.
2  * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  * Copyright (C) 2011-2017 - Daniel De Matteis
4  *
5  * RetroArch is free software: you can redistribute it and/or modify it under the terms
6  * of the GNU General Public License as published by the Free Software Found-
7  * ation, either version 3 of the License, or (at your option) any later version.
8  *
9  * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  * PURPOSE. See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along with RetroArch.
14  * If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __AUDIO_DRIVER__H
18 #define __AUDIO_DRIVER__H
19 
20 #include <stdint.h>
21 #include <stddef.h>
22 #include <sys/types.h>
23 
24 #include <boolean.h>
25 #include <audio/audio_mixer.h>
26 #include <audio/audio_resampler.h>
27 #include <retro_common_api.h>
28 
30 
31 #define AUDIO_CHUNK_SIZE_BLOCKING 512
32 
33 /* So we don't get complete line-noise when fast-forwarding audio. */
34 #define AUDIO_CHUNK_SIZE_NONBLOCKING 2048
35 
36 #define AUDIO_MAX_RATIO 16
37 
38 #define AUDIO_MIXER_MAX_STREAMS 16
39 
41 {
49 };
50 
52 {
58 };
59 
60 typedef struct audio_mixer_stream
61 {
66  float volume;
67  void *buf;
68  char *name;
69  size_t bufsize;
71 
72 typedef struct audio_statistics
73 {
78  unsigned samples;
80 
81 typedef struct audio_driver
82 {
83  /* Creates and initializes handle to audio driver.
84  *
85  * Returns: audio driver handle on success, otherwise NULL.
86  **/
87  void *(*init)(const char *device, unsigned rate,
88  unsigned latency, unsigned block_frames, unsigned *new_rate);
89 
90  /*
91  * @data : Pointer to audio data handle.
92  * @buf : Audio buffer data.
93  * @size : Size of audio buffer.
94  *
95  * Write samples to audio driver.
96  *
97  * Write data in buffer to audio driver.
98  * A frame here is defined as one combined sample of left and right
99  * channels. (I.e. 44.1kHz, 16-bit stereo has 88.2k samples/s, and
100  * 44.1k frames/s.)
101  *
102  * Samples are interleaved in format LRLRLRLRLR ...
103  * If the driver returns true in use_float(), a floating point
104  * format will be used, with range [-1.0, 1.0].
105  * If not, signed 16-bit samples in native byte ordering will be used.
106  *
107  * This function returns the number of frames successfully written.
108  * If an error occurs, -1 should be returned.
109  * Note that non-blocking behavior that cannot write at this time
110  * should return 0 as returning -1 will terminate the driver.
111  *
112  * Unless said otherwise with set_nonblock_state(), all writes
113  * are blocking, and it should block till it has written all frames.
114  */
115  ssize_t (*write)(void *data, const void *buf, size_t size);
116 
117  /* Temporarily pauses the audio driver. */
118  bool (*stop)(void *data);
119 
120  /* Resumes audio driver from the paused state. */
121  bool (*start)(void *data, bool is_shutdown);
122 
123  /* Is the audio driver currently running? */
124  bool (*alive)(void *data);
125 
126  /* Should we care about blocking in audio thread? Fast forwarding.
127  *
128  * If state is true, nonblocking operation is assumed.
129  * This is typically used for fast-forwarding. If driver cannot
130  * implement nonblocking writes, this can be disregarded, but should
131  * log a message to stderr.
132  * */
133  void (*set_nonblock_state)(void *data, bool toggle);
134 
135  /* Stops and frees driver data. */
136  void (*free)(void *data);
137 
138  /* Defines if driver will take standard floating point samples,
139  * or int16_t samples.
140  *
141  * If true is returned, the audio driver is capable of using
142  * floating point data. This will likely increase performance as the
143  * resampler unit uses floating point. The sample range is
144  * [-1.0, 1.0].
145  * */
146  bool (*use_float)(void *data);
147 
148  /* Human-readable identifier. */
149  const char *ident;
150 
151  /* Optional. Get audio device list (allocates, caller has to free this) */
152  void *(*device_list_new)(void *data);
153 
154  /* Optional. Frees audio device list */
155  void (*device_list_free)(void *data, void *data2);
156 
157  /* Optional. */
158  size_t (*write_avail)(void *data);
159 
160  size_t (*buffer_size)(void *data);
162 
164 {
165  float volume;
168  void *buf;
169  char *basename;
170  size_t bufsize;
173 
174 void audio_driver_destroy_data(void);
175 
176 void audio_driver_set_own_driver(void);
177 
179 
180 void audio_driver_suspend(void);
181 
182 bool audio_driver_is_suspended(void);
183 
184 void audio_driver_resume(void);
185 
186 void audio_driver_set_active(void);
187 
188 bool audio_driver_is_active(void);
189 
190 void audio_driver_destroy(void);
191 
193 
195 
197 
199 
201 
209 const void *audio_driver_find_handle(int index);
210 
218 const char *audio_driver_find_ident(int index);
219 
221 
229 const char* config_get_audio_driver_options(void);
230 
232 
233 size_t audio_driver_sample_batch(const int16_t *data, size_t frames);
234 
236 
237 size_t audio_driver_sample_batch_rewind(const int16_t *data, size_t frames);
238 
239 bool audio_driver_mixer_extension_supported(const char *ext);
240 
242 
243 void audio_driver_dsp_filter_init(const char *device);
244 
246 
248 
249 void audio_driver_setup_rewind(void);
250 
252 
253 bool audio_driver_set_callback(const void *data);
254 
255 bool audio_driver_callback(void);
256 
257 bool audio_driver_has_callback(void);
258 
259 /* Sets audio monitor rate to new value. */
261 
262 bool audio_driver_find_driver(void);
263 
264 bool audio_driver_toggle_mute(void);
265 
266 bool audio_driver_start(bool is_shutdown);
267 
268 bool audio_driver_stop(void);
269 
270 bool audio_driver_owns_driver(void);
271 
272 void audio_driver_unset_callback(void);
273 
275 
276 void audio_set_float(enum audio_action action, float val);
277 
278 void audio_set_bool(enum audio_action action, bool val);
279 
280 void audio_unset_bool(enum audio_action action, bool val);
281 
282 float *audio_get_float_ptr(enum audio_action action);
283 
284 bool *audio_get_bool_ptr(enum audio_action action);
285 
286 bool audio_driver_deinit(void);
287 
288 bool audio_driver_init(void);
289 
290 void audio_driver_menu_sample(void);
291 
293 
295 
296 void audio_driver_mixer_play_stream(unsigned i);
297 
299 
301 
302 void audio_driver_mixer_stop_stream(unsigned i);
303 
304 float audio_driver_mixer_get_stream_volume(unsigned i);
305 
306 void audio_driver_mixer_set_stream_volume(unsigned i, float vol);
307 
308 void audio_driver_mixer_remove_stream(unsigned i);
309 
311 
313 
314 const char *audio_driver_mixer_get_stream_name(unsigned i);
315 
317 
329 extern audio_driver_t audio_xa;
336 extern audio_driver_t audio_gx;
337 extern audio_driver_t audio_ax;
346 
348 
349 #endif
Definition: audio_driver.h:48
bool audio_driver_owns_driver(void)
Definition: audio_driver.c:1547
void(* set_nonblock_state)(void *data, bool toggle)
Definition: audio_driver.h:133
void audio_driver_sample(int16_t left, int16_t right)
Definition: audio_driver.c:738
audio_driver_t audio_ctr_dsp
Definition: ctr_dsp_audio.c:199
void audio_driver_set_own_driver(void)
Definition: audio_driver.c:1537
float volume
Definition: audio_driver.h:66
Definition: audio_driver.h:60
const GLvoid * ptr
Definition: nx_glsym.h:242
audio_mixer_state
Definition: audio_driver.h:51
void audio_driver_mixer_remove_stream(unsigned i)
Definition: audio_driver.c:1347
struct audio_statistics audio_statistics_t
bool * audio_get_bool_ptr(enum audio_action action)
Definition: audio_driver.c:1631
enum audio_mixer_type type
Definition: audio_driver.h:166
audio_mixer_stream_t * audio_driver_mixer_get_stream(unsigned i)
Definition: audio_driver.c:204
GLuint GLfloat * val
Definition: glext.h:7847
void audio_driver_dsp_filter_init(const char *device)
Definition: audio_driver.c:846
void audio_driver_setup_rewind(void)
Definition: audio_driver.c:911
audio_driver_t audio_coreaudio
Definition: coreaudio.c:449
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
audio_mixer_voice_t * voice
Definition: audio_driver.h:63
audio_driver_t audio_switch_thread
Definition: switch_thread_audio.c:432
audio_driver_t audio_wasapi
Definition: wasapi.c:1075
GLenum const GLfloat * params
Definition: glext.h:6297
audio_mixer_stop_cb_t stop_cb
Definition: audio_driver.h:64
bool audio_driver_mixer_extension_supported(const char *ext)
Definition: audio_driver.c:1014
GLuint start
Definition: glext.h:6292
audio_driver_t audio_pulse
Definition: pulse.c:344
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:8418
void audio_driver_unset_callback(void)
Definition: audio_driver.c:1518
struct audio_mixer_stream audio_mixer_stream_t
void audio_driver_monitor_set_rate(void)
Definition: audio_driver.c:1441
Definition: audio_driver.h:81
bool audio_driver_stop(void)
Definition: audio_driver.c:1508
bool audio_driver_mixer_add_stream(audio_mixer_stream_params_t *params)
Definition: audio_driver.c:1159
float std_deviation_percentage
Definition: audio_driver.h:75
audio_driver_t audio_tinyalsa
Definition: tinyalsa.c:2421
const char * config_get_audio_driver_options(void)
Definition: audio_driver.c:344
enum audio_mixer_state state
Definition: audio_driver.h:167
GLsizeiptr size
Definition: glext.h:6559
const char * audio_driver_mixer_get_stream_name(unsigned i)
Definition: audio_driver.c:211
const char * ident
Definition: audio_driver.h:149
GLboolean enable
Definition: glext.h:12027
audio_mixer_sound_t * handle
Definition: audio_driver.h:62
bool audio_driver_disable_callback(void)
Definition: audio_driver.c:1430
void(* device_list_free)(void *data, void *data2)
Definition: audio_driver.h:155
bool audio_driver_start(bool is_shutdown)
Definition: audio_driver.c:1490
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
Definition: audio_driver.h:47
Definition: audio_driver.h:72
bool audio_driver_find_driver(void)
Definition: audio_driver.c:932
bool audio_driver_is_active(void)
Definition: audio_driver.c:1572
Definition: ibxm.h:9
GLdouble GLdouble right
Definition: glext.h:11766
void * buf
Definition: audio_driver.h:168
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
void(* audio_mixer_stop_cb_t)(audio_mixer_sound_t *sound, unsigned reason)
Definition: audio_mixer.h:52
typedef bool(RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index
void audio_driver_resume(void)
Definition: audio_driver.c:1562
char * basename
Definition: audio_driver.h:169
audio_driver_t audio_alsathread
Definition: alsathread.c:406
GLenum GLuint GLsizei bufsize
Definition: glext.h:8140
void audio_driver_mixer_play_stream_sequential(unsigned i)
Definition: audio_driver.c:1288
bool compute_audio_buffer_statistics(audio_statistics_t *stats)
Definition: audio_driver.c:226
Definition: audio_driver.h:53
const void * audio_driver_find_handle(int index)
Definition: audio_driver.c:314
Definition: audio_driver.h:42
void audio_driver_mixer_play_stream(unsigned i)
Definition: audio_driver.c:1276
audio_driver_t audio_ps3
Definition: ps3_audio.c:239
audio_action
Definition: audio_driver.h:40
Definition: audio_driver.h:56
void audio_driver_dsp_filter_free(void)
Definition: audio_driver.c:839
size_t bufsize
Definition: audio_driver.h:69
size_t audio_driver_sample_batch(const int16_t *data, size_t frames)
Definition: audio_driver.c:781
Definition: audio_driver.h:55
bool(* stop)(void *data)
Definition: audio_driver.h:118
Definition: audio_driver.h:43
float audio_driver_mixer_get_stream_volume(unsigned i)
Definition: audio_driver.c:1294
audio_driver_t audio_switch
Definition: switch_audio.c:350
bool audio_driver_deinit(void)
Definition: audio_driver.c:1402
float average_buffer_saturation
Definition: audio_driver.h:74
bool audio_driver_get_devices_list(void **ptr)
Definition: audio_driver.c:1005
float * audio_get_float_ptr(enum audio_action action)
Definition: audio_driver.c:1617
Definition: audio_driver.h:46
float close_to_blocking
Definition: audio_driver.h:77
bool audio_driver_callback(void)
Definition: audio_driver.c:1451
bool(* alive)(void *data)
Definition: audio_driver.h:124
signed short int16_t
Definition: stdint.h:122
audio_driver_t audio_ax
Definition: wiiu_audio.c:322
bool(* use_float)(void *data)
Definition: audio_driver.h:146
char * name
Definition: audio_driver.h:68
audio_driver_t audio_dsound
Definition: dsound.c:517
audio_mixer_type
Definition: audio_mixer.h:39
Definition: audio_mixer.c:121
audio_driver_t audio_sdl
Definition: sdl_audio.c:257
bool audio_driver_free_devices_list(void)
Definition: audio_driver.c:977
Definition: audio_mixer.c:70
static struct frame frames[2]
Definition: ffmpeg_core.c:162
audio_driver_t audio_opensl
Definition: opensl.c:307
audio_driver_t audio_null
Definition: nullaudio.c:82
Definition: audio_driver.h:45
bool audio_driver_new_devices_list(void)
Definition: audio_driver.c:988
void audio_driver_monitor_adjust_system_rates(void)
Definition: audio_driver.c:888
bool audio_driver_enable_callback(void)
Definition: audio_driver.c:1421
audio_driver_t audio_oss
Definition: oss.c:201
struct audio_mixer_stream_params audio_mixer_stream_params_t
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
void audio_driver_mixer_stop_stream(unsigned i)
Definition: audio_driver.c:1317
float close_to_underrun
Definition: audio_driver.h:76
size_t(* write_avail)(void *data)
Definition: audio_driver.h:158
const char * audio_driver_find_ident(int index)
Definition: audio_driver.c:329
enum resampler_quality audio_driver_get_resampler_quality(void)
Definition: audio_driver.c:194
void audio_driver_sample_rewind(int16_t left, int16_t right)
Definition: audio_driver.c:803
GLuint index
Definition: glext.h:6671
void audio_set_float(enum audio_action action, float val)
Definition: audio_driver.c:1598
bool audio_driver_is_suspended(void)
Definition: audio_driver.c:1557
void audio_driver_suspend(void)
Definition: audio_driver.c:1552
void audio_set_bool(enum audio_action action, bool val)
Definition: audio_driver.c:1584
audio_driver_t audio_audioio
Definition: audioio.c:190
void audio_driver_deinit_resampler(void)
Definition: audio_driver.c:969
Definition: audio_driver.h:54
bool audio_driver_set_callback(const void *data)
Definition: audio_driver.c:1411
Definition: audio_driver.h:44
void audio_driver_set_active(void)
Definition: audio_driver.c:1567
bool audio_driver_has_callback(void)
Definition: audio_driver.c:1462
bool audio_driver_toggle_mute(void)
Definition: audio_driver.c:1469
audio_driver_t audio_ctr_csnd
Definition: ctr_csnd_audio.c:293
unsigned samples
Definition: audio_driver.h:78
void audio_unset_bool(enum audio_action action, bool val)
audio_driver_t audio_rwebaudio
Definition: rwebaudio.c:104
audio_mixer_stop_cb_t cb
Definition: audio_driver.h:171
enum audio_mixer_state state
Definition: audio_driver.h:65
ssize_t(* write)(void *data, const void *buf, size_t size)
Definition: audio_driver.h:115
float volume
Definition: audio_driver.h:165
enum audio_mixer_state audio_driver_mixer_get_stream_state(unsigned i)
Definition: audio_driver.c:1242
size_t bufsize
Definition: audio_driver.h:170
void audio_driver_unset_own_driver(void)
Definition: audio_driver.c:1542
void audio_driver_frame_is_reverse(void)
Definition: audio_driver.c:1524
struct audio_driver audio_driver_t
audio_driver_t audio_rsound
Definition: rsound.c:229
void(* free)(void *data)
Definition: audio_driver.h:136
audio_driver_t audio_xa
Definition: xaudio.c:429
audio_driver_t audio_roar
Definition: roar.c:139
audio_driver_t audio_jack
Definition: jack.c:374
audio_driver_t audio_psp
Definition: psp_audio.c:298
void * buf
Definition: audio_driver.h:67
Definition: audio_driver.h:163
void audio_driver_destroy(void)
Definition: audio_driver.c:1577
audio_driver_t audio_alsa
Definition: alsa.c:406
audio_driver_t audio_xenon360
Definition: xenon360_audio.c:140
void audio_driver_set_buffer_size(size_t bufsize)
Definition: audio_driver.c:883
audio_driver_t audio_gx
Definition: gx_audio.c:225
void audio_driver_destroy_data(void)
Definition: audio_driver.c:1532
GLint left
Definition: glext.h:8393
void audio_driver_menu_sample(void)
Definition: audio_driver.c:755
size_t audio_driver_sample_batch_rewind(const int16_t *data, size_t frames)
Definition: audio_driver.c:825
audio_driver_t audio_openal
Definition: openal.c:266
bool audio_driver_init(void)
Definition: audio_driver.c:1000
void audio_driver_set_nonblocking_state(bool enable)
Definition: audio_driver.c:582
struct nk_device device
Definition: nk_common.c:44
Definition: audio_driver.h:57
audio_driver_t audio_ps2
Definition: ps2_audio.c:283
void audio_driver_mixer_set_stream_volume(unsigned i, float vol)
Definition: audio_driver.c:1302
size_t(* buffer_size)(void *data)
Definition: audio_driver.h:160
resampler_quality
Definition: audio_resampler.h:50
void audio_driver_mixer_play_stream_looped(unsigned i)
Definition: audio_driver.c:1282