| 1 | /* MixingMatrix.cpp |
| 2 | * |
| 3 | * Copyright (C) 2010-2017 David Weenink |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * See the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "Interpreter.h"cxx . . $ `<file>/sys/Interpreter.h`/ |
| 20 | #include "MixingMatrix.h"cxx . . $ `<file>/dwtools/MixingMatrix.h`/ |
| 21 | |
| 22 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (MixingMatrix, TableOfReal, 0); |
| 23 | |
| 24 | autoMixingMatrixcxx . . $ autoMixingMatrix# MixingMatrix_createcxx . . $ MixingMatrix_create(3585a88d304573af). (integercxx . . $ integer# numberOfOutputChannels, integercxx . . $ integer# numberOfInputChannels) { |
| 25 | try { |
| 26 | autoMixingMatrixcxx . . $ autoMixingMatrix# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (MixingMatrix); |
| 27 | TableOfReal_initcxx . . $ TableOfReal_init(cfadf70b559ed315). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfOutputChannels, numberOfInputChannels); |
| 28 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 29 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 30 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"MixingMatrix not created."); |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | autoMixingMatrixcxx . . $ autoMixingMatrix# MixingMatrix_createSimplecxx . . $ MixingMatrix_createSimple(2a9766b15da491a0). (integercxx . . $ integer# numberOfOutputChannels, integercxx . . $ integer# numberOfInputChannels, conststring32cxx . . $ conststring32# elements_string) { |
| 35 | try { |
| 36 | autoSTRVECcxx . . $ autoSTRVEC# elements = splitByWhitespace_STRVECcxx . . $ splitByWhitespace_STRVEC(d3c03a92d990d008). (elements_string); |
| 37 | |
| 38 | const integercxx . . $ integer# numberOfCells = numberOfInputChannels * numberOfOutputChannels; |
| 39 | |
| 40 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (elements.size == numberOfCells, |
| 41 | U"The number of mixing coefficients (", elements.size, U") should equal the number of cells (", numberOfCells, U") in the mixing matrix."); |
| 42 | |
| 43 | autoMixingMatrixcxx . . $ autoMixingMatrix# me = MixingMatrix_createcxx . . $ MixingMatrix_create(3585a88d304573af). (numberOfOutputChannels, numberOfInputChannels); |
| 44 | |
| 45 | /* |
| 46 | Construct the full matrix from the elements |
| 47 | */ |
| 48 | for (integercxx . . $ integer# inum = 1; inum <= numberOfCells; inum ++) { |
| 49 | double number; |
| 50 | Interpreter_numericExpressioncxx . . $ Interpreter_numericExpression(8639512facf48b76). (0, elements [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).inum].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & number); |
| 51 | const integercxx . . $ integer# irow = (inum - 1) / numberOfInputChannels + 1; |
| 52 | const integercxx . . $ integer# icol = (inum - 1) % numberOfInputChannels + 1; |
| 53 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icol] = number; |
| 54 | } |
| 55 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 56 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 57 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"MixingMatrix not created."); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | void MixingMatrix_setRandomGausscxx . . $ MixingMatrix_setRandomGauss(bccce4f2b6afeb03). (MixingMatrixcxx . . $ MixingMatrix# me, double mean, double stdev) { |
| 62 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; i++) { |
| 63 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.; j++) { |
| 64 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (mean, stdev); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | void MixingMatrix_multiplyInputChannelcxx . . $ MixingMatrix_multiplyInputChannel(c7f9d8093e0c8b09). (MixingMatrixcxx . . $ MixingMatrix# me, integercxx . . $ integer# inputChannel, double value) { |
| 70 | if (inputChannel >= 1 && inputChannel <= mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.) { |
| 71 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; i ++) { |
| 72 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).inputChannel] *= value; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // https://developer.mozilla.org/en-US/docs/Web/API/AudioNode/channelInterpretation |
| 78 | void MixingMatrix_setStandardChannelInterpretationcxx . . $ MixingMatrix_setStandardChannelInterpretation(da6a509e9bebb142). (MixingMatrixcxx . . $ MixingMatrix# me) { |
| 79 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; i++) { |
| 80 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.; j++) { |
| 81 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = 0.0; |
| 82 | } |
| 83 | } |
| 84 | bool dimensionsCovered = true; |
| 85 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. == 1) { // mono input |
| 86 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 2) { // up-mix to stereo |
| 87 | /* |
| 88 | The M input channel is used for both output channels (L and R). |
| 89 | output.L = input.M |
| 90 | output.R = input.M |
| 91 | */ |
| 92 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 1.0; |
| 93 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 4) { // up-mix to quad |
| 94 | /* |
| 95 | The M input channel is used for non-surround output channels (L and R). |
| 96 | Surround output channels (SL and SR) are silent. |
| 97 | output.L = input.M |
| 98 | output.R = input.M |
| 99 | output.SL = 0 |
| 100 | output.SR = 0 |
| 101 | */ |
| 102 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 1.0; |
| 103 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 6) { // up-mix to to 5.1 |
| 104 | /* |
| 105 | The M input channel is used for the center output channel (C). |
| 106 | All the others (L, R, LFE, SL, and SR) are silent. |
| 107 | output.L = 0 |
| 108 | output.R = 0 |
| 109 | output.C = input.M |
| 110 | output.LFE = 0 |
| 111 | output.SL = 0 |
| 112 | output.SR = 0 |
| 113 | */ |
| 114 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 1.0; |
| 115 | } else { |
| 116 | dimensionsCovered = false; |
| 117 | } |
| 118 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. == 2) { // stereo input |
| 119 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 1) { // down-mix to mono |
| 120 | /* |
| 121 | Both input channels (L and R) are equally combined to produce the unique output channel (M). |
| 122 | output.M = 0.5 * (input.L + input.R) |
| 123 | */ |
| 124 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 0.5; |
| 125 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 2) { // to stereo |
| 126 | /* |
| 127 | output.L = input.L |
| 128 | output.R = input.R |
| 129 | */ |
| 130 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 1.0; |
| 131 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 4) { // up-mix to quad |
| 132 | /* |
| 133 | The L and R input channels are used for their non-surround respective output channels (L and R). |
| 134 | Surround output channels (SL and SR) are silent. |
| 135 | output.L = input.L |
| 136 | output.R = input.R |
| 137 | output.SL = 0 |
| 138 | output.SR = 0 |
| 139 | */ |
| 140 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 1.0; |
| 141 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 6) { // up-mix to 5.1 |
| 142 | /* |
| 143 | The L and R input channels are used for their non-surround respective output channels (L and R). |
| 144 | Surround output channels (SL and SR), as well as the center (C) and subwoofer (LFE) channels, are left silent. |
| 145 | output.L = input.L |
| 146 | output.R = input.R |
| 147 | output.C = 0 |
| 148 | output.LFE = 0 |
| 149 | output.SL = 0 |
| 150 | output.SR = 0 |
| 151 | */ |
| 152 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 1.0; |
| 153 | } else { // up-mix |
| 154 | dimensionsCovered = false; |
| 155 | } |
| 156 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. == 4) { // quad input |
| 157 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 1) { // down-mix to mono |
| 158 | /* |
| 159 | All four input channels (L, R, SL, and SR) are equally combined to produce the unique output |
| 160 | channel (M). |
| 161 | output.M = 0.25 * (input.L + input.R + input.SL + input.SR) |
| 162 | */ |
| 163 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).4] = 0.25; |
| 164 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 2) { // down-mix to stereo |
| 165 | /* |
| 166 | Both left input channels (L and SL) are equally combined to produce the unique left output channel (L). |
| 167 | And similarly, both right input channels (R and SR) are equally combined to produce the unique right output channel (R). |
| 168 | output.L = 0.5 * (input.L + input.SL) |
| 169 | output.R = 0.5 * (input.R + input.SR) |
| 170 | */ |
| 171 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = 0.5; |
| 172 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).4] = 0.5; |
| 173 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 6) { // up-mix to 5.1 |
| 174 | /* |
| 175 | The L, R, SL, and SR input channels are used for their respective output channels (L and R). |
| 176 | Center (C) and subwoofer (LFE) channels are left silent. |
| 177 | output.L = input.L |
| 178 | output.R = input.R |
| 179 | output.C = 0 |
| 180 | output.LFE = 0 |
| 181 | output.SL = input.SL |
| 182 | output.SR = input.SR |
| 183 | */ |
| 184 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).5] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).6] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).4] = 1.0; |
| 185 | } else { |
| 186 | dimensionsCovered = false; |
| 187 | } |
| 188 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. == 6) { // 5.1 input) |
| 189 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 1) { // down-mix to mono |
| 190 | /* |
| 191 | The left (L and SL), right (R and SR) and central channels are all mixed together. |
| 192 | The surround channels are slightly attenuated and the regular lateral channels are power-compensated to make them count as a single channel by multiplying by √2/2. |
| 193 | The subwoofer (LFE) channel is lost. |
| 194 | output.M = 0.7071 * (input.L + input.R) + input.C + 0.5 * (input.SL + input.SR) |
| 195 | */ |
| 196 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = 1.0; |
| 197 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 0.5; // NUMsqrt1_2 is not safe if the channels are equal; |
| 198 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).5] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).6] = 0.5; |
| 199 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 2) { // down-mix to stereo |
| 200 | /* |
| 201 | The central channel (C) is summed with each lateral surround channel (SL or SR) and mixed to each lateral channel. |
| 202 | As it is mixed down to two channels, it is mixed at a lower power: in each case it is multiplied by √2/2. |
| 203 | The subwoofer (LFE) channel is lost. |
| 204 | output.L = input.L + 0.7071 * (input.C + input.SL) |
| 205 | output.R = input.R + 0.7071 * (input.C + input.SR) |
| 206 | */ |
| 207 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = 1.0; |
| 208 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).5] = 0.5; // NUMsqrt1_2; |
| 209 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).6] = 0.5; // NUMsqrt1_2; |
| 210 | } else if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. == 4) { // down-mix to quad |
| 211 | /* |
| 212 | The central (C) is mixed with the lateral non-surround channels (L and R). |
| 213 | As it is mixed down to two channels, it is mixed at a lower power: in each case it is multiplied by √2/2. |
| 214 | The surround channels are passed unchanged. The subwoofer (LFE) channel is lost. |
| 215 | output.L = input.L + 0.7071 * input.C |
| 216 | output.R = input.R + 0.7071 * input.C |
| 217 | output.SL = input.SL |
| 218 | output.SR = input.SR |
| 219 | */ |
| 220 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).5] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).4] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).6] = 1.0; |
| 221 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).3] = NUMsqrt1_2cxx . . $ NUMsqrt1_2.; |
| 222 | } else { |
| 223 | dimensionsCovered = false; |
| 224 | } |
| 225 | } else { |
| 226 | dimensionsCovered = false; |
| 227 | } |
| 228 | if (! dimensionsCovered) { |
| 229 | /* |
| 230 | Fill each output channel with its input counterpart, that is the input channel with the same index. |
| 231 | Channels with no corresponding input channels are left silent. |
| 232 | */ |
| 233 | const integercxx . . $ integer# lowerDimension = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows., mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.); |
| 234 | for (integercxx . . $ integer# i = 1; i <= lowerDimension; i++) |
| 235 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = 1.0; |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | void MixingMatrix_muteAndActivateChannelscxx . . $ MixingMatrix_muteAndActivateChannels(31a0bef1e1312fe8). (MixingMatrixcxx . . $ MixingMatrix# me, constBOOLVECcxx . . $ constBOOLVEC# const& muteChannels) { |
| 240 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (muteChannels.size == mycxx . . $ `melder/melder.h:44:9`! numberOfColumns); |
| 241 | integercxx . . $ integer# numberOfMuteChannels = 0; |
| 242 | for (integercxx . . $ integer# ichan = 1; ichan <= muteChannels.sizecxx . . $ constvector#size.; ichan ++) |
| 243 | if (muteChannels [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).ichan]) |
| 244 | numberOfMuteChannels ++; |
| 245 | /* |
| 246 | Set all mute channels to 0 and all other channels to 1. |
| 247 | To prevent overflow, scale by the number of channels that are on. |
| 248 | */ |
| 249 | const double coefficient = ( mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. > numberOfMuteChannels ? 1.0 / (mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns. - numberOfMuteChannels) : 0.0 ); |
| 250 | for (integercxx . . $ integer# ichan = 1; ichan <= mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.; ichan ++) { |
| 251 | const double channelScaling = ( muteChannels [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).ichan] ? 0.0 : coefficient ); |
| 252 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; irow ++) |
| 253 | mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ichan] = channelScaling; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | /* End of file MixingMatrix.cpp */ |