From c93dc6f4f366384c064123b25e9652b584568b8c Mon Sep 17 00:00:00 2001 From: Adrian Siekierka Date: Sat, 8 Mar 2025 20:06:01 +0100 Subject: [PATCH] swan: Add command to change internal speaker loudness --- doc/7-systems/wonderswan.md | 5 +++++ src/engine/dispatch.h | 5 +++-- src/engine/platform/swan.cpp | 13 ++++++++++++- src/engine/playback.cpp | 1 + src/engine/sysDef.cpp | 3 +++ 5 files changed, 24 insertions(+), 3 deletions(-) diff --git a/doc/7-systems/wonderswan.md b/doc/7-systems/wonderswan.md index 2ff7ac961..a7ee4d627 100644 --- a/doc/7-systems/wonderswan.md +++ b/doc/7-systems/wonderswan.md @@ -20,6 +20,11 @@ it has 4 wavetable channels. some of them have additional capabilities: - `13xx`: **setup sweep amount.** channel 3 only. - `00` to `7F` for 0 to 127. - `80` to `FF` for -128 to -1. +- `20xx`: **set internal speaker loudness.** + - 0-1: 100% (default). + - 2-3: 200%. + - 4-7: 400%. + - 8: 800%. ## info diff --git a/src/engine/dispatch.h b/src/engine/dispatch.h index 64f9515da..2669f14f0 100644 --- a/src/engine/dispatch.h +++ b/src/engine/dispatch.h @@ -171,8 +171,9 @@ enum DivDispatchCmds { DIV_CMD_X1_010_AUTO_ENVELOPE, DIV_CMD_X1_010_SAMPLE_BANK_SLOT, - DIV_CMD_WS_SWEEP_TIME, - DIV_CMD_WS_SWEEP_AMOUNT, + DIV_CMD_WS_SWEEP_TIME, // (time) + DIV_CMD_WS_SWEEP_AMOUNT, // (value) + DIV_CMD_WS_GLOBAL_SPEAKER_VOLUME, // (multiplier) DIV_CMD_N163_WAVE_POSITION, DIV_CMD_N163_WAVE_LENGTH, diff --git a/src/engine/platform/swan.cpp b/src/engine/platform/swan.cpp index 698afb1bc..e1689c7b5 100644 --- a/src/engine/platform/swan.cpp +++ b/src/engine/platform/swan.cpp @@ -421,6 +421,17 @@ int DivPlatformSwan::dispatch(DivCommand c) { rWrite(0x0c,c.value&0xff); } break; + case DIV_CMD_WS_GLOBAL_SPEAKER_VOLUME: + if (c.value <= 1) { + rWrite(0x11,0x09|(3<<1)); + } else if (c.value <= 3) { + rWrite(0x11,0x09|(2<<1)); + } else if (c.value <= 7) { + rWrite(0x11,0x09|(1<<1)); + } else { + rWrite(0x11,0x09|(0<<1)); + } + break; case DIV_CMD_NOTE_PORTA: { int destFreq=NOTE_PERIODIC(c.value2+chan[c.chan].sampleNoteDelta); bool return2=false; @@ -631,7 +642,7 @@ void DivPlatformSwan::setFlags(const DivConfig& flags) { chipClock=3072000; CHECK_CUSTOM_CLOCK; rate=chipClock/128; - stereo=flags.getBool("stereo",false); + stereo=flags.getBool("stereo",true); for (int i=0; i<4; i++) { oscBuf[i]->setRate(rate); } diff --git a/src/engine/playback.cpp b/src/engine/playback.cpp index 9421702e1..381e24320 100644 --- a/src/engine/playback.cpp +++ b/src/engine/playback.cpp @@ -170,6 +170,7 @@ const char* cmdName[]={ "WS_SWEEP_TIME", "WS_SWEEP_AMOUNT", + "WS_GLOBAL_SPEAKER_VOLUME", "N163_WAVE_POSITION", "N163_WAVE_LENGTH", diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 3ba955d63..d9bf59f94 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1389,6 +1389,9 @@ void DivEngine::registerSystems() { {0x12, {DIV_CMD_WS_SWEEP_TIME, _("12xx: Setup sweep period (0: disabled; 1-20: enabled/period)")}}, {0x13, {DIV_CMD_WS_SWEEP_AMOUNT, _("13xx: Set sweep amount")}}, {0x17, {DIV_CMD_SAMPLE_MODE, _("17xx: Toggle PCM mode (LEGACY)")}}, + }, + { + {0x20, {DIV_CMD_WS_GLOBAL_SPEAKER_VOLUME, _("20xx: Set internal speaker loudness (0-1: 100%, 2-3: 200%, 4-7: 400%, 8: 800%)")}}, } );