mirror of https://github.com/mgba-emu/mgba.git
Add sound buffer resizing menu options
This commit is contained in:
parent
62f6471c0d
commit
71211bac46
|
@ -8,8 +8,6 @@ extern "C" {
|
|||
#include "gba-thread.h"
|
||||
}
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace QGBA;
|
||||
|
||||
AudioProcessor::AudioProcessor(QObject* parent)
|
||||
|
@ -48,11 +46,16 @@ void AudioProcessor::start() {
|
|||
|
||||
m_device->setInput(m_context);
|
||||
m_device->setFormat(m_audioOutput->format());
|
||||
m_audioOutput->setBufferSize(m_context->audioBuffers * 4);
|
||||
|
||||
assert(m_audioOutput->thread() == thread());
|
||||
m_audioOutput->start(m_device);
|
||||
}
|
||||
|
||||
void AudioProcessor::pause() {
|
||||
m_audioOutput->stop();
|
||||
}
|
||||
|
||||
void AudioProcessor::setBufferSamples(int samples) {
|
||||
QAudioFormat format = m_audioOutput->format();
|
||||
m_audioOutput->setBufferSize(samples * format.channelCount() * format.sampleSize() / 8);
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@ public slots:
|
|||
void start();
|
||||
void pause();
|
||||
|
||||
void setBufferSamples(int samples);
|
||||
|
||||
private:
|
||||
GBAThread* m_context;
|
||||
QAudioOutput* m_audioOutput;
|
||||
|
|
|
@ -166,6 +166,14 @@ void GameController::keyReleased(int key) {
|
|||
updateKeys();
|
||||
}
|
||||
|
||||
void GameController::setAudioBufferSamples(int samples) {
|
||||
GBAThreadInterrupt(&m_threadContext);
|
||||
m_threadContext.audioBuffers = samples;
|
||||
GBAAudioResizeBuffer(&m_threadContext.gba->audio, samples);
|
||||
GBAThreadContinue(&m_threadContext);
|
||||
QMetaObject::invokeMethod(m_audioProcessor, "setBufferSamples", Q_ARG(int, samples));
|
||||
}
|
||||
|
||||
void GameController::updateKeys() {
|
||||
int activeKeys = m_activeKeys;
|
||||
#ifdef BUILD_SDL
|
||||
|
|
|
@ -51,6 +51,7 @@ public slots:
|
|||
void frameAdvance();
|
||||
void keyPressed(int key);
|
||||
void keyReleased(int key);
|
||||
void setAudioBufferSamples(int samples);
|
||||
|
||||
#ifdef BUILD_SDL
|
||||
private slots:
|
||||
|
|
|
@ -28,6 +28,7 @@ Window::Window(QWidget* parent)
|
|||
connect(m_controller, SIGNAL(gameStopped(GBAThread*)), this, SLOT(gameStopped()));
|
||||
connect(this, SIGNAL(startDrawing(const uint32_t*, GBAThread*)), m_display, SLOT(startDrawing(const uint32_t*, GBAThread*)), Qt::QueuedConnection);
|
||||
connect(this, SIGNAL(shutdown()), m_display, SLOT(stopDrawing()));
|
||||
connect(this, SIGNAL(audioBufferSamplesChanged(int)), m_controller, SLOT(setAudioBufferSamples(int)));
|
||||
|
||||
setupMenu(menuBar());
|
||||
}
|
||||
|
@ -132,6 +133,22 @@ void Window::gameStopped() {
|
|||
}
|
||||
}
|
||||
|
||||
void Window::setBuffers512() {
|
||||
emit audioBufferSamplesChanged(512);
|
||||
}
|
||||
|
||||
void Window::setBuffers1024() {
|
||||
emit audioBufferSamplesChanged(1024);
|
||||
}
|
||||
|
||||
void Window::setBuffers2048() {
|
||||
emit audioBufferSamplesChanged(2048);
|
||||
}
|
||||
|
||||
void Window::setBuffers4096() {
|
||||
emit audioBufferSamplesChanged(4096);
|
||||
}
|
||||
|
||||
void Window::setupMenu(QMenuBar* menubar) {
|
||||
menubar->clear();
|
||||
QMenu* fileMenu = menubar->addMenu(tr("&File"));
|
||||
|
@ -139,7 +156,7 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
fileMenu->addAction(tr("Sh&utdown"), m_controller, SLOT(closeGame()));
|
||||
|
||||
QMenu* emulationMenu = menubar->addMenu(tr("&Emulation"));
|
||||
QAction* pause = new QAction(tr("&Pause"), 0);
|
||||
QAction* pause = new QAction(tr("&Pause"), nullptr);
|
||||
pause->setChecked(false);
|
||||
pause->setCheckable(true);
|
||||
pause->setShortcut(tr("Ctrl+P"));
|
||||
|
@ -148,13 +165,20 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
m_gameActions.append(pause);
|
||||
emulationMenu->addAction(pause);
|
||||
|
||||
QAction* frameAdvance = new QAction(tr("&Next frame"), 0);
|
||||
QAction* frameAdvance = new QAction(tr("&Next frame"), nullptr);
|
||||
frameAdvance->setShortcut(tr("Ctrl+N"));
|
||||
frameAdvance->setDisabled(true);
|
||||
connect(frameAdvance, SIGNAL(triggered()), m_controller, SLOT(frameAdvance()));
|
||||
m_gameActions.append(frameAdvance);
|
||||
emulationMenu->addAction(frameAdvance);
|
||||
|
||||
QMenu* soundMenu = menubar->addMenu(tr("&Sound"));
|
||||
QMenu* buffersMenu = soundMenu->addMenu(tr("Buffer &size"));
|
||||
buffersMenu->addAction(tr("512"), this, SLOT(setBuffers512()));
|
||||
buffersMenu->addAction(tr("1024"), this, SLOT(setBuffers1024()));
|
||||
buffersMenu->addAction(tr("2048"), this, SLOT(setBuffers2048()));
|
||||
buffersMenu->addAction(tr("4096"), this, SLOT(setBuffers4096()));
|
||||
|
||||
QMenu* debuggingMenu = menubar->addMenu(tr("&Debugging"));
|
||||
#ifdef USE_GDB_STUB
|
||||
QAction* gdbWindow = new QAction(tr("Start &GDB server..."), nullptr);
|
||||
|
|
|
@ -38,10 +38,18 @@ protected:
|
|||
virtual void keyReleaseEvent(QKeyEvent* event) override;
|
||||
virtual void closeEvent(QCloseEvent*) override;
|
||||
|
||||
signals:
|
||||
void audioBufferSamplesChanged(int samples);
|
||||
|
||||
private slots:
|
||||
void gameStarted(GBAThread*);
|
||||
void gameStopped();
|
||||
|
||||
void setBuffers512();
|
||||
void setBuffers1024();
|
||||
void setBuffers2048();
|
||||
void setBuffers4096();
|
||||
|
||||
private:
|
||||
void setupMenu(QMenuBar*);
|
||||
GameController* m_controller;
|
||||
|
|
Loading…
Reference in New Issue