Add sound buffer resizing menu options
Jeffrey Pfau jeffrey@endrift.com
Tue, 22 Jul 2014 00:32:38 -0700
6 files changed,
51 insertions(+),
5 deletions(-)
M
src/platform/qt/AudioProcessor.cpp
→
src/platform/qt/AudioProcessor.cpp
@@ -8,8 +8,6 @@ extern "C" {
#include "gba-thread.h" } -#include <cassert> - using namespace QGBA; AudioProcessor::AudioProcessor(QObject* parent)@@ -48,11 +46,16 @@ }
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); +}
M
src/platform/qt/AudioProcessor.h
→
src/platform/qt/AudioProcessor.h
@@ -22,6 +22,8 @@ public slots:
void start(); void pause(); + void setBufferSamples(int samples); + private: GBAThread* m_context; QAudioOutput* m_audioOutput;
M
src/platform/qt/GameController.cpp
→
src/platform/qt/GameController.cpp
@@ -166,6 +166,14 @@ m_activeKeys &= ~mappedKey;
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
M
src/platform/qt/GameController.h
→
src/platform/qt/GameController.h
@@ -51,6 +51,7 @@ void setPaused(bool paused);
void frameAdvance(); void keyPressed(int key); void keyReleased(int key); + void setAudioBufferSamples(int samples); #ifdef BUILD_SDL private slots:
M
src/platform/qt/Window.cpp
→
src/platform/qt/Window.cpp
@@ -28,6 +28,7 @@ connect(m_controller, SIGNAL(gameStopped(GBAThread*)), m_display, SLOT(stopDrawing()));
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 @@ action->setDisabled(true);
} } +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 @@ fileMenu->addAction(tr("Load &ROM..."), this, SLOT(selectROM()), QKeySequence::Open);
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,12 +165,19 @@ connect(pause, SIGNAL(triggered(bool)), m_controller, SLOT(setPaused(bool)));
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
M
src/platform/qt/Window.h
→
src/platform/qt/Window.h
@@ -38,9 +38,17 @@ virtual void keyPressEvent(QKeyEvent* event) override;
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*);