mirror of
https://github.com/sle118/squeezelite-esp32.git
synced 2025-12-10 21:47:04 +03:00
new cspot/bell
This commit is contained in:
@@ -1,39 +1,44 @@
|
||||
#include "AudioMixer.h"
|
||||
|
||||
#include <mutex> // for scoped_lock
|
||||
|
||||
using namespace bell;
|
||||
|
||||
AudioMixer::AudioMixer() {
|
||||
}
|
||||
AudioMixer::AudioMixer() {}
|
||||
|
||||
std::unique_ptr<StreamInfo> AudioMixer::process(std::unique_ptr<StreamInfo> info) {
|
||||
std::scoped_lock lock(this->accessMutex);
|
||||
if (info->numChannels != from) {
|
||||
throw std::runtime_error("AudioMixer: Input channel count does not match configuration");
|
||||
}
|
||||
info->numChannels = to;
|
||||
std::unique_ptr<StreamInfo> AudioMixer::process(
|
||||
std::unique_ptr<StreamInfo> info) {
|
||||
std::scoped_lock lock(this->accessMutex);
|
||||
if (info->numChannels != from) {
|
||||
throw std::runtime_error(
|
||||
"AudioMixer: Input channel count does not match configuration");
|
||||
}
|
||||
info->numChannels = to;
|
||||
|
||||
for (auto &singleConf : mixerConfig) {
|
||||
if (singleConf.source.size() == 1) {
|
||||
if (singleConf.source[0] == singleConf.destination) {
|
||||
continue;
|
||||
}
|
||||
// Copy channel
|
||||
for (int i = 0; i < info->numSamples; i++) {
|
||||
info->data[singleConf.destination][i] = info->data[singleConf.source[0]][i];
|
||||
}
|
||||
} else {
|
||||
// Mix channels
|
||||
float sample = 0.0f;
|
||||
for (int i = 0; i < info->numSamples; i++) {
|
||||
sample = 0.0;
|
||||
for (auto &source : singleConf.source) {
|
||||
sample += info->data[source][i];
|
||||
}
|
||||
|
||||
info->data[singleConf.destination][i] = sample / (float) singleConf.source.size();
|
||||
}
|
||||
for (auto& singleConf : mixerConfig) {
|
||||
if (singleConf.source.size() == 1) {
|
||||
if (singleConf.source[0] == singleConf.destination) {
|
||||
continue;
|
||||
}
|
||||
// Copy channel
|
||||
for (int i = 0; i < info->numSamples; i++) {
|
||||
info->data[singleConf.destination][i] =
|
||||
info->data[singleConf.source[0]][i];
|
||||
}
|
||||
} else {
|
||||
// Mix channels
|
||||
float sample = 0.0f;
|
||||
for (int i = 0; i < info->numSamples; i++) {
|
||||
sample = 0.0;
|
||||
for (auto& source : singleConf.source) {
|
||||
sample += info->data[source][i];
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
info->data[singleConf.destination][i] =
|
||||
sample / (float)singleConf.source.size();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
Reference in New Issue
Block a user