ref: 8e668058eaedc563b3d14ce1c364abaca3907c98
parent: 5c08f66453bf9fa07c86f55cdea0f8b4f8812591
author: robs <robs>
date: Sat May 26 02:18:22 EDT 2007
QAD fix to allow mixer to mixdown any number of channels
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -196,7 +196,8 @@
return(SOX_EOF);
}
- if ((ichan != 1 && ichan != 2 && ichan != 4)
+ if ((ichan != 1 && ichan != 2 && ichan != 4 &&
+ mixer->mix != MIX_CENTER && ochan != 1)
|| (ochan != 1 && ochan != 2 && ochan != 4)) {
sox_fail("Can't average %d channels into %d channels",
ichan, ochan);
@@ -384,10 +385,9 @@
mixer->sources[0][2] = 1.0;
mixer->sources[0][3] = 1.0;
}
- /* CASE 2 */
- else if (ichan == 2 && ochan == 1) {
- mixer->sources[0][0] = 0.5;
- mixer->sources[1][0] = 0.5;
+ /* CASE 2, 6 */
+ else if (ochan == 1) {
+ mixer->sources[0][0] = 1.0 / ichan;
}
/* CASE 5 */
else if (ichan == 2 && ochan == 4) {
@@ -396,13 +396,6 @@
mixer->sources[1][1] = 1.0;
mixer->sources[1][3] = 1.0;
}
- /* CASE 6 */
- else if (ichan == 4 && ochan == 1) {
- mixer->sources[0][0] = 0.25;
- mixer->sources[1][0] = 0.25;
- mixer->sources[2][0] = 0.25;
- mixer->sources[3][0] = 0.25;
- }
/* CASE 7 */
else if (ichan == 4 && ochan == 2) {
mixer->sources[0][0] = 0.5;
@@ -535,7 +528,7 @@
for (j = 0; j < ochan; j++) {
samp = 0.0;
for (i = 0; i < ichan; i++)
- samp += ibuf[i] * mixer->sources[i][j];
+ samp += ibuf[i] * mixer->sources[mixer->mix == MIX_CENTER? 0 : i][j];
SOX_SAMPLE_CLIP_COUNT(samp, effp->clips);
obuf[j] = samp;
}