Skip to content

Commit e2ecbc3

Browse files
authored
update to go 1.24, fix OPL voice playback (#15)
* update to go 1.24, fix opl voice playback * update opl2 module to 1.0.2
1 parent 23076fe commit e2ecbc3

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

format/s3m/voice/voice.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,26 @@ func (v *s3mVoice) Setup(inst *instrument.Instrument[period.Amiga, s3mVolume.Fin
150150
return err
151151
}
152152

153+
// Build OPL2 register set from instrument definition.
154+
instOPL := d
155+
v.opl2 = component.OPL2Registers{
156+
Mod: component.OPL2Operator{
157+
Reg20: instOPL.Modulator.GetReg20(),
158+
Reg40: instOPL.Modulator.GetReg40(),
159+
Reg60: instOPL.Modulator.GetReg60(),
160+
Reg80: instOPL.Modulator.GetReg80(),
161+
RegE0: instOPL.Modulator.GetRegE0(),
162+
},
163+
Car: component.OPL2Operator{
164+
Reg20: instOPL.Carrier.GetReg20(),
165+
Reg40: instOPL.Carrier.GetReg40(),
166+
Reg60: instOPL.Carrier.GetReg60(),
167+
Reg80: instOPL.Carrier.GetReg80(),
168+
RegE0: instOPL.Carrier.GetRegE0(),
169+
},
170+
RegC0: instOPL.GetRegC0(),
171+
}
172+
153173
var o component.OPL2[period.Amiga, s3mVolume.FineVolume, s3mVolume.Volume]
154174
o.Setup(v.opl2Chip, int(v.opl2Channel), v.opl2, s3mPeriod.S3MAmigaConverter, s3mSystem.DefaultC4SampleRate, inst.GetDefaultVolume())
155175
v.voicer = &o

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/gotracker/playback
22

3-
go 1.21
3+
go 1.24.0
44

55
require (
66
github.com/gotracker/goaudiofile v1.0.16
7-
github.com/gotracker/opl2 v1.0.1
7+
github.com/gotracker/opl2 v1.0.2
88
github.com/heucuva/comparison v1.0.0
99
github.com/heucuva/optional v0.0.1
10-
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f
10+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9
1111
)

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
github.com/gotracker/goaudiofile v1.0.16 h1:+QlrDbZluWs01NZdg3JOuM+Zm98o1NNFVbtts2Fkw2M=
22
github.com/gotracker/goaudiofile v1.0.16/go.mod h1:mX/CjpkoClUFrGQ8MU6x2hm4ma/ClQTh83wwHhLC7RY=
3-
github.com/gotracker/opl2 v1.0.1 h1:1PVNs0dXqEAQxdws7fz2WEE3nSKkMb1osTTT7KgEi5g=
4-
github.com/gotracker/opl2 v1.0.1/go.mod h1:lW1WbZlh7svEMpurp9LLYWSyf1WPAb750cQ7xGIhCnY=
3+
github.com/gotracker/opl2 v1.0.2 h1:G1KaUAbl+3Khwq++1L+Bs55Iep1AimhCmGFs5hJOBOU=
4+
github.com/gotracker/opl2 v1.0.2/go.mod h1:lW1WbZlh7svEMpurp9LLYWSyf1WPAb750cQ7xGIhCnY=
55
github.com/heucuva/comparison v1.0.0 h1:xxXNKS9GKHetQavOz35FitlAXWvmvM3U6M5IRIw7kN8=
66
github.com/heucuva/comparison v1.0.0/go.mod h1:5l0Va1uxFyy7S4DgdflnayxV2HStFwWI2rzbrlNNNMk=
77
github.com/heucuva/optional v0.0.1 h1:tLbVBMQBKzQVfe43bHQFSxjhTzYcRK8frnTBG6FLksM=
88
github.com/heucuva/optional v0.0.1/go.mod h1:2AtE/X9279wzrHLkCNvKl0xP7AiEIj3RijGKwbO8R3M=
99
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
1010
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
11-
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f h1:3CW0unweImhOzd5FmYuRsD4Y4oQFKZIjAnKbjV4WIrw=
12-
golang.org/x/exp v0.0.0-20240314144324-c7f7c6466f7f/go.mod h1:CxmFvTBINI24O/j8iY7H1xHzx2i4OsyguNBmN/uPtqc=
11+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 h1:MDfG8Cvcqlt9XXrmEiD4epKn7VJHZO84hejP9Jmp0MM=
12+
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
1313
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
1414
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

voice/component/opl2.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,20 @@ func (o *OPL2[TPeriod, TMixingVolume, TVolume]) calc40(reg40 uint8, vol volume.V
171171
}
172172

173173
func (o *OPL2[TPeriod, TMixingVolume, TVolume]) periodToFreqBlock(p TPeriod, baseFreq frequency.Frequency) (uint16, uint8) {
174-
modFreq := o.periodConverter.GetFrequency(p)
175-
freq := float64(baseFreq) * float64(modFreq) / 261625
176-
174+
// The period converter can return either an absolute frequency (Hz) or a
175+
// relative multiplier, depending on the converter implementation. For the
176+
// legacy OPL path, absolute frequencies need to be scaled down to the
177+
// expected OPL range (mirroring dbopl): baseFreq * freq / 261625.
178+
modFreq := float64(o.periodConverter.GetFrequency(p))
179+
var freq float64
180+
if modFreq > 200 { // treat as absolute Hz (Amiga-style converters)
181+
freq = float64(baseFreq) * modFreq / 261625.0
182+
} else { // treat as a ratio/multiplier (Linear-style converters)
183+
freq = modFreq * float64(baseFreq)
184+
}
185+
if freq <= 0 {
186+
return 0, 0
187+
}
177188
return o.freqToFnumBlock(freq)
178189
}
179190

0 commit comments

Comments
 (0)