switch from qtMedia to rtAudio
This commit is contained in:
@@ -1,27 +1,28 @@
|
||||
|
||||
cmake_minimum_required(VERSION 3.21)
|
||||
project(metabolus LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets Multimedia)
|
||||
find_package(Qt6 REQUIRED COMPONENTS Widgets)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(RTAUDIO REQUIRED rtaudio)
|
||||
|
||||
qt_standard_project_setup()
|
||||
|
||||
qt_add_executable(metabolus
|
||||
add_executable(metabolus
|
||||
src/main.cpp
|
||||
src/MainWindow.cpp
|
||||
src/MainWindow.h
|
||||
src/MainWindow.ui
|
||||
src/synth/AudioStream.cpp
|
||||
src/synth/AudioStream.h
|
||||
src/synth/AudioEngine.cpp
|
||||
src/synth/AudioEngine.h
|
||||
src/synth/Synth.cpp
|
||||
src/synth/Synth.h
|
||||
resources/resources.qrc
|
||||
)
|
||||
|
||||
target_link_libraries(metabolus
|
||||
PRIVATE
|
||||
Qt6::Widgets
|
||||
Qt6::Multimedia
|
||||
)
|
||||
target_include_directories(metabolus PRIVATE ${RTAUDIO_INCLUDE_DIRS})
|
||||
target_link_libraries(metabolus PRIVATE Qt6::Widgets ${RTAUDIO_LIBRARIES})
|
||||
target_compile_options(metabolus PRIVATE ${RTAUDIO_CFLAGS_OTHER})
|
||||
|
||||
@@ -21,11 +21,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
connect(ui->inputValue, &QLineEdit::editingFinished, this, &MainWindow::onValueChanged);
|
||||
|
||||
// synth business
|
||||
synth_ = new Synth(this);
|
||||
audioStream_ = new AudioStream(synth_, this);
|
||||
|
||||
audioStream_->start();
|
||||
synth_->audioSink()->start(audioStream_);
|
||||
audio_ = new AudioEngine();
|
||||
audio_->start();
|
||||
|
||||
}
|
||||
|
||||
@@ -52,7 +49,7 @@ void MainWindow::onSliderValueChanged(int value) {
|
||||
QSignalBlocker blocker(ui->inputValue);
|
||||
ui->inputValue->setText(QString::number(value));
|
||||
|
||||
synth_->setFrequency(static_cast<float>(value));
|
||||
audio_->setFrequency(static_cast<float>(value));
|
||||
}
|
||||
|
||||
// allows only values within the min, max to be set by the text field
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "synth/Synth.h"
|
||||
#include "synth/AudioStream.h"
|
||||
#include "synth/AudioEngine.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@@ -42,7 +41,6 @@ private:
|
||||
void applySliderStep();
|
||||
void syncValueToUi(int value);
|
||||
|
||||
Synth *synth_ = nullptr;
|
||||
AudioStream *audioStream_ = nullptr;
|
||||
AudioEngine* audio_ = nullptr;
|
||||
|
||||
};
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
|
||||
#include "AudioStream.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
AudioStream::AudioStream(Synth *synth, QObject *parent) : QIODevice(parent), synth_(synth) {
|
||||
|
||||
}
|
||||
|
||||
void AudioStream::start() {
|
||||
|
||||
// std::cout << "AudioStream::start()" << std::endl;
|
||||
open(QIODevice::ReadOnly);
|
||||
}
|
||||
|
||||
void AudioStream::stop() {
|
||||
|
||||
close();
|
||||
}
|
||||
|
||||
qint64 AudioStream::readData(char *data, qint64 maxlen) {
|
||||
|
||||
// std::cout << "sample out " << std::endl;
|
||||
QByteArray samples = synth_->generateSamples(maxlen);
|
||||
memcpy(data, samples.constData(), samples.size());
|
||||
return samples.size();
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QIODevice>
|
||||
#include "Synth.h"
|
||||
|
||||
class AudioStream : public QIODevice
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AudioStream(Synth *synth, QObject *parent = nullptr);
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
protected:
|
||||
qint64 readData(char *data, qint64 maxlen) override;
|
||||
qint64 writeData(const char *, qint64) override { return 0; }
|
||||
|
||||
private:
|
||||
Synth *synth_;
|
||||
};
|
||||
@@ -1,4 +1,6 @@
|
||||
|
||||
/*
|
||||
|
||||
#include "Synth.h"
|
||||
|
||||
#include <QMediaDevices>
|
||||
@@ -28,13 +30,12 @@ Synth::~Synth() {
|
||||
|
||||
void Synth::start() {
|
||||
|
||||
/*
|
||||
// std::cout << "Synth::start()" << std::endl;
|
||||
if (audioSink_->state() == QAudio::ActiveState)
|
||||
return;
|
||||
// if (audioSink_->state() == QAudio::ActiveState)
|
||||
// return;
|
||||
|
||||
audioDevice_ = audioSink_->start();
|
||||
*/
|
||||
// audioDevice_ = audioSink_->start();
|
||||
|
||||
}
|
||||
|
||||
void Synth::stop() {
|
||||
@@ -109,4 +110,6 @@ void Synth::applyConfig(const AudioConfig& config) {
|
||||
audioSink_ = new QAudioSink(device, format_, this);
|
||||
|
||||
audioSink_->setBufferSize(config.bufferSize);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
|
||||
#include <QObject>
|
||||
#include <QAudioFormat>
|
||||
#include <QAudioSink>
|
||||
@@ -45,4 +47,6 @@ private:
|
||||
float phase_ = 0.0f;
|
||||
|
||||
float freq = 400.0f;
|
||||
};
|
||||
};
|
||||
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user