cubeb 0.0.0
Loading...
Searching...
No Matches
cubeb.h
Go to the documentation of this file.
1/*
2 * Copyright © 2011 Mozilla Foundation
3 *
4 * This program is made available under an ISC-style license. See the
5 * accompanying file LICENSE for details.
6 */
7#if !defined(CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382)
8#define CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382
9
10#include "cubeb_export.h"
11#include <stdint.h>
12#include <stdlib.h>
13
14#if defined(__cplusplus)
15extern "C" {
16#endif
17
125typedef struct cubeb
127typedef struct cubeb_stream
131typedef enum {
140#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
144 CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32BE
145#else
149 CUBEB_SAMPLE_FLOAT32NE = CUBEB_SAMPLE_FLOAT32LE
150#endif
152
155typedef void const * cubeb_devid;
156
158typedef enum {
159 CUBEB_LOG_DISABLED = 0,
161 1,
165
167typedef enum {
168 CHANNEL_UNKNOWN = 0,
169 CHANNEL_FRONT_LEFT = 1 << 0,
170 CHANNEL_FRONT_RIGHT = 1 << 1,
171 CHANNEL_FRONT_CENTER = 1 << 2,
172 CHANNEL_LOW_FREQUENCY = 1 << 3,
173 CHANNEL_BACK_LEFT = 1 << 4,
174 CHANNEL_BACK_RIGHT = 1 << 5,
175 CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6,
176 CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7,
177 CHANNEL_BACK_CENTER = 1 << 8,
178 CHANNEL_SIDE_LEFT = 1 << 9,
179 CHANNEL_SIDE_RIGHT = 1 << 10,
180 CHANNEL_TOP_CENTER = 1 << 11,
181 CHANNEL_TOP_FRONT_LEFT = 1 << 12,
182 CHANNEL_TOP_FRONT_CENTER = 1 << 13,
183 CHANNEL_TOP_FRONT_RIGHT = 1 << 14,
184 CHANNEL_TOP_BACK_LEFT = 1 << 15,
185 CHANNEL_TOP_BACK_CENTER = 1 << 16,
186 CHANNEL_TOP_BACK_RIGHT = 1 << 17
188
192typedef uint32_t cubeb_channel_layout;
193// Some common layout definitions.
194enum {
195 CUBEB_LAYOUT_UNDEFINED = 0, // Indicate the speaker's layout is undefined.
196 CUBEB_LAYOUT_MONO = CHANNEL_FRONT_CENTER,
197 CUBEB_LAYOUT_MONO_LFE = CUBEB_LAYOUT_MONO | CHANNEL_LOW_FREQUENCY,
198 CUBEB_LAYOUT_STEREO = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT,
199 CUBEB_LAYOUT_STEREO_LFE = CUBEB_LAYOUT_STEREO | CHANNEL_LOW_FREQUENCY,
200 CUBEB_LAYOUT_3F =
201 CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_FRONT_CENTER,
202 CUBEB_LAYOUT_3F_LFE = CUBEB_LAYOUT_3F | CHANNEL_LOW_FREQUENCY,
203 CUBEB_LAYOUT_2F1 =
204 CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_BACK_CENTER,
205 CUBEB_LAYOUT_2F1_LFE = CUBEB_LAYOUT_2F1 | CHANNEL_LOW_FREQUENCY,
206 CUBEB_LAYOUT_3F1 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
207 CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER,
208 CUBEB_LAYOUT_3F1_LFE = CUBEB_LAYOUT_3F1 | CHANNEL_LOW_FREQUENCY,
209 CUBEB_LAYOUT_2F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
210 CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT,
211 CUBEB_LAYOUT_2F2_LFE = CUBEB_LAYOUT_2F2 | CHANNEL_LOW_FREQUENCY,
212 CUBEB_LAYOUT_QUAD = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
213 CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT,
214 CUBEB_LAYOUT_QUAD_LFE = CUBEB_LAYOUT_QUAD | CHANNEL_LOW_FREQUENCY,
215 CUBEB_LAYOUT_3F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
216 CHANNEL_FRONT_CENTER | CHANNEL_SIDE_LEFT |
217 CHANNEL_SIDE_RIGHT,
218 CUBEB_LAYOUT_3F2_LFE = CUBEB_LAYOUT_3F2 | CHANNEL_LOW_FREQUENCY,
219 CUBEB_LAYOUT_3F2_BACK = CUBEB_LAYOUT_QUAD | CHANNEL_FRONT_CENTER,
220 CUBEB_LAYOUT_3F2_LFE_BACK = CUBEB_LAYOUT_3F2_BACK | CHANNEL_LOW_FREQUENCY,
221 CUBEB_LAYOUT_3F3R_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
222 CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY |
223 CHANNEL_BACK_CENTER | CHANNEL_SIDE_LEFT |
224 CHANNEL_SIDE_RIGHT,
225 CUBEB_LAYOUT_3F4_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT |
226 CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY |
227 CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT |
228 CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT,
229};
230
260
265typedef enum {
266 CUBEB_INPUT_PROCESSING_PARAM_NONE = 0x00,
267 CUBEB_INPUT_PROCESSING_PARAM_ECHO_CANCELLATION = 0x01,
268 CUBEB_INPUT_PROCESSING_PARAM_NOISE_SUPPRESSION = 0x02,
269 CUBEB_INPUT_PROCESSING_PARAM_AUTOMATIC_GAIN_CONTROL = 0x04,
270 CUBEB_INPUT_PROCESSING_PARAM_VOICE_ISOLATION = 0x08,
272
287
289typedef struct {
290 char * output_name;
291 char * input_name;
293
301
303enum {
307 -2,
310 -4,
312 -5
314
318typedef enum {
319 CUBEB_DEVICE_TYPE_UNKNOWN,
320 CUBEB_DEVICE_TYPE_INPUT,
321 CUBEB_DEVICE_TYPE_OUTPUT
323
334
344
345#if defined(WORDS_BIGENDIAN) || defined(__BIG_ENDIAN__)
347#define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16BE
350#define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32BE
351#else
353#define CUBEB_DEVICE_FMT_S16NE CUBEB_DEVICE_FMT_S16LE
356#define CUBEB_DEVICE_FMT_F32NE CUBEB_DEVICE_FMT_F32LE
357#endif
359#define CUBEB_DEVICE_FMT_S16_MASK \
360 (CUBEB_DEVICE_FMT_S16LE | CUBEB_DEVICE_FMT_S16BE)
362#define CUBEB_DEVICE_FMT_F32_MASK \
363 (CUBEB_DEVICE_FMT_F32LE | CUBEB_DEVICE_FMT_F32BE)
365#define CUBEB_DEVICE_FMT_ALL \
366 (CUBEB_DEVICE_FMT_S16_MASK | CUBEB_DEVICE_FMT_F32_MASK)
367
372typedef enum {
373 CUBEB_DEVICE_PREF_NONE = 0x00,
374 CUBEB_DEVICE_PREF_MULTIMEDIA = 0x01,
375 CUBEB_DEVICE_PREF_VOICE = 0x02,
376 CUBEB_DEVICE_PREF_NOTIFICATION = 0x04,
377 CUBEB_DEVICE_PREF_ALL = 0x0F
379
411
419
421typedef struct {
422 const char * const *
424 size_t count;
426
449typedef long (*cubeb_data_callback)(cubeb_stream * stream, void * user_ptr,
450 void const * input_buffer,
451 void * output_buffer, long nframes);
452
457typedef void (*cubeb_state_callback)(cubeb_stream * stream, void * user_ptr,
458 cubeb_state state);
459
463typedef void (*cubeb_device_changed_callback)(void * user_ptr);
464
473 void * user_ptr);
474
476typedef void (*cubeb_log_callback)(char const * fmt, ...);
477
496CUBEB_EXPORT int
497cubeb_init(cubeb ** context, char const * context_name,
498 char const * backend_name);
499
503CUBEB_EXPORT char const *
505
509CUBEB_EXPORT cubeb_backend_names
511
519CUBEB_EXPORT int
520cubeb_get_max_channel_count(cubeb * context, uint32_t * max_channels);
521
533CUBEB_EXPORT int
535 uint32_t * latency_frames);
536
544CUBEB_EXPORT int
545cubeb_get_preferred_sample_rate(cubeb * context, uint32_t * rate);
546
555CUBEB_EXPORT int
557 cubeb * context, cubeb_input_processing_params * params);
558
562CUBEB_EXPORT void
564
597CUBEB_EXPORT int
599 char const * stream_name, cubeb_devid input_device,
600 cubeb_stream_params * input_stream_params,
601 cubeb_devid output_device,
602 cubeb_stream_params * output_stream_params,
603 uint32_t latency_frames, cubeb_data_callback data_callback,
604 cubeb_state_callback state_callback, void * user_ptr);
605
609CUBEB_EXPORT void
611
616CUBEB_EXPORT int
618
623CUBEB_EXPORT int
625
631CUBEB_EXPORT int
632cubeb_stream_get_position(cubeb_stream * stream, uint64_t * position);
633
642CUBEB_EXPORT int
643cubeb_stream_get_latency(cubeb_stream * stream, uint32_t * latency);
644
654CUBEB_EXPORT int
655cubeb_stream_get_input_latency(cubeb_stream * stream, uint32_t * latency);
663CUBEB_EXPORT int
664cubeb_stream_set_volume(cubeb_stream * stream, float volume);
665
672CUBEB_EXPORT int
673cubeb_stream_set_name(cubeb_stream * stream, char const * stream_name);
674
682CUBEB_EXPORT int
684 cubeb_device ** const device);
685
695CUBEB_EXPORT int
697
706CUBEB_EXPORT int
709
716CUBEB_EXPORT int
718
727CUBEB_EXPORT int
729 cubeb_stream * stream,
730 cubeb_device_changed_callback device_changed_callback);
731
736CUBEB_EXPORT void *
738
747CUBEB_EXPORT int
749 cubeb_device_collection * collection);
750
756CUBEB_EXPORT int
758 cubeb_device_collection * collection);
759
776CUBEB_EXPORT int
778 cubeb * context, cubeb_device_type devtype,
779 cubeb_device_collection_changed_callback callback, void * user_ptr);
780
789CUBEB_EXPORT int
791 cubeb_log_callback log_callback);
792
793#if defined(__cplusplus)
794}
795#endif
796
797#endif /* CUBEB_c2f983e9_c96f_e71c_72c3_bbf62992a382 */
CUBEB_EXPORT cubeb_backend_names cubeb_get_backend_names()
Get a read-only array of strings identifying available backends.
CUBEB_EXPORT int cubeb_get_preferred_sample_rate(cubeb *context, uint32_t *rate)
Get the preferred sample rate for this backend: this is hardware and platform dependent,...
void const * cubeb_devid
An opaque handle used to refer a particular input or output device across calls.
Definition cubeb.h:155
CUBEB_EXPORT int cubeb_stream_get_current_device(cubeb_stream *stm, cubeb_device **const device)
Get the current output device for this stream.
cubeb_channel
A single channel position, to be used in a bitmask.
Definition cubeb.h:167
CUBEB_EXPORT char const * cubeb_get_backend_id(cubeb *context)
Get a read-only string identifying this context's current backend.
void(* cubeb_device_collection_changed_callback)(cubeb *context, void *user_ptr)
User supplied callback called when the underlying device collection changed.
Definition cubeb.h:472
cubeb_device_type
Whether a particular device is an input device (e.g.
Definition cubeb.h:318
CUBEB_EXPORT int cubeb_register_device_collection_changed(cubeb *context, cubeb_device_type devtype, cubeb_device_collection_changed_callback callback, void *user_ptr)
Registers a callback which is called when the system detects a new device or a device is removed,...
CUBEB_EXPORT int cubeb_enumerate_devices(cubeb *context, cubeb_device_type devtype, cubeb_device_collection *collection)
Returns enumerated devices.
CUBEB_EXPORT int cubeb_stream_device_destroy(cubeb_stream *stream, cubeb_device *devices)
Destroy a cubeb_device structure.
CUBEB_EXPORT int cubeb_stream_get_input_latency(cubeb_stream *stream, uint32_t *latency)
Get the input latency for this stream, in frames.
cubeb_device_pref
Channel type for a cubeb_stream.
Definition cubeb.h:372
CUBEB_EXPORT int cubeb_stream_set_volume(cubeb_stream *stream, float volume)
Set the volume for a stream.
void(* cubeb_log_callback)(char const *fmt,...)
User supplied callback called when a message needs logging.
Definition cubeb.h:476
CUBEB_EXPORT int cubeb_set_log_callback(cubeb_log_level log_level, cubeb_log_callback log_callback)
Set a callback to be called with a message.
CUBEB_EXPORT int cubeb_stream_set_input_processing_params(cubeb_stream *stream, cubeb_input_processing_params params)
Set what input processing features to enable for this stream.
void(* cubeb_device_changed_callback)(void *user_ptr)
User supplied callback called when the underlying device changed.
Definition cubeb.h:463
struct cubeb cubeb
Opaque handle referencing the application state.
Definition cubeb.h:125
CUBEB_EXPORT int cubeb_stream_register_device_changed_callback(cubeb_stream *stream, cubeb_device_changed_callback device_changed_callback)
Set a callback to be notified when the output device changes.
CUBEB_EXPORT int cubeb_stream_start(cubeb_stream *stream)
Start playback.
CUBEB_EXPORT int cubeb_stream_init(cubeb *context, cubeb_stream **stream, char const *stream_name, cubeb_devid input_device, cubeb_stream_params *input_stream_params, cubeb_devid output_device, cubeb_stream_params *output_stream_params, uint32_t latency_frames, cubeb_data_callback data_callback, cubeb_state_callback state_callback, void *user_ptr)
Initialize a stream associated with the supplied application context.
long(* cubeb_data_callback)(cubeb_stream *stream, void *user_ptr, void const *input_buffer, void *output_buffer, long nframes)
User supplied data callback.
Definition cubeb.h:449
cubeb_sample_format
Sample format enumeration.
Definition cubeb.h:131
@ CUBEB_SAMPLE_FLOAT32LE
Big endian 32-bit IEEE floating point PCM.
Definition cubeb.h:137
@ CUBEB_SAMPLE_FLOAT32BE
Native endian 16-bit signed PCM.
Definition cubeb.h:139
@ CUBEB_SAMPLE_S16BE
Little endian 32-bit IEEE floating point PCM.
Definition cubeb.h:135
@ CUBEB_SAMPLE_S16LE
Little endian 16-bit signed PCM.
Definition cubeb.h:133
@ CUBEB_SAMPLE_S16NE
Native endian 32-bit IEEE floating point PCM.
Definition cubeb.h:147
cubeb_device_state
The state of a device.
Definition cubeb.h:327
@ CUBEB_DEVICE_STATE_DISABLED
The device has been disabled at the system level.
Definition cubeb.h:328
@ CUBEB_DEVICE_STATE_ENABLED
The device is enabled.
Definition cubeb.h:332
@ CUBEB_DEVICE_STATE_UNPLUGGED
The device is enabled, but nothing is plugged into it.
Definition cubeb.h:330
CUBEB_EXPORT int cubeb_stream_set_input_mute(cubeb_stream *stream, int mute)
Set input mute state for this stream.
CUBEB_EXPORT int cubeb_get_max_channel_count(cubeb *context, uint32_t *max_channels)
Get the maximum possible number of channels.
CUBEB_EXPORT int cubeb_get_supported_input_processing_params(cubeb *context, cubeb_input_processing_params *params)
Get the supported input processing features for this backend.
cubeb_stream_prefs
Miscellaneous stream preferences.
Definition cubeb.h:232
@ CUBEB_STREAM_PREF_JACK_NO_AUTO_CONNECT
Don't automatically try to connect ports.
Definition cubeb.h:256
@ CUBEB_STREAM_PREF_NONE
No stream preferences are requested.
Definition cubeb.h:233
@ CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING
Disable switching default device on OS changes.
Definition cubeb.h:239
@ CUBEB_STREAM_PREF_PERSIST
Request that the volume and mute settings should persist across restarts of the stream and/or applica...
Definition cubeb.h:252
@ CUBEB_STREAM_PREF_RAW
Windows only.
Definition cubeb.h:249
@ CUBEB_STREAM_PREF_VOICE
This stream is going to transport voice data.
Definition cubeb.h:242
@ CUBEB_STREAM_PREF_LOOPBACK
Request a loopback stream.
Definition cubeb.h:234
CUBEB_EXPORT int cubeb_stream_get_latency(cubeb_stream *stream, uint32_t *latency)
Get the latency for this stream, in frames.
CUBEB_EXPORT int cubeb_init(cubeb **context, char const *context_name, char const *backend_name)
Initialize an application context.
struct cubeb_stream cubeb_stream
Opaque handle referencing the stream state.
Definition cubeb.h:127
CUBEB_EXPORT int cubeb_stream_stop(cubeb_stream *stream)
Stop playback.
CUBEB_EXPORT int cubeb_device_collection_destroy(cubeb *context, cubeb_device_collection *collection)
Destroy a cubeb_device_collection, and its cubeb_device_info.
CUBEB_EXPORT int cubeb_stream_get_position(cubeb_stream *stream, uint64_t *position)
Get the current stream playback position.
void(* cubeb_state_callback)(cubeb_stream *stream, void *user_ptr, cubeb_state state)
User supplied state callback.
Definition cubeb.h:457
uint32_t cubeb_channel_layout
A bitmask representing the channel layout of a cubeb stream.
Definition cubeb.h:192
CUBEB_EXPORT void cubeb_stream_destroy(cubeb_stream *stream)
Destroy a stream.
CUBEB_EXPORT int cubeb_stream_set_name(cubeb_stream *stream, char const *stream_name)
Change a stream's name.
cubeb_device_fmt
Architecture specific sample type.
Definition cubeb.h:338
@ CUBEB_DEVICE_FMT_S16BE
16-bit integers, Big Endian.
Definition cubeb.h:340
@ CUBEB_DEVICE_FMT_F32BE
32-bit floating point, Big Endian.
Definition cubeb.h:342
@ CUBEB_DEVICE_FMT_S16LE
16-bit integers, Little Endian.
Definition cubeb.h:339
@ CUBEB_DEVICE_FMT_F32LE
32-bit floating point, Little Endian.
Definition cubeb.h:341
@ CUBEB_ERROR
Unclassified error.
Definition cubeb.h:305
@ CUBEB_ERROR_INVALID_FORMAT
Unsupported cubeb_stream_params requested.
Definition cubeb.h:306
@ CUBEB_ERROR_NOT_SUPPORTED
Optional function not implemented in current backend.
Definition cubeb.h:309
@ CUBEB_ERROR_DEVICE_UNAVAILABLE
Device specified by cubeb_devid not available.
Definition cubeb.h:311
@ CUBEB_OK
Success.
Definition cubeb.h:304
@ CUBEB_ERROR_INVALID_PARAMETER
Invalid parameter specified.
Definition cubeb.h:308
CUBEB_EXPORT void cubeb_destroy(cubeb *context)
Destroy an application context.
cubeb_log_level
Level (verbosity) of logging for a particular cubeb context.
Definition cubeb.h:158
@ CUBEB_LOG_NORMAL
< Logging disabled
Definition cubeb.h:160
@ CUBEB_LOG_VERBOSE
Verbose logging of callbacks, can have performance implications.
Definition cubeb.h:162
cubeb_input_processing_params
Input stream audio processing parameters.
Definition cubeb.h:265
CUBEB_EXPORT int cubeb_get_min_latency(cubeb *context, cubeb_stream_params *params, uint32_t *latency_frames)
Get the minimal latency value, in frames, that is guaranteed to work when creating a stream for the s...
cubeb_state
Stream states signaled via state_callback.
Definition cubeb.h:295
@ CUBEB_STATE_STARTED
Stream started.
Definition cubeb.h:296
@ CUBEB_STATE_ERROR
Stream disabled due to error.
Definition cubeb.h:299
@ CUBEB_STATE_DRAINED
Stream drained.
Definition cubeb.h:298
@ CUBEB_STATE_STOPPED
Stream stopped.
Definition cubeb.h:297
CUBEB_EXPORT void * cubeb_stream_user_ptr(cubeb_stream *stream)
Return the user data pointer registered with the stream with cubeb_stream_init.
Array of compiled backends returned by cubeb_get_backend_names.
Definition cubeb.h:421
const char *const * names
Array of strings representing backend names.
Definition cubeb.h:423
size_t count
Length of the array.
Definition cubeb.h:424
Device collection.
Definition cubeb.h:415
size_t count
Device count in collection.
Definition cubeb.h:417
cubeb_device_info * device
Array of pointers to device info.
Definition cubeb.h:416
This structure holds the characteristics of an input or output audio device.
Definition cubeb.h:385
cubeb_device_state state
State of device disabled/enabled/unplugged.
Definition cubeb.h:397
uint32_t max_rate
Maximum sample rate supported.
Definition cubeb.h:405
uint32_t min_rate
Minimum sample rate supported.
Definition cubeb.h:406
cubeb_device_type type
Type of device (Input/Output).
Definition cubeb.h:396
cubeb_device_pref preferred
Preferred device.
Definition cubeb.h:398
cubeb_device_fmt default_format
The default sample format for this device.
Definition cubeb.h:402
char const * group_id
Two devices have the same group identifier if they belong to the same physical device; for example a ...
Definition cubeb.h:391
uint32_t max_channels
Channels.
Definition cubeb.h:403
uint32_t default_rate
Default/Preferred sample rate.
Definition cubeb.h:404
uint32_t latency_lo
Lowest possible latency in frames.
Definition cubeb.h:408
char const * vendor_name
Optional vendor name, may be NULL.
Definition cubeb.h:394
uint32_t latency_hi
Higest possible latency in frames.
Definition cubeb.h:409
char const * device_id
Device identifier which might be presented in a UI.
Definition cubeb.h:388
cubeb_devid devid
Device identifier handle.
Definition cubeb.h:386
char const * friendly_name
Friendly device name which might be presented in a UI.
Definition cubeb.h:389
cubeb_device_fmt format
Sample format supported.
Definition cubeb.h:400
Audio device description.
Definition cubeb.h:289
char * input_name
The name of the input device.
Definition cubeb.h:291
char * output_name
The name of the output device.
Definition cubeb.h:290
Stream format initialization parameters.
Definition cubeb.h:274
cubeb_input_processing_params input_params
Requested input processing params.
Definition cubeb.h:283
cubeb_sample_format format
Requested sample format.
Definition cubeb.h:275
cubeb_channel_layout layout
Requested channel layout.
Definition cubeb.h:280
cubeb_stream_prefs prefs
Requested preferences.
Definition cubeb.h:282
uint32_t rate
Requested sample rate.
Definition cubeb.h:277
uint32_t channels
Requested channel count.
Definition cubeb.h:278