diff options
author | Filippos Karapetis | 2013-01-02 12:41:14 +0200 |
---|---|---|
committer | Filippos Karapetis | 2013-01-02 12:42:54 +0200 |
commit | 98ec26754329b13170e045c7aa34915be8be4758 (patch) | |
tree | c5f684c253c96c2b74ad33b9c75e084782bf02bc /audio/softsynth | |
parent | 5c44f3e95351d8ab7cb4a041b701da814ff77fea (diff) | |
download | scummvm-rg350-98ec26754329b13170e045c7aa34915be8be4758.tar.gz scummvm-rg350-98ec26754329b13170e045c7aa34915be8be4758.tar.bz2 scummvm-rg350-98ec26754329b13170e045c7aa34915be8be4758.zip |
MT-32: Sync with the latest changes in munt
This syncs our code with munt commits 3f0db2d and 2c5f314
Diffstat (limited to 'audio/softsynth')
-rw-r--r-- | audio/softsynth/mt32/Partial.cpp | 25 | ||||
-rw-r--r-- | audio/softsynth/mt32/Tables.cpp | 12 | ||||
-rw-r--r-- | audio/softsynth/mt32/Tables.h | 2 |
3 files changed, 16 insertions, 23 deletions
diff --git a/audio/softsynth/mt32/Partial.cpp b/audio/softsynth/mt32/Partial.cpp index 58878a3513..a4d1ab03fa 100644 --- a/audio/softsynth/mt32/Partial.cpp +++ b/audio/softsynth/mt32/Partial.cpp @@ -284,8 +284,12 @@ unsigned long Partial::generateSamples(float *partialBuf, unsigned long length) // res corresponds to a value set in an LA32 register Bit8u res = patchCache->srcPartial.tvf.resonance + 1; - // Using tiny exact table for computation of EXP2F(1.0f - (32 - res) / 4.0f) - float resAmp = tables.resAmpMax[res]; + float resAmp; + { + // resAmp = EXP2F(1.0f - (32 - res) / 4.0f); + static const float resAmpFactor = EXP2F(-7); + resAmp = EXP2I(res << 10) * resAmpFactor; + } // The cutoffModifier may not be supposed to be directly added to the cutoff - // it may for example need to be multiplied in some way. @@ -317,23 +321,26 @@ unsigned long Partial::generateSamples(float *partialBuf, unsigned long length) relWavePos -= waveLen; } + // Ratio of positive segment to wave length float pulseLen = 0.5f; if (pulseWidthVal > 128) { - pulseLen += tables.pulseLenFactor[pulseWidthVal - 128]; + // pulseLen = EXP2F((64 - pulseWidthVal) / 64); + static const float pulseLenFactor = EXP2F(-192 / 64); + pulseLen = EXP2I((256 - pulseWidthVal) << 6) * pulseLenFactor; } pulseLen *= waveLen; - float lLen = pulseLen - cosineLen; + float hLen = pulseLen - cosineLen; // Ignore pulsewidths too high for given freq - if (lLen < 0.0f) { - lLen = 0.0f; + if (hLen < 0.0f) { + hLen = 0.0f; } // Ignore pulsewidths too high for given freq and cutoff - float hLen = waveLen - lLen - 2 * cosineLen; - if (hLen < 0.0f) { - hLen = 0.0f; + float lLen = waveLen - hLen - 2 * cosineLen; + if (lLen < 0.0f) { + lLen = 0.0f; } // Correct resAmp for cutoff in range 50..66 diff --git a/audio/softsynth/mt32/Tables.cpp b/audio/softsynth/mt32/Tables.cpp index b6e63840bc..5353a74079 100644 --- a/audio/softsynth/mt32/Tables.cpp +++ b/audio/softsynth/mt32/Tables.cpp @@ -72,24 +72,12 @@ Tables::Tables() { //synth->printDebug("%d: %d", i, pulseWidth100To255[i]); } - // Ratio of negative segment to wave length - for (int i = 0; i < 128; i++) { - // Formula determined from sample analysis. - float pt = 0.5f / 127.0f * i; - pulseLenFactor[i] = (1.241857812f - pt) * pt; // seems to be 2 ^ (5 / 16) = 1.241857812f - } - // The LA32 chip presumably has such a table inside as the internal computaions seem to be performed using fixed point math with 12-bit fractions for (int i = 0; i < 4096; i++) { exp2[i] = EXP2F(i / 4096.0f); } // found from sample analysis - for (int i = 0; i < 32; i++) { - resAmpMax[i] = EXP2F(1.0f - (32 - i) / 4.0f); - } - - // found from sample analysis resAmpFadeFactor[7] = 1.0f / 8.0f; resAmpFadeFactor[6] = 2.0f / 8.0f; resAmpFadeFactor[5] = 3.0f / 8.0f; diff --git a/audio/softsynth/mt32/Tables.h b/audio/softsynth/mt32/Tables.h index b353cf4c51..c3e80e7e9b 100644 --- a/audio/softsynth/mt32/Tables.h +++ b/audio/softsynth/mt32/Tables.h @@ -57,8 +57,6 @@ public: Bit8u pulseWidth100To255[101]; float exp2[4096]; - float pulseLenFactor[128]; - float resAmpMax[32]; float resAmpFadeFactor[8]; float sinf10[5120]; }; |