Skip to content

Commit

Permalink
Adjust audio device buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
f1xpl committed Mar 31, 2018
1 parent 75297a8 commit 2c8daca
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/autoapp/Projection/RtAudioOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ bool RtAudioOutput::open()

try
{
uint32_t bufferFrames = 128;
dac_->openStream(&parameters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast<void*>(this), nullptr);
RtAudio::StreamOptions streamOptions;
streamOptions.flags = RTAUDIO_MINIMIZE_LATENCY | RTAUDIO_SCHEDULE_REALTIME;
uint32_t bufferFrames = sampleRate_ == 16000 ? 1024 : 2048; //according to the observation of audio packets
dac_->openStream(&parameters, nullptr, RTAUDIO_SINT16, sampleRate_, &bufferFrames, &RtAudioOutput::audioBufferReadHandler, static_cast<void*>(this), &streamOptions);
return audioBuffer_.open(QIODevice::ReadWrite);
}
catch(const RtAudioError& e)
Expand Down Expand Up @@ -104,8 +106,7 @@ void RtAudioOutput::stop()

void RtAudioOutput::suspend()
{
std::lock_guard<decltype(mutex_)> lock(mutex_);
this->doSuspend();
//not needed
}

uint32_t RtAudioOutput::getSampleSize() const
Expand All @@ -125,7 +126,7 @@ uint32_t RtAudioOutput::getSampleRate() const

void RtAudioOutput::doSuspend()
{
if(!dac_->isStreamOpen() && !dac_->isStreamRunning())
if(dac_->isStreamOpen() && dac_->isStreamRunning())
{
try
{
Expand Down

0 comments on commit 2c8daca

Please sign in to comment.