diff options
author | JP Cimalando <jpcima@users.noreply.github.com> | 2019-02-24 00:41:22 +0100 |
---|---|---|
committer | JP Cimalando <jpcima@users.noreply.github.com> | 2019-02-24 00:41:22 +0100 |
commit | e587395a064d19f894c5295e1d97af4d2fb87ea7 (patch) | |
tree | 171d9f1be24c5b382a8139b494a77e907209b8d4 | |
parent | c903e6df7b3dde7de714311360130a3d0219d873 (diff) | |
download | libADLMIDI-e587395a064d19f894c5295e1d97af4d2fb87ea7.tar.gz libADLMIDI-e587395a064d19f894c5295e1d97af4d2fb87ea7.tar.bz2 libADLMIDI-e587395a064d19f894c5295e1d97af4d2fb87ea7.zip |
java: output volume and panning
-rw-r--r-- | src/chips/java/JavaOPL3.hpp (renamed from src/chips/java/OPL3.cpp) | 0 | ||||
-rw-r--r-- | src/chips/java_opl3.cpp | 24 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/chips/java/OPL3.cpp b/src/chips/java/JavaOPL3.hpp index 9a4469b..9a4469b 100644 --- a/src/chips/java/OPL3.cpp +++ b/src/chips/java/JavaOPL3.hpp diff --git a/src/chips/java_opl3.cpp b/src/chips/java_opl3.cpp index ebf7899..d35c023 100644 --- a/src/chips/java_opl3.cpp +++ b/src/chips/java_opl3.cpp @@ -19,7 +19,14 @@ */ #include "java_opl3.h" -#include "java/OPL3.cpp" +#include "java/JavaOPL3.hpp" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#ifndef M_SQRT1_2 +# define M_SQRT1_2 0.70710678118654752440 +#endif JavaOPL3::JavaOPL3() : OPLChipBaseBufferedT(), @@ -39,6 +46,10 @@ void JavaOPL3::setRate(uint32_t rate) OPLChipBaseBufferedT::setRate(rate); JavaOPL::OPL3 *chip_r = reinterpret_cast<JavaOPL::OPL3 *>(m_chip); chip_r->Reset(); + + float pan = sinf(M_SQRT1_2); + for (unsigned channel = 0; channel < 18; ++channel) + chip_r->SetPanning(channel, pan, pan); } void JavaOPL3::reset() @@ -57,7 +68,14 @@ void JavaOPL3::writeReg(uint16_t addr, uint8_t data) void JavaOPL3::writePan(uint16_t addr, uint8_t data) { JavaOPL::OPL3 *chip_r = reinterpret_cast<JavaOPL::OPL3 *>(m_chip); - // TODO panning + + unsigned high = (addr >> 8) & 0x01; + unsigned regm = addr & 0xff; + unsigned channel = 9 * high + (regm & 0x0f); + + float phase = (data == 63 || data == 64) ? 63.5f : (float)data; + phase *= (float)(M_PI / 2 / 127); + chip_r->SetPanning(channel, sinf(phase), cosf(phase)); } void JavaOPL3::nativeGenerateN(int16_t *output, size_t frames) @@ -77,7 +95,7 @@ void JavaOPL3::nativeGenerateN(int16_t *output, size_t frames) size_t cursamples = 2 * curframes; for(size_t i = 0; i < cursamples; ++i) { - int32_t sample = (int32_t)lround(32768 * buf[i]); + int32_t sample = (int32_t)lround(4096 * buf[i]); sample = (sample > -32768) ? sample : -32768; sample = (sample < +32767) ? sample : +32767; output[i] = (int16_t)sample; |