1104{
1105 if (streams.empty() || gains.size() != streams.size()) {
1106 throw std::invalid_argument("Streams and gains vectors must have the same size");
1107 }
1108
1109 auto numeric_data = Yantra::OperationHelper::extract_numeric_data(streams);
1110
1111 if (is_same_size(numeric_data)) {
1112 size_t channel_length = numeric_data[0].size();
1113 std::vector<double> result(channel_length, 0.0);
1114
1115 for (size_t s = 0; s < numeric_data.size(); ++s) {
1116 const auto& span = numeric_data[s];
1117 double gain = gains[s];
1118
1119 for (size_t i = 0; i < span.size(); ++i) {
1120 result[i] += span[i] * gain;
1121 }
1122 }
1123
1124 return result;
1125 }
1126
1127 std::vector<std::vector<double>> double_streams;
1128 double_streams.reserve(streams.size());
1129
1130 for (const auto& span : numeric_data) {
1131 double_streams.emplace_back(span.begin(), span.end());
1132 }
1133
1135}
std::vector< double > mix_with_gains(const std::vector< std::vector< double > > &streams, const std::vector< double > &gains)
Mix multiple data streams with specified gains.