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.
40 lines
768 B
C++
40 lines
768 B
C++
#include "audiooutputdeviceproxy.h"
|
|
|
|
#include "audiobufferaverage.h"
|
|
|
|
AudioOutputDeviceProxy::AudioOutputDeviceProxy() :
|
|
device_(nullptr),
|
|
send_averages_(false)
|
|
{
|
|
}
|
|
|
|
void AudioOutputDeviceProxy::SetDevice(QIODevice *device)
|
|
{
|
|
device_ = device;
|
|
}
|
|
|
|
void AudioOutputDeviceProxy::SetSendAverages(bool send)
|
|
{
|
|
send_averages_ = send;
|
|
}
|
|
|
|
qint64 AudioOutputDeviceProxy::readData(char *data, qint64 maxlen)
|
|
{
|
|
if (device_) {
|
|
qint64 read_count = device_->read(data, maxlen);
|
|
|
|
if (send_averages_ && read_count > 0) {
|
|
emit ProcessedAverages(AudioBufferAverage::ProcessAverages(data, static_cast<int>(read_count)));
|
|
}
|
|
|
|
return read_count;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
qint64 AudioOutputDeviceProxy::writeData(const char *data, qint64 maxSize)
|
|
{
|
|
return -1;
|
|
}
|