1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-11-26 08:49:37 +00:00

Reintroduce Qt5 support.

This commit is contained in:
Thomas Harte 2023-12-30 23:03:15 -05:00
parent 0c770c474b
commit c1778a8fee
3 changed files with 39 additions and 4 deletions

View File

@ -1,4 +1,5 @@
QT += core gui multimedia widgets openglwidgets
QT += core gui multimedia widgets
greaterThan(5, QT_MAJOR_VERSION) QT += openglwidgets
# Be specific about C++17 but also try the vaguer C++1z for older
# versions of Qt.
@ -25,7 +26,7 @@ DEFINES += IGNORE_APPLE
QMAKE_CXXFLAGS_RELEASE += -DNDEBUG
# Generate warnings for any use of APIs deprecated prior to Qt 7.0.0.
# Development was performed against Qt 6.6.1.
# Development was performed against Qt 6.6.1 and Qt 5.15.2
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x070000

View File

@ -2,14 +2,17 @@
#include "settings.h"
#include "timer.h"
#include <QtGlobal>
#include <QObject>
#include <QStandardPaths>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QAudioDevice>
#include <QMediaDevices>
#endif
#include <QtWidgets>
#include <QtGlobal>
#include <cstdio>
@ -317,16 +320,32 @@ void MainWindow::launchMachine() {
static constexpr size_t samplesPerBuffer = 256; // TODO: select this dynamically.
const auto speaker = audio_producer->get_speaker();
if(speaker) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QAudioDevice device(QMediaDevices::defaultAudioOutput());
if(true) { // TODO: how to check that audio output is available in Qt6?
QAudioFormat idealFormat = device.preferredFormat();
#else
const QAudioDeviceInfo &defaultDeviceInfo = QAudioDeviceInfo::defaultOutputDevice();
if(!defaultDeviceInfo.isNull()) {
QAudioFormat idealFormat = defaultDeviceInfo.preferredFormat();
#endif
// Use the ideal format's sample rate, provide stereo as long as at least two channels
// are available, and — at least for now — assume a good buffer size.
audioIsStereo = (idealFormat.channelCount() > 1) && speaker->get_is_stereo();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
audioIs8bit = idealFormat.sampleFormat() == QAudioFormat::UInt8;
#else
audioIs8bit = idealFormat.sampleSize() < 16;
#endif
idealFormat.setChannelCount(1 + int(audioIsStereo));
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
idealFormat.setSampleFormat(audioIs8bit ? QAudioFormat::UInt8 : QAudioFormat::Int16);
#else
idealFormat.setSampleSize(audioIs8bit ? 8 : 16);
#endif
speaker->set_output_rate(idealFormat.sampleRate(), samplesPerBuffer, audioIsStereo);
speaker->set_delegate(this);
@ -334,7 +353,11 @@ void MainWindow::launchMachine() {
audioThread.start();
audioThread.performAsync([&] {
// Create an audio output.
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
audioOutput = std::make_unique<QAudioSink>(device, idealFormat);
#else
audioOutput = std::make_unique<QAudioOutput>(idealFormat);
#endif
// Start the output. The additional `audioBuffer` is meant to minimise latency,
// believe it or not, given Qt's semantics.

View File

@ -1,7 +1,14 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QAudioSink>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
#include <QAudioSink>
#else
#include <QAudioOutput>
#endif
#include <QMainWindow>
#include <memory>
@ -70,7 +77,11 @@ class MainWindow : public QMainWindow, public Outputs::Speaker::Speaker::Delegat
std::unique_ptr<Machine::DynamicMachine> machine;
std::mutex machineMutex;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
std::unique_ptr<QAudioSink> audioOutput;
#else
std::unique_ptr<QAudioOutput> audioOutput;
#endif
bool audioIs8bit = false, audioIsStereo = false;
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) override;
AudioBuffer audioBuffer;