mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-02 09:01:50 -05:00
channelmix: handle stereo to mono
This commit is contained in:
parent
2b88dde567
commit
4d7311aca1
1 changed files with 39 additions and 34 deletions
|
|
@ -118,25 +118,26 @@ struct impl {
|
||||||
#define _MASK(ch) (1ULL << SPA_AUDIO_CHANNEL_ ## ch)
|
#define _MASK(ch) (1ULL << SPA_AUDIO_CHANNEL_ ## ch)
|
||||||
#define STEREO (_MASK(FL)|_MASK(FR))
|
#define STEREO (_MASK(FL)|_MASK(FR))
|
||||||
|
|
||||||
#define FL 0
|
#define M 0
|
||||||
#define FR 1
|
#define FL 1
|
||||||
#define FC 2
|
#define FR 2
|
||||||
#define LFE 3
|
#define FC 3
|
||||||
#define SL 4
|
#define LFE 4
|
||||||
#define SR 5
|
#define SL 5
|
||||||
#define FLC 6
|
#define SR 6
|
||||||
#define FRC 7
|
#define FLC 7
|
||||||
#define RC 8
|
#define FRC 8
|
||||||
#define RL 9
|
#define RC 9
|
||||||
#define RR 10
|
#define RL 10
|
||||||
#define TC 11
|
#define RR 11
|
||||||
#define TFL 12
|
#define TC 12
|
||||||
#define TFC 13
|
#define TFL 13
|
||||||
#define TFR 14
|
#define TFC 14
|
||||||
#define TRL 15
|
#define TFR 15
|
||||||
#define TRC 16
|
#define TRL 16
|
||||||
#define TRR 17
|
#define TRC 17
|
||||||
#define NUM_CHAN 18
|
#define TRR 18
|
||||||
|
#define NUM_CHAN 19
|
||||||
|
|
||||||
#define SQRT3_2 1.22474487139158904909 /* sqrt(3/2) */
|
#define SQRT3_2 1.22474487139158904909 /* sqrt(3/2) */
|
||||||
|
|
||||||
|
|
@ -182,7 +183,7 @@ static int make_matrix(struct impl *this,
|
||||||
uint32_t dst_chan, uint64_t dst_mask)
|
uint32_t dst_chan, uint64_t dst_mask)
|
||||||
{
|
{
|
||||||
float matrix[NUM_CHAN][NUM_CHAN] = {{ 0 }};
|
float matrix[NUM_CHAN][NUM_CHAN] = {{ 0 }};
|
||||||
uint64_t missing;
|
uint64_t unassigned;
|
||||||
int i, j, matrix_encoding = MATRIX_NORMAL, c;
|
int i, j, matrix_encoding = MATRIX_NORMAL, c;
|
||||||
float clev = M_SQRT1_2;
|
float clev = M_SQRT1_2;
|
||||||
float slev = M_SQRT1_2;
|
float slev = M_SQRT1_2;
|
||||||
|
|
@ -190,15 +191,15 @@ static int make_matrix(struct impl *this,
|
||||||
float max = 0.0f;
|
float max = 0.0f;
|
||||||
|
|
||||||
for (i = 0; i < NUM_CHAN; i++) {
|
for (i = 0; i < NUM_CHAN; i++) {
|
||||||
if (src_mask & dst_mask & (1ULL << (i + 3)))
|
if (src_mask & dst_mask & (1ULL << (i + 2)))
|
||||||
matrix[i][i]= 1.0;
|
matrix[i][i]= 1.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
missing = src_mask & ~dst_mask;
|
unassigned = src_mask & ~dst_mask;
|
||||||
|
|
||||||
spa_log_debug(this->log, "missing %08lx", missing);
|
spa_log_debug(this->log, "unassigned %08lx", unassigned);
|
||||||
|
|
||||||
if (missing & _MASK(FC)){
|
if (unassigned & _MASK(FC)){
|
||||||
if ((dst_mask & STEREO) == STEREO){
|
if ((dst_mask & STEREO) == STEREO){
|
||||||
if(src_mask & STEREO) {
|
if(src_mask & STEREO) {
|
||||||
matrix[FL][FC] += clev;
|
matrix[FL][FC] += clev;
|
||||||
|
|
@ -211,8 +212,12 @@ static int make_matrix(struct impl *this,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing & STEREO){
|
if (unassigned & STEREO){
|
||||||
if (dst_mask & _MASK(FC)) {
|
if (dst_mask & _MASK(MONO)) {
|
||||||
|
matrix[M][FL] += 0.5;
|
||||||
|
matrix[M][FR] += 0.5;
|
||||||
|
}
|
||||||
|
else if (dst_mask & _MASK(FC)) {
|
||||||
matrix[FC][FL] += M_SQRT1_2;
|
matrix[FC][FL] += M_SQRT1_2;
|
||||||
matrix[FC][FR] += M_SQRT1_2;
|
matrix[FC][FR] += M_SQRT1_2;
|
||||||
if (src_mask & _MASK(FC))
|
if (src_mask & _MASK(FC))
|
||||||
|
|
@ -221,7 +226,7 @@ static int make_matrix(struct impl *this,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing & _MASK(RC)) {
|
if (unassigned & _MASK(RC)) {
|
||||||
if (dst_mask & _MASK(RL)){
|
if (dst_mask & _MASK(RL)){
|
||||||
matrix[RL][RC] += M_SQRT1_2;
|
matrix[RL][RC] += M_SQRT1_2;
|
||||||
matrix[RR][RC] += M_SQRT1_2;
|
matrix[RR][RC] += M_SQRT1_2;
|
||||||
|
|
@ -231,7 +236,7 @@ static int make_matrix(struct impl *this,
|
||||||
} else if(dst_mask & _MASK(FL)) {
|
} else if(dst_mask & _MASK(FL)) {
|
||||||
if (matrix_encoding == MATRIX_DOLBY ||
|
if (matrix_encoding == MATRIX_DOLBY ||
|
||||||
matrix_encoding == MATRIX_DPLII) {
|
matrix_encoding == MATRIX_DPLII) {
|
||||||
if (missing & (_MASK(RL)|_MASK(RR))) {
|
if (unassigned & (_MASK(RL)|_MASK(RR))) {
|
||||||
matrix[FL][RC] -= slev * M_SQRT1_2;
|
matrix[FL][RC] -= slev * M_SQRT1_2;
|
||||||
matrix[FR][RC] += slev * M_SQRT1_2;
|
matrix[FR][RC] += slev * M_SQRT1_2;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -248,7 +253,7 @@ static int make_matrix(struct impl *this,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing & _MASK(RL)) {
|
if (unassigned & _MASK(RL)) {
|
||||||
if (dst_mask & _MASK(RC)) {
|
if (dst_mask & _MASK(RC)) {
|
||||||
matrix[RC][RL] += M_SQRT1_2;
|
matrix[RC][RL] += M_SQRT1_2;
|
||||||
matrix[RC][RR] += M_SQRT1_2;
|
matrix[RC][RR] += M_SQRT1_2;
|
||||||
|
|
@ -282,7 +287,7 @@ static int make_matrix(struct impl *this,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing & _MASK(SL)) {
|
if (unassigned & _MASK(SL)) {
|
||||||
if (dst_mask & _MASK(RL)) {
|
if (dst_mask & _MASK(RL)) {
|
||||||
if (src_mask & _MASK(RL)) {
|
if (src_mask & _MASK(RL)) {
|
||||||
matrix[RL][SL] += M_SQRT1_2;
|
matrix[RL][SL] += M_SQRT1_2;
|
||||||
|
|
@ -316,7 +321,7 @@ static int make_matrix(struct impl *this,
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (missing & _MASK(FLC)) {
|
if (unassigned & _MASK(FLC)) {
|
||||||
if (dst_mask & _MASK(FL)) {
|
if (dst_mask & _MASK(FL)) {
|
||||||
matrix[FC][FLC]+= 1.0;
|
matrix[FC][FLC]+= 1.0;
|
||||||
matrix[FC][FRC]+= 1.0;
|
matrix[FC][FRC]+= 1.0;
|
||||||
|
|
@ -326,7 +331,7 @@ static int make_matrix(struct impl *this,
|
||||||
} else
|
} else
|
||||||
return -ENOTSUP;
|
return -ENOTSUP;
|
||||||
}
|
}
|
||||||
if (missing & _MASK(LFE)) {
|
if (unassigned & _MASK(LFE)) {
|
||||||
if (dst_mask & _MASK(FC)) {
|
if (dst_mask & _MASK(FC)) {
|
||||||
matrix[FC][LFE] += llev;
|
matrix[FC][LFE] += llev;
|
||||||
} else if (dst_mask & _MASK(FL)) {
|
} else if (dst_mask & _MASK(FL)) {
|
||||||
|
|
@ -339,10 +344,10 @@ static int make_matrix(struct impl *this,
|
||||||
c = 0;
|
c = 0;
|
||||||
for (i = 0; i < NUM_CHAN; i++) {
|
for (i = 0; i < NUM_CHAN; i++) {
|
||||||
float sum = 0.0;
|
float sum = 0.0;
|
||||||
if ((dst_mask & (1UL << (i + 3))) == 0)
|
if ((dst_mask & (1UL << (i + 2))) == 0)
|
||||||
continue;
|
continue;
|
||||||
for (j = 0; j < NUM_CHAN; j++) {
|
for (j = 0; j < NUM_CHAN; j++) {
|
||||||
if ((src_mask & (1UL << (j + 3))) == 0)
|
if ((src_mask & (1UL << (j + 2))) == 0)
|
||||||
continue;
|
continue;
|
||||||
this->matrix[c++] = matrix[i][j];
|
this->matrix[c++] = matrix[i][j];
|
||||||
sum += fabs(matrix[i][j]);
|
sum += fabs(matrix[i][j]);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue