From 47124bda2eb23eea4fe8e39d0850aa2b66778172 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Wed, 10 Oct 2018 15:13:11 -0700 Subject: [PATCH] Use correct sound buffer size everywhere --- qtBuildSystem/Mu/emuwrapper.cpp | 4 ++-- qtBuildSystem/Mu/mainwindow.cpp | 2 +- src/emulator.c | 2 +- src/emulator.h | 2 +- tests/audioAddress.txt | 1 + tools/palm/muExpansionDriver/soundDriver.c | 1 + tools/palm/muExpansionDriver/soundDriver.h | 1 + 7 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 tests/audioAddress.txt create mode 100644 tools/palm/muExpansionDriver/soundDriver.c create mode 100644 tools/palm/muExpansionDriver/soundDriver.h diff --git a/qtBuildSystem/Mu/emuwrapper.cpp b/qtBuildSystem/Mu/emuwrapper.cpp index 797fd55..2441c7c 100644 --- a/qtBuildSystem/Mu/emuwrapper.cpp +++ b/qtBuildSystem/Mu/emuwrapper.cpp @@ -93,7 +93,7 @@ void EmuWrapper::emuThreadRun(){ emulateFrame(); if(!emuNewFrameReady){ memcpy(emuDoubleBufferVideo, emuVideoWidth == 320 ? palmExtendedFramebuffer : palmFramebuffer, emuVideoWidth * emuVideoHeight * sizeof(uint16_t)); - memcpy(emuDoubleBufferAudio, palmAudio, AUDIO_SAMPLES); + memcpy(emuDoubleBufferAudio, palmAudio, AUDIO_SAMPLES * 2/*channels*/ * sizeof(int16_t)); emuNewFrameReady = true; } } @@ -207,7 +207,7 @@ uint32_t EmuWrapper::init(const QString& romPath, const QString& bootloaderPath, emuPaused = false; emuNewFrameReady = false; emuDoubleBufferVideo = new uint16_t[emuVideoWidth * emuVideoHeight]; - emuDoubleBufferAudio = new int16_t[CRYSTAL_FREQUENCY * AUDIO_DUTY_CYCLE_SIZE * 2/*channels*/]; + emuDoubleBufferAudio = new int16_t[AUDIO_SAMPLES * 2/*channels*/]; emuThread = std::thread(&EmuWrapper::emuThreadRun, this); } else{ diff --git a/qtBuildSystem/Mu/mainwindow.cpp b/qtBuildSystem/Mu/mainwindow.cpp index 8044061..afb5a47 100644 --- a/qtBuildSystem/Mu/mainwindow.cpp +++ b/qtBuildSystem/Mu/mainwindow.cpp @@ -170,7 +170,7 @@ void MainWindow::updateDisplay(){ ui->display->repaint(); //audio - audioOut->write((const char*)emu.getAudioSamples(), AUDIO_SAMPLES * sizeof(int16_t)); + audioOut->write((const char*)emu.getAudioSamples(), AUDIO_SAMPLES * 2/*channels*/ * sizeof(int16_t)); //power LED ui->powerButtonLed->setStyleSheet(emu.getPowerButtonLed() ? "background: lime" : ""); diff --git a/src/emulator.c b/src/emulator.c index a82acbc..a5e3a26 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -95,7 +95,7 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t spec memset(palmExtendedFramebuffer, 0x00, 320 * 320 * sizeof(uint16_t)); //add 320*320 silkscreen image later, 2xBRZ should be able to make 320*320 version of the 160*160 silkscreen } - memset(palmAudio, 0x00, AUDIO_SAMPLES * 2 * sizeof(int16_t)); + memset(palmAudio, 0x00, AUDIO_SAMPLES * 2/*channels*/ * sizeof(int16_t)); m68328Reset(); sed1376Reset(); ads7846Reset(); diff --git a/src/emulator.h b/src/emulator.h index 55f3488..5e14bc4 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -112,12 +112,12 @@ typedef struct{ }misc_hw_t; //config options +#define EMU_FPS 60 #define AUDIO_DUTY_CYCLE_SIZE 20//the amount of frequencys the PWM can play #define SAVE_STATE_VERSION 0 //system constants #define CRYSTAL_FREQUENCY 32768 -#define EMU_FPS 60 #define AUDIO_SAMPLES (CRYSTAL_FREQUENCY / EMU_FPS * AUDIO_DUTY_CYCLE_SIZE) //emulator data, some are GUI interface variables, some should be left alone diff --git a/tests/audioAddress.txt b/tests/audioAddress.txt new file mode 100644 index 0000000..f3dc124 --- /dev/null +++ b/tests/audioAddress.txt @@ -0,0 +1 @@ +Audio write, PC:0x10087FC4(printed 4 times) diff --git a/tools/palm/muExpansionDriver/soundDriver.c b/tools/palm/muExpansionDriver/soundDriver.c new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tools/palm/muExpansionDriver/soundDriver.c @@ -0,0 +1 @@ + diff --git a/tools/palm/muExpansionDriver/soundDriver.h b/tools/palm/muExpansionDriver/soundDriver.h new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tools/palm/muExpansionDriver/soundDriver.h @@ -0,0 +1 @@ +