@@ -16,6 +16,7 @@ wmsx.OPL4AudioWave = function(opl4) {
1616 rateDecayDurTable = tabs . getRateDecayDurations ( ) ;
1717 envAttackCurve = tabs . getEnvAttackCurve ( ) ;
1818 panpotValues = tabs . getPanPotValues ( ) ;
19+ volumeTable = tabs . getVolumeTable ( ) ;
1920 }
2021
2122 this . connect = function ( machine ) {
@@ -61,17 +62,19 @@ wmsx.OPL4AudioWave = function(opl4) {
6162 wmsx . Util . arrayFill ( dl , 0 ) ;
6263 wmsx . Util . arrayFill ( d2r , 0 ) ;
6364 wmsx . Util . arrayFill ( rr , 0 ) ;
64- wmsx . Util . arrayFill ( volume , 0x7f ) ;
6565 wmsx . Util . arrayFill ( am , 0 ) ;
6666 wmsx . Util . arrayFill ( vib , 0 ) ;
6767 wmsx . Util . arrayFill ( rc , 0 ) ;
68+ wmsx . Util . arrayFill ( volume , 0x7f ) ;
69+ wmsx . Util . arrayFill ( panpotL , 0 ) ;
70+ wmsx . Util . arrayFill ( panpotR , 0 ) ;
6871
6972 // Dynamic values
7073
7174 wmsx . Util . arrayFill ( amAtt , 0 ) ;
72- wmsx . Util . arrayFill ( envAtt , 0x100 << 4 ) ;
73- wmsx . Util . arrayFill ( totalAttL , 0x100 << 4 ) ;
74- wmsx . Util . arrayFill ( totalAttR , 0x100 << 4 ) ;
75+ wmsx . Util . arrayFill ( envAtt , 256 ) ;
76+ wmsx . Util . arrayFill ( totalAttL , 1024 ) ;
77+ wmsx . Util . arrayFill ( totalAttR , 1024 ) ;
7578 wmsx . Util . arrayFill ( envStep , IDLE ) ;
7679 wmsx . Util . arrayFill ( envStepLevelDur , 0 ) ;
7780 wmsx . Util . arrayFill ( envStepLevelIncClock , 0 ) ;
@@ -135,11 +138,11 @@ wmsx.OPL4AudioWave = function(opl4) {
135138
136139 if ( delta > 0 ) {
137140 sample = advanceSample ( cha , delta ) ;
138- sampleL += expTable [ sample + totalAttL [ cha ] ] ;
139- sampleR += expTable [ sample + totalAttR [ cha ] ] ;
141+ sampleL += sample * volumeTable [ totalAttL [ cha ] ] ;
142+ sampleR += sample * volumeTable [ totalAttR [ cha ] ] ;
140143 } else {
141- sampleL += expTable [ sampleValue [ cha ] + totalAttL [ cha ] ] ;
142- sampleR += expTable [ sampleValue [ cha ] + totalAttR [ cha ] ] ;
144+ sampleL += sampleValue [ cha ] * volumeTable [ totalAttL [ cha ] ] ;
145+ sampleR += sampleValue [ cha ] * volumeTable [ totalAttR [ cha ] ] ;
143146 }
144147
145148 // if (delta > 0) sampleL += advanceSample(cha, delta); else sampleL += sampleValue[cha];
@@ -319,15 +322,15 @@ wmsx.OPL4AudioWave = function(opl4) {
319322 function startSample ( cha ) {
320323 samplePos [ cha ] = 0 ;
321324 phaseCounter [ cha ] = 0 ;
322- return updateSampleValue12bitsLog ( cha ) ;
325+ return updateSampleValue16bits ( cha ) ;
323326 }
324327
325328 function advanceSample ( cha , quant ) {
326329 var newPos = samplePos [ cha ] + quant ;
327330 samplePos [ cha ] = newPos > endPosition [ cha ]
328331 ? loopPosition [ cha ] + ( newPos - endPosition [ cha ] ) - 1
329332 : newPos ;
330- return updateSampleValue12bitsLog ( cha ) ;
333+ return updateSampleValue16bits ( cha ) ;
331334 }
332335
333336 function updateSampleValue12bitsLog ( cha ) {
@@ -492,8 +495,8 @@ wmsx.OPL4AudioWave = function(opl4) {
492495 }
493496
494497 function updateTotalAttenuation ( cha ) {
495- totalAttL [ cha ] = amAtt [ cha ] + ( envAtt [ cha ] << 4 ) + ( volume [ cha ] << 4 ) + ( panpotL [ cha ] << 7 ) ;
496- totalAttR [ cha ] = amAtt [ cha ] + ( envAtt [ cha ] << 4 ) + ( volume [ cha ] << 4 ) + ( panpotR [ cha ] << 7 ) ;
498+ totalAttL [ cha ] = amAtt [ cha ] + ( envAtt [ cha ] << 0 ) + ( volume [ cha ] << 0 ) + ( panpotL [ cha ] << 3 ) ;
499+ totalAttR [ cha ] = amAtt [ cha ] + ( envAtt [ cha ] << 0 ) + ( volume [ cha ] << 0 ) + ( panpotR [ cha ] << 3 ) ;
497500 }
498501
499502
@@ -559,7 +562,7 @@ wmsx.OPL4AudioWave = function(opl4) {
559562
560563 // Pre calculated tables, factors, values
561564
562- var linearTable , expTable , vibValues , rateAttackDurTable , rateDecayDurTable , envAttackCurve , panpotValues ;
565+ var volumeTable , linearTable , expTable , vibValues , rateAttackDurTable , rateDecayDurTable , envAttackCurve , panpotValues ;
563566 var sampleResult = [ 0 , 0 ] ;
564567
565568
0 commit comments