audio: removed hardcoded stereo value
Fixes bug that caused AudioMonitor to only show two channels regardless of the actual number of channels being mixed.
This commit is contained in:
@@ -22,20 +22,19 @@
|
||||
|
||||
OLIVE_NAMESPACE_ENTER
|
||||
|
||||
QVector<double> AudioBufferAverage::ProcessAverages(const char *data, int length)
|
||||
QVector<double> AudioBufferAverage::ProcessAverages(const char *data, int length, int channel_count)
|
||||
{
|
||||
// FIXME: Assumes float and stereo
|
||||
const float* samples = reinterpret_cast<const float*>(data);
|
||||
int sample_count = static_cast<int>(length / static_cast<int>(sizeof(float)));
|
||||
int channels = 2;
|
||||
|
||||
// Create array of samples to send
|
||||
QVector<double> averages(channels);
|
||||
QVector<double> averages(channel_count);
|
||||
averages.fill(0);
|
||||
|
||||
// Add all samples together
|
||||
for (int i=0;i<sample_count;i++) {
|
||||
averages[i%channels] = qMax(averages[i%channels], static_cast<double>(qAbs(samples[i])));
|
||||
averages[i%channel_count] = qMax(averages[i%channel_count], static_cast<double>(qAbs(samples[i])));
|
||||
}
|
||||
|
||||
return averages;
|
||||
|
||||
@@ -32,7 +32,7 @@ class AudioBufferAverage
|
||||
public:
|
||||
AudioBufferAverage() = default;
|
||||
|
||||
static QVector<double> ProcessAverages(const char* data, int length);
|
||||
static QVector<double> ProcessAverages(const char* data, int length, int channel_count);
|
||||
};
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
@@ -94,7 +94,7 @@ qint64 AudioOutputDeviceProxy::readData(char *data, qint64 maxlen)
|
||||
|
||||
// If we read any
|
||||
if (read_count > 0 && send_averages_) {
|
||||
emit ProcessedAverages(AudioBufferAverage::ProcessAverages(data, static_cast<int>(read_count)));
|
||||
emit ProcessedAverages(AudioBufferAverage::ProcessAverages(data, static_cast<int>(read_count), params_.channel_count()));
|
||||
}
|
||||
|
||||
return read_count;
|
||||
|
||||
@@ -151,7 +151,7 @@ void AudioOutputManager::ProcessAverages(const char *data, int length)
|
||||
return;
|
||||
}
|
||||
|
||||
emit SentSamples(AudioBufferAverage::ProcessAverages(data, length));
|
||||
emit SentSamples(AudioBufferAverage::ProcessAverages(data, length, output_.get()->format().channelCount()));
|
||||
}
|
||||
|
||||
OLIVE_NAMESPACE_EXIT
|
||||
|
||||
Reference in New Issue
Block a user