diff options
author | Jean-Yves Avenard <[email protected]> | 2018-03-19 14:57:07 +0100 |
---|---|---|
committer | Paul Adenot <[email protected]> | 2018-03-19 14:57:07 +0100 |
commit | 789eaaa3b0d77b55e110353972d6713889f510ea (patch) | |
tree | fbeb48958ab83c329193f37c54133c9bc68aac4a /include | |
parent | c88a484e1aac878419946334c49d35d6948beec7 (diff) | |
download | cubeb-789eaaa3b0d77b55e110353972d6713889f510ea.tar.gz cubeb-789eaaa3b0d77b55e110353972d6713889f510ea.zip |
Multi-channels support for windows/mac/linux (#426)
* Add QUAD and QUAD_LFE layouts.
* Remove dual mono layout.
It makes no sense to have a case for those as the data structure
used (a bitmask) do not allow to represent this channel layout (a
channel can only be present once). As such it was a non-functional
layout
* Fix up cubeb_pulse compilation using C++ keyword.
* Remove the concept of preferred layout.
Channel layout is derived by the content being played. The concept of
preferred layout is meaningless. Either we have a layout defined, or
we don't. There's no in-between.
So we remove it.
* Remove CHANNEL_MONO concept.
* Add cubeb_sample_size convenience method.
* Rework cubeb_mixer.
This completely replace the existing remixer which had serious limitations:
1- Had no memory bound checks
2- Could only downmix 5.1 and 7.1 to stereo.
This mixer allows to convert from any sane layout to any other and work directly on interleaved samples.
This cubeb_mixer doesn't have an API compatible with the previous one.
This commit is non-fonctional, and was split for ease of review.
* Fix remixing on mac, windows and pulse backend.
* Make cubeb_mixer creation infallible.
Rather than ignore nonsensical layouts, we attempt to play it according to the stream channels count instead. The audio data will be played as-is, dropping the extra channels or inserting silence where needed.
* User proper sample size when calculating offsets.
Should the user data be of a different type to what the AudioUnit output is set to, we would have written outside the end of our allocated buffer.
* Fix input mixing and clarify frames vs samples terminology
* If a layout is unknown or invalid, always treat it as plain stereo or mono.
Diffstat (limited to 'include')
-rw-r--r-- | include/cubeb/cubeb.h | 126 |
1 files changed, 60 insertions, 66 deletions
diff --git a/include/cubeb/cubeb.h b/include/cubeb/cubeb.h index d690a0a..f781cdf 100644 --- a/include/cubeb/cubeb.h +++ b/include/cubeb/cubeb.h @@ -157,63 +157,66 @@ typedef enum { CUBEB_LOG_VERBOSE = 2, /**< Verbose logging of callbacks, can have performance implications. */ } cubeb_log_level; -/** SMPTE channel layout (also known as wave order) - * DUAL-MONO L R - * DUAL-MONO-LFE L R LFE - * MONO M - * MONO-LFE M LFE - * STEREO L R - * STEREO-LFE L R LFE - * 3F L R C - * 3F-LFE L R C LFE - * 2F1 L R RC - * 2F1-LFE L R LFE RC - * 3F1 L R C RC - * 3F1-LFE L R C LFE RC - * 2F2 L R LS RS - * 2F2-LFE L R LFE LS RS - * 3F2 L R C LS RS - * 3F2-LFE L R C LFE LS RS - * 3F3R-LFE L R C LFE RC LS RS - * 3F4-LFE L R C LFE RLS RRS LS RS - * - * The abbreviation of channel name is defined in following table: - * Abbr Channel name - * --------------------------- - * M Mono - * L Left - * R Right - * C Center - * LS Left Surround - * RS Right Surround - * RLS Rear Left Surround - * RC Rear Center - * RRS Rear Right Surround - * LFE Low Frequency Effects - */ - typedef enum { - CUBEB_LAYOUT_UNDEFINED, // Indicate the speaker's layout is undefined. - CUBEB_LAYOUT_DUAL_MONO, - CUBEB_LAYOUT_DUAL_MONO_LFE, - CUBEB_LAYOUT_MONO, - CUBEB_LAYOUT_MONO_LFE, - CUBEB_LAYOUT_STEREO, - CUBEB_LAYOUT_STEREO_LFE, - CUBEB_LAYOUT_3F, - CUBEB_LAYOUT_3F_LFE, - CUBEB_LAYOUT_2F1, - CUBEB_LAYOUT_2F1_LFE, - CUBEB_LAYOUT_3F1, - CUBEB_LAYOUT_3F1_LFE, - CUBEB_LAYOUT_2F2, - CUBEB_LAYOUT_2F2_LFE, - CUBEB_LAYOUT_3F2, - CUBEB_LAYOUT_3F2_LFE, - CUBEB_LAYOUT_3F3R_LFE, - CUBEB_LAYOUT_3F4_LFE, - CUBEB_LAYOUT_MAX -} cubeb_channel_layout; + CHANNEL_UNKNOWN = 0, + CHANNEL_FRONT_LEFT = 1 << 0, + CHANNEL_FRONT_RIGHT = 1 << 1, + CHANNEL_FRONT_CENTER = 1 << 2, + CHANNEL_LOW_FREQUENCY = 1 << 3, + CHANNEL_BACK_LEFT = 1 << 4, + CHANNEL_BACK_RIGHT = 1 << 5, + CHANNEL_FRONT_LEFT_OF_CENTER = 1 << 6, + CHANNEL_FRONT_RIGHT_OF_CENTER = 1 << 7, + CHANNEL_BACK_CENTER = 1 << 8, + CHANNEL_SIDE_LEFT = 1 << 9, + CHANNEL_SIDE_RIGHT = 1 << 10, + CHANNEL_TOP_CENTER = 1 << 11, + CHANNEL_TOP_FRONT_LEFT = 1 << 12, + CHANNEL_TOP_FRONT_CENTER = 1 << 13, + CHANNEL_TOP_FRONT_RIGHT = 1 << 14, + CHANNEL_TOP_BACK_LEFT = 1 << 15, + CHANNEL_TOP_BACK_CENTER = 1 << 16, + CHANNEL_TOP_BACK_RIGHT = 1 << 17 +} cubeb_channel; + +typedef uint32_t cubeb_channel_layout; +// Some common layout definitions. +enum { + CUBEB_LAYOUT_UNDEFINED = 0, // Indicate the speaker's layout is undefined. + CUBEB_LAYOUT_MONO = CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_MONO_LFE = CUBEB_LAYOUT_MONO | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_STEREO = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT, + CUBEB_LAYOUT_STEREO_LFE = CUBEB_LAYOUT_STEREO | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F = + CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_3F_LFE = CUBEB_LAYOUT_3F | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_2F1 = + CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | CHANNEL_BACK_CENTER, + CUBEB_LAYOUT_2F1_LFE = CUBEB_LAYOUT_2F1 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F1 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_BACK_CENTER, + CUBEB_LAYOUT_3F1_LFE = CUBEB_LAYOUT_3F1 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_2F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_2F2_LFE = CUBEB_LAYOUT_2F2 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_QUAD = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT, + CUBEB_LAYOUT_QUAD_LFE = CUBEB_LAYOUT_QUAD | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F2 = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_SIDE_LEFT | + CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_3F2_LFE = CUBEB_LAYOUT_3F2 | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F2_BACK = CUBEB_LAYOUT_QUAD | 1 << CHANNEL_FRONT_CENTER, + CUBEB_LAYOUT_3F2_LFE_BACK = CUBEB_LAYOUT_3F2_BACK | CHANNEL_LOW_FREQUENCY, + CUBEB_LAYOUT_3F3R_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | + CHANNEL_BACK_CENTER | CHANNEL_SIDE_LEFT | + CHANNEL_SIDE_RIGHT, + CUBEB_LAYOUT_3F4_LFE = CHANNEL_FRONT_LEFT | CHANNEL_FRONT_RIGHT | + CHANNEL_FRONT_CENTER | CHANNEL_LOW_FREQUENCY | + CHANNEL_BACK_LEFT | CHANNEL_BACK_RIGHT | + CHANNEL_SIDE_LEFT | CHANNEL_SIDE_RIGHT, +}; /** Miscellaneous stream preferences. */ typedef enum { @@ -230,7 +233,7 @@ typedef struct { #cubeb_sample_format. */ uint32_t rate; /**< Requested sample rate. Valid range is [1000, 192000]. */ uint32_t channels; /**< Requested channel count. Valid range is [1, 8]. */ - cubeb_channel_layout layout; /**< Requested channel layout. This must be consistent with the provided channels. */ + cubeb_channel_layout layout; /**< Requested channel layout. This must be consistent with the provided channels. CUBEB_LAYOUT_UNDEFINED if unknown */ cubeb_stream_prefs prefs; /**< Requested preferences. */ } cubeb_stream_params; @@ -458,15 +461,6 @@ CUBEB_EXPORT int cubeb_get_min_latency(cubeb * context, @retval CUBEB_ERROR_NOT_SUPPORTED */ CUBEB_EXPORT int cubeb_get_preferred_sample_rate(cubeb * context, uint32_t * rate); -/** Get the preferred layout for this backend: this is hardware and - platform dependent. - @param context A pointer to the cubeb context. - @param layout The layout of the current speaker configuration. - @retval CUBEB_OK - @retval CUBEB_ERROR_INVALID_PARAMETER - @retval CUBEB_ERROR_NOT_SUPPORTED */ -CUBEB_EXPORT int cubeb_get_preferred_channel_layout(cubeb * context, cubeb_channel_layout * layout); - /** Destroy an application context. This must be called after all stream have * been destroyed. @param context A pointer to the cubeb context.*/ |