aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/mt32/LA32WaveGenerator.cpp
diff options
context:
space:
mode:
authorColin Snover2016-11-24 09:24:00 -0600
committerColin Snover2016-12-16 15:44:29 -0600
commitb8d70d26faea1ed71b0176326c97859b31afb8ef (patch)
tree89b7cff8de9359e5a7877ac0e4bc6b4212e861f3 /audio/softsynth/mt32/LA32WaveGenerator.cpp
parentffea222f5bfda8383cb52480b48998c9d0093911 (diff)
downloadscummvm-rg350-b8d70d26faea1ed71b0176326c97859b31afb8ef.tar.gz
scummvm-rg350-b8d70d26faea1ed71b0176326c97859b31afb8ef.tar.bz2
scummvm-rg350-b8d70d26faea1ed71b0176326c97859b31afb8ef.zip
MT32: Update Munt to 2.0.1-pre
This update uses upstream commit f88ef828a600ce66d1f730c8fb2a7f580f6f6165. This update switches to use the new Munt C++ interface, which will allow ScummVM to link to an external Munt library instead of requiring it to be built-in in the future. For the moment, the emulator is still built-in, since it is not available from most package repositories. The Munt driver in ScummVM now uses writeSysex instead of the (now-private) playSysexWithoutFraming, per recommendation from the Munt team <https://github.com/munt/munt/pull/30>. This changeset also removes direct modifications that used to be made to Munt code, to ease future updates. To update Munt code in the future: 1. Replace all source files in the `softsynth/mt32` directory with new files from the upstream `mt32emu/src` directory; 2. Update `config.h` with the correct version number for the new version of Munt; 3. Update `module.mk` to add any new source files that need to be built.
Diffstat (limited to 'audio/softsynth/mt32/LA32WaveGenerator.cpp')
-rwxr-xr-x[-rw-r--r--]audio/softsynth/mt32/LA32WaveGenerator.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/audio/softsynth/mt32/LA32WaveGenerator.cpp b/audio/softsynth/mt32/LA32WaveGenerator.cpp
index 765f75fa61..a9c425beac 100644..100755
--- a/audio/softsynth/mt32/LA32WaveGenerator.cpp
+++ b/audio/softsynth/mt32/LA32WaveGenerator.cpp
@@ -1,5 +1,5 @@
/* Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Dean Beeler, Jerome Fisher
- * Copyright (C) 2011, 2012, 2013, 2014 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
+ * Copyright (C) 2011-2016 Dean Beeler, Jerome Fisher, Sergey V. Mikayev
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -15,15 +15,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <cstddef>
+
+#include "internals.h"
+
+#include "LA32WaveGenerator.h"
+#include "Tables.h"
+
#if MT32EMU_USE_FLOAT_SAMPLES
+#define MT32EMU_LA32_WAVE_GENERATOR_CPP
#include "LA32FloatWaveGenerator.cpp"
+#undef MT32EMU_LA32_WAVE_GENERATOR_CPP
#else
-//#include <cmath>
-#include "mt32emu.h"
-#include "mmath.h"
-#include "internals.h"
-
namespace MT32Emu {
static const Bit32u SINE_SEGMENT_RELATIVE_LENGTH = 1 << 18;
@@ -50,7 +54,7 @@ Bit16s LA32Utilites::unlog(const LogSample &logSample) {
void LA32Utilites::addLogSamples(LogSample &logSample1, const LogSample &logSample2) {
Bit32u logSampleValue = logSample1.logValue + logSample2.logValue;
- logSample1.logValue = logSampleValue < 65536 ? (Bit16u)logSampleValue : 65535;
+ logSample1.logValue = logSampleValue < 65536 ? Bit16u(logSampleValue) : 65535;
logSample1.sign = logSample1.sign == logSample2.sign ? LogSample::POSITIVE : LogSample::NEGATIVE;
}
@@ -130,9 +134,7 @@ void LA32WaveGenerator::advancePosition() {
Bit32u lowLinearLength = (resonanceWaveLengthFactor << 8) - 4 * SINE_SEGMENT_RELATIVE_LENGTH - highLinearLength;
computePositions(highLinearLength, lowLinearLength, resonanceWaveLengthFactor);
- // resonancePhase computation hack
- int *resonancePhaseAlias = (int *)&resonancePhase;
- *resonancePhaseAlias = ((resonanceSinePosition >> 18) + (phase > POSITIVE_FALLING_SINE_SEGMENT ? 2 : 0)) & 3;
+ resonancePhase = ResonancePhase(((resonanceSinePosition >> 18) + (phase > POSITIVE_FALLING_SINE_SEGMENT ? 2 : 0)) & 3);
}
void LA32WaveGenerator::generateNextSquareWaveLogSample() {
@@ -158,7 +160,7 @@ void LA32WaveGenerator::generateNextSquareWaveLogSample() {
logSampleValue += (MIDDLE_CUTOFF_VALUE - cutoffVal) >> 9;
}
- squareLogSample.logValue = logSampleValue < 65536 ? (Bit16u)logSampleValue : 65535;
+ squareLogSample.logValue = logSampleValue < 65536 ? Bit16u(logSampleValue) : 65535;
squareLogSample.sign = phase < NEGATIVE_FALLING_SINE_SEGMENT ? LogSample::POSITIVE : LogSample::NEGATIVE;
}
@@ -198,7 +200,7 @@ void LA32WaveGenerator::generateNextResonanceWaveLogSample() {
// After all the amp decrements are added, it should be safe now to adjust the amp of the resonance wave to what we see on captures
logSampleValue -= 1 << 12;
- resonanceLogSample.logValue = logSampleValue < 65536 ? (Bit16u)logSampleValue : 65535;
+ resonanceLogSample.logValue = logSampleValue < 65536 ? Bit16u(logSampleValue) : 65535;
resonanceLogSample.sign = resonancePhase < NEGATIVE_FALLING_RESONANCE_SINE_SEGMENT ? LogSample::POSITIVE : LogSample::NEGATIVE;
}
@@ -216,7 +218,7 @@ void LA32WaveGenerator::generateNextSawtoothCosineLogSample(LogSample &logSample
void LA32WaveGenerator::pcmSampleToLogSample(LogSample &logSample, const Bit16s pcmSample) const {
Bit32u logSampleValue = (32787 - (pcmSample & 32767)) << 1;
logSampleValue += amp >> 10;
- logSample.logValue = logSampleValue < 65536 ? (Bit16u)logSampleValue : 65535;
+ logSample.logValue = logSampleValue < 65536 ? Bit16u(logSampleValue) : 65535;
logSample.sign = pcmSample < 0 ? LogSample::NEGATIVE : LogSample::POSITIVE;
}
@@ -377,7 +379,7 @@ Bit16s LA32PartialPair::unlogAndMixWGOutput(const LA32WaveGenerator &wg) {
Bit16s firstSample = LA32Utilites::unlog(wg.getOutputLogSample(true));
Bit16s secondSample = LA32Utilites::unlog(wg.getOutputLogSample(false));
if (wg.isPCMWave()) {
- return Bit16s(firstSample + ((Bit32s(secondSample - firstSample) * wg.getPCMInterpolationFactor()) >> 7));
+ return Bit16s(firstSample + (((Bit32s(secondSample) - Bit32s(firstSample)) * wg.getPCMInterpolationFactor()) >> 7));
}
return firstSample + secondSample;
}
@@ -407,7 +409,7 @@ Bit16s LA32PartialPair::nextOutSample() {
Bit16s slaveSample = slave.isPCMWave() ? LA32Utilites::unlog(slave.getOutputLogSample(true)) : unlogAndMixWGOutput(slave);
slaveSample <<= 2;
slaveSample >>= 2;
- Bit16s ringModulatedSample = Bit16s(((Bit32s)masterSample * (Bit32s)slaveSample) >> 13);
+ Bit16s ringModulatedSample = Bit16s((Bit32s(masterSample) * Bit32s(slaveSample)) >> 13);
return mixed ? nonOverdrivenMasterSample + ringModulatedSample : ringModulatedSample;
}
@@ -423,6 +425,6 @@ bool LA32PartialPair::isActive(const PairType useMaster) const {
return useMaster == MASTER ? master.isActive() : slave.isActive();
}
-}
+} // namespace MT32Emu
#endif // #if MT32EMU_USE_FLOAT_SAMPLES