Previously the audio output manager was a "hybrid device" that acted as a pull device for audio devices and as a push device and device proxy for the rest of the application. This approach turned out to be flawed, particularly in the frequent opening and closing of the audio device (extremely slow). Since we use both pulling (for constant playback) and pushing (audio scrubbing, short bursts of sound), it needed a similar but different approach. This approach will switch the output device from push mode (default) to pull mode (during playback) only when necessary resulting in far less UI lag (basically unnoticeable now) than the previous approach.
21 lines
602 B
C++
21 lines
602 B
C++
#include "audiobufferaverage.h"
|
|
|
|
QVector<double> AudioBufferAverage::ProcessAverages(const char *data, int length)
|
|
{
|
|
// 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);
|
|
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])));
|
|
}
|
|
|
|
return averages;
|
|
}
|