From 7c7cb61d2fe9dc1fbaa5a23ed0094754f2442b3e Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sat, 6 Jun 2020 22:35:50 -0400 Subject: [PATCH] Corrects missing audio, at the cost of frame rate. I'm now spinning on the ability of QAudioOutput to accept additional data. --- OSBindings/Qt/mainwindow.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OSBindings/Qt/mainwindow.cpp b/OSBindings/Qt/mainwindow.cpp index 46b4b0953..3244bf10d 100644 --- a/OSBindings/Qt/mainwindow.cpp +++ b/OSBindings/Qt/mainwindow.cpp @@ -180,7 +180,7 @@ void MainWindow::launchMachine() { // are available, and — at least for now — assume 512 samples/buffer is a good size. audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo(); audioIs8bit = idealFormat.sampleSize() < 16; - const int samplesPerBuffer = 65536; + const int samplesPerBuffer = 512; speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo); // Adjust format appropriately, and create an audio output. @@ -322,7 +322,13 @@ bool MainWindow::eventFilter(QObject *obj, QEvent *event) { case QEvent::User: { const auto audioEvent = dynamic_cast(event); if(audioEvent) { - audioIODevice->write(reinterpret_cast(audioEvent->audio.data()), qint64(audioEvent->audio.size())); + const char *buffer = reinterpret_cast(audioEvent->audio.data()); + size_t sizeLeft = audioEvent->audio.size() * sizeof(int16_t); + while(sizeLeft) { + const auto bytesWritten = audioIODevice->write(buffer, qint64(sizeLeft)); + sizeLeft -= bytesWritten; + buffer += bytesWritten; + } } } break;