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 /src/cubeb_mixer.h | |
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 'src/cubeb_mixer.h')
-rw-r--r-- | src/cubeb_mixer.h | 79 |
1 files changed, 13 insertions, 66 deletions
diff --git a/src/cubeb_mixer.h b/src/cubeb_mixer.h index 51fb908..dd84b87 100644 --- a/src/cubeb_mixer.h +++ b/src/cubeb_mixer.h @@ -8,80 +8,27 @@ #ifndef CUBEB_MIXER #define CUBEB_MIXER -#include "cubeb/cubeb.h" // for cubeb_channel_layout ,CUBEB_CHANNEL_LAYOUT_MAPS and cubeb_stream_params. -#include <stdbool.h> +#include "cubeb/cubeb.h" // for cubeb_channel_layout and cubeb_stream_params. #if defined(__cplusplus) extern "C" { #endif -typedef enum { - CHANNEL_INVALID = -1, - CHANNEL_MONO = 0, - CHANNEL_LEFT, - CHANNEL_RIGHT, - CHANNEL_CENTER, - CHANNEL_LS, - CHANNEL_RS, - CHANNEL_RLS, - CHANNEL_RCENTER, - CHANNEL_RRS, - CHANNEL_LFE, - CHANNEL_UNMAPPED, - CHANNEL_MAX = 256 // Max number of supported channels. -} cubeb_channel; - -static cubeb_channel const CHANNEL_INDEX_TO_ORDER[CUBEB_LAYOUT_MAX][CHANNEL_MAX] = { - { CHANNEL_INVALID }, // UNDEFINED - { CHANNEL_LEFT, CHANNEL_RIGHT }, // DUAL_MONO - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LFE }, // DUAL_MONO_LFE - { CHANNEL_MONO }, // MONO - { CHANNEL_MONO, CHANNEL_LFE }, // MONO_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT }, // STEREO - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LFE }, // STEREO_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER }, // 3F - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE }, // 3F_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_RCENTER }, // 2F1 - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LFE, CHANNEL_RCENTER }, // 2F1_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_RCENTER }, // 3F1 - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RCENTER }, // 3F1_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LS, CHANNEL_RS }, // 2F2 - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_LFE, CHANNEL_LS, CHANNEL_RS }, // 2F2_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LS, CHANNEL_RS }, // 3F2 - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_LS, CHANNEL_RS }, // 3F2_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RCENTER, CHANNEL_LS, CHANNEL_RS }, // 3F3R_LFE - { CHANNEL_LEFT, CHANNEL_RIGHT, CHANNEL_CENTER, CHANNEL_LFE, CHANNEL_RLS, CHANNEL_RRS, CHANNEL_LS, CHANNEL_RS } // 3F4_LFE - // When more channels are present, the stream is considered unmapped to a - // particular speaker set. -}; - -typedef struct { - unsigned int channels; - cubeb_channel map[CHANNEL_MAX]; -} cubeb_channel_map; - -cubeb_channel_layout cubeb_channel_map_to_layout(cubeb_channel_map const * channel_map); - -bool cubeb_should_upmix(cubeb_stream_params const * stream, cubeb_stream_params const * mixer); - -bool cubeb_should_downmix(cubeb_stream_params const * stream, cubeb_stream_params const * mixer); - -bool cubeb_should_mix(cubeb_stream_params const * stream, cubeb_stream_params const * mixer); - -typedef enum { - CUBEB_MIXER_DIRECTION_DOWNMIX = 0x01, - CUBEB_MIXER_DIRECTION_UPMIX = 0x02, -} cubeb_mixer_direction; - typedef struct cubeb_mixer cubeb_mixer; cubeb_mixer * cubeb_mixer_create(cubeb_sample_format format, - unsigned char direction); + uint32_t in_channels, + cubeb_channel_layout in_layout, + uint32_t out_channels, + cubeb_channel_layout out_layout); void cubeb_mixer_destroy(cubeb_mixer * mixer); -void cubeb_mixer_mix(cubeb_mixer * mixer, long frames, - void * input_buffer, unsigned long input_buffer_length, - void * output_buffer, unsigned long output_buffer_length, - cubeb_stream_params const * stream_params, - cubeb_stream_params const * mixer_params); +int cubeb_mixer_mix(cubeb_mixer * mixer, + size_t frames, + void * input_buffer, + size_t input_buffer_size, + void * output_buffer, + size_t output_buffer_size); + +unsigned int cubeb_channel_layout_nb_channels(cubeb_channel_layout channel_layout); #if defined(__cplusplus) } |