Skip to content

Commit 9cbdc1a

Browse files
committed
OPL4 WIP
1 parent 75389ed commit 9cbdc1a

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/main/msx/audio/OPL4Audio.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ wmsx.OPL4Audio = function(pName, cart) {
8989

9090
var audioSocket, audioSignal;
9191

92-
var VOLUME = 0.85 * (3 / 24 / 4096); // X channels, samples -4096 .. +4096
92+
var VOLUME = 0.65 * (7 / 24 / 4096); // X channels, samples -4096 .. +4096
9393
var SAMPLE_RATE = 44100; // Main CPU clock / 81.2734693877551 = 44100 Hz
9494
var CLOCK = 49780; // Main CPU clock / 72 = 49780 Hz
9595

src/main/msx/audio/OPL4AudioWave.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ wmsx.OPL4AudioWave = function(opl4) {
1515
kslValues = tabs.getKSLValues();
1616
rateAttackDurTable = tabs.getRateAttackDurations();
1717
rateDecayDurTable = tabs.getRateDecayDurations();
18+
envAttackCurve = tabs.getEnvAttackCurve();
1819
}
1920

2021
this.connect = function(machine) {
@@ -60,24 +61,24 @@ wmsx.OPL4AudioWave = function(opl4) {
6061
wmsx.Util.arrayFill(dl, 0);
6162
wmsx.Util.arrayFill(d2r, 0);
6263
wmsx.Util.arrayFill(rr, 0);
63-
wmsx.Util.arrayFill(volume, 0);
64+
wmsx.Util.arrayFill(volume, 0x7f);
6465
wmsx.Util.arrayFill(am, 0);
6566
wmsx.Util.arrayFill(vib, 0);
6667
wmsx.Util.arrayFill(rc, 0);
6768

6869
// Dynamic values
6970

70-
wmsx.Util.arrayFill(volumeAtt, 0);
71+
wmsx.Util.arrayFill(volumeAtt, 0x7f << 4);
7172
wmsx.Util.arrayFill(amAtt, 0);
72-
wmsx.Util.arrayFill(envAtt, 0);
73-
wmsx.Util.arrayFill(totalAtt, 0);
73+
wmsx.Util.arrayFill(envAtt, 0x100 << 4);
74+
wmsx.Util.arrayFill(totalAtt, 0x100 << 4);
7475
wmsx.Util.arrayFill(envStep, IDLE);
7576
wmsx.Util.arrayFill(envStepLevelDur, 0);
7677
wmsx.Util.arrayFill(envStepLevelIncClock, 0);
7778
wmsx.Util.arrayFill(envStepLevelInc, 0);
7879
wmsx.Util.arrayFill(envStepNext, IDLE);
7980
wmsx.Util.arrayFill(envStepNextAtLevel, 0);
80-
wmsx.Util.arrayFill(envLevel, 0);
81+
wmsx.Util.arrayFill(envLevel, 256);
8182
wmsx.Util.arrayFill(rcOffset, 0);
8283
};
8384

@@ -449,7 +450,7 @@ wmsx.OPL4AudioWave = function(opl4) {
449450
envLevel[cha] = 256;
450451
envStepLevelIncClock[cha] = envStepLevelDur[cha] = 0; // Never
451452
envStepLevelInc[cha] = 0;
452-
envStepNextAtLevel[cha] = 255; // Never
453+
envStepNextAtLevel[cha] = 257; // Never
453454
envStepNext[cha] = IDLE;
454455
break;
455456
}
@@ -476,14 +477,12 @@ wmsx.OPL4AudioWave = function(opl4) {
476477
}
477478

478479
function updateEnvAttenuation(cha) {
479-
envAtt[cha] = envLevel[cha] << 4;
480-
// envAtt[cha] = (envLevel[cha] === 128 ? 256 : envLevel[cha]) << 5; // Higher attenuation in case of minimum level to produce silence
480+
envAtt[cha] = (envStep[cha] === ATTACK ? envAttackCurve[envLevel[cha]] : envLevel[cha]) << 4;
481481
updateTotalAttenuation(cha);
482482
}
483483

484484
function updateVolumeAttenuation(cha) {
485485
volumeAtt[cha] = volume[cha] << 4;
486-
// volumeAtt[cha] = (volume[cha] === 15 ? 30 : volume[cha]) << 7; // Higher attenuation in case of minimum volume to produce silence
487486
updateTotalAttenuation(cha);
488487
}
489488

@@ -555,7 +554,7 @@ wmsx.OPL4AudioWave = function(opl4) {
555554

556555
// Pre calculated tables, factors, values
557556

558-
var linearTable, expTable, vibValues, kslValues, rateAttackDurTable, rateDecayDurTable;
557+
var linearTable, expTable, vibValues, kslValues, rateAttackDurTable, rateDecayDurTable, envAttackCurve;
559558

560559

561560
// Savestate -------------------------------------------

src/main/msx/audio/OPL4WaveTables.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
wmsx.OPL4WaveTables = function() {
44
"use strict";
55

6+
this.getEnvAttackCurve = function() {
7+
var tab = new Array(257);
8+
tab[0] = 0;
9+
tab[256] = 256;
10+
for (var i = 1; i < 256; ++i)
11+
tab[i] = 256 - Math.floor((Math.log(((256 - i)/256) + 0.0188) / 4 + 0.995) * 256);
12+
return tab;
13+
};
14+
15+
616
this.getLinearTable12Bits = function() {
717
// Complete table for all possible values (4096 entries). -255 .. 255 values, sign in bit 14
818
var tab = new Array(4096);
@@ -34,7 +44,7 @@ wmsx.OPL4WaveTables = function() {
3444
var tab = new Array(76);
3545
for (var i = 0; i < 64; ++i) {
3646
var dur = this.RATE_ATTACK_DURATIONS[i];
37-
tab[i] = dur >= 0 ? Math.max(1, Math.round(dur / 10 / 1000 * 49780 / 256)) : 0; // Valid Durations are at least 1 clock. 0 = infinite
47+
tab[i] = dur >= 0 ? Math.max(1, Math.round(dur / 1000 * 49780 / 256)) : 0; // Valid Durations are at least 1 clock. 0 = infinite
3848
}
3949
// Repeat last value for exceeding rates (> 63), possible when Rate = 15 and KSR offset > 3, as (Rate x 4 + KSROffset) can be > 63!
4050
for (i = 64; i < 60 + 16; ++i)

0 commit comments

Comments
 (0)