mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 17:35:08 +02:00
Add outputBufferSizeFrames property to Audio
This commit is contained in:
parent
bd88e0f38d
commit
f97109f6a4
2 changed files with 24 additions and 3 deletions
|
@ -60,6 +60,8 @@ static const int MUTE_ICON_SIZE = 24;
|
|||
|
||||
static const int RECEIVED_AUDIO_STREAM_CAPACITY_FRAMES = 100;
|
||||
|
||||
static const int DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3;
|
||||
|
||||
Audio::Audio(QObject* parent) :
|
||||
AbstractAudioInterface(parent),
|
||||
_audioInput(NULL),
|
||||
|
@ -123,6 +125,7 @@ Audio::Audio(QObject* parent) :
|
|||
_inputRingBufferMsecsAvailableStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS),
|
||||
_audioOutputMsecsUnplayedStats(1, FRAMES_AVAILABLE_STATS_WINDOW_SECONDS),
|
||||
_lastSentAudioPacket(0),
|
||||
_outputBufferSizeFrames(DEFAULT_AUDIO_OUTPUT_BUFFER_SIZE_FRAMES),
|
||||
_packetSentTimeGaps(1, APPROXIMATELY_30_SECONDS_OF_AUDIO_PACKETS),
|
||||
_audioOutputIODevice(_receivedAudioStream)
|
||||
{
|
||||
|
@ -443,6 +446,7 @@ void Audio::start() {
|
|||
QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput);
|
||||
qDebug() << "The default audio output device is" << outputDeviceInfo.deviceName();
|
||||
bool outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo);
|
||||
outputFormatSupported = switchOutputToAudioDevice(outputDeviceInfo);
|
||||
|
||||
if (!inputFormatSupported) {
|
||||
qDebug() << "Unable to set up audio input because of a problem with input format.";
|
||||
|
@ -1852,11 +1856,9 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
|
|||
|
||||
outputFormatChanged();
|
||||
|
||||
const int AUDIO_OUTPUT_BUFFER_SIZE_FRAMES = 3;
|
||||
|
||||
// setup our general output device for audio-mixer audio
|
||||
_audioOutput = new QAudioOutput(outputDeviceInfo, _outputFormat, this);
|
||||
_audioOutput->setBufferSize(AUDIO_OUTPUT_BUFFER_SIZE_FRAMES * _outputFrameSize * sizeof(int16_t));
|
||||
_audioOutput->setBufferSize(_outputBufferSizeFrames * _outputFrameSize * sizeof(int16_t));
|
||||
qDebug() << "Output Buffer capacity in frames: " << _audioOutput->bufferSize() / sizeof(int16_t) / (float)_outputFrameSize;
|
||||
|
||||
_audioOutputIODevice.start();
|
||||
|
@ -1877,6 +1879,20 @@ bool Audio::switchOutputToAudioDevice(const QAudioDeviceInfo& outputDeviceInfo)
|
|||
return supportedFormat;
|
||||
}
|
||||
|
||||
void Audio::setOutputBufferSize(int numFrames) {
|
||||
if (numFrames != _outputBufferSizeFrames) {
|
||||
qDebug() << "Audio output buffer size (frames): " << numFrames;
|
||||
_outputBufferSizeFrames = numFrames;
|
||||
|
||||
if (_audioOutput) {
|
||||
// The buffer size can't be adjusted after QAudioOutput::start() has been called, so
|
||||
// recreate the device by switching to the default.
|
||||
QAudioDeviceInfo outputDeviceInfo = defaultAudioDeviceForMode(QAudio::AudioOutput);
|
||||
switchOutputToAudioDevice(outputDeviceInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The following constant is operating system dependent due to differences in
|
||||
// the way input audio is handled. The audio input buffer size is inversely
|
||||
// proportional to the accelerator ratio.
|
||||
|
|
|
@ -123,6 +123,8 @@ public:
|
|||
|
||||
void setRecorder(RecorderPointer recorder) { _recorder = recorder; }
|
||||
|
||||
int getOutputBufferSize() { return _outputBufferSizeFrames; }
|
||||
|
||||
public slots:
|
||||
void start();
|
||||
void stop();
|
||||
|
@ -150,6 +152,7 @@ public slots:
|
|||
void addLastFrameRepeatedWithFadeToScope(int samplesPerChannel);
|
||||
void addStereoSamplesToScope(const QByteArray& samples);
|
||||
void processReceivedSamples(const QByteArray& inputBuffer, QByteArray& outputBuffer);
|
||||
void setOutputBufferSize(int numFrames);
|
||||
|
||||
virtual bool outputLocalInjector(bool isStereo, qreal volume, AudioInjector* injector);
|
||||
|
||||
|
@ -201,6 +204,8 @@ private:
|
|||
|
||||
QString _inputAudioDeviceName;
|
||||
QString _outputAudioDeviceName;
|
||||
|
||||
int _outputBufferSizeFrames;
|
||||
|
||||
StDev _stdev;
|
||||
QElapsedTimer _timeSinceLastReceived;
|
||||
|
|
Loading…
Reference in a new issue