Repository navigation
Commit 1bcdfb3
GENS: the phase a channel update works with wraps as well
The patch that made Fcnt unsigned left the int that GET_CURRENT_PHASE() copies it into, on the grounds that the phase is only shifted and masked there. That is true of the phase as it arrives, but not of what the channel update does with it: modulation adds one operator's output to the next one's phase, and that addition overflows the same way the counter did.
src/chips/gens/Ym2612.cpp:1424:5: runtime error: signed integer overflow: -2146769536 + -2312044 cannot be represented in type 'int'
The four in0..in3 of T_Update_Chan(), T_Update_Chan_LFO(), T_Update_Chan_Int() and T_Update_Chan_LFO_Int() are that phase, and they are unsigned now, as Fcnt is. Every use of them is the same as before: they are set from Fcnt, added to in DO_FEEDBACK() and in the algorithm macros, and read as (in >> SIN_LBITS) & SIN_MASK, which takes bits 14 to 25 -- the bits an arithmetic shift and a logical shift agree on, since the mask is twelve bits wide. Copying Fcnt into an int was also a conversion that the standard leaves to the implementation once the counter had gone past INT_MAX, and that goes away too.
A fuzz target of ADLplug-Next found it, one that plays MIDI through the real-time API with the chip settings a saved project can hold: the emulator GENS, two chips, the LFO on, and a note of 104 at velocity 11, which the daily run came upon in a quarter of an hour.1 parent be1b2fe commit 1bcdfb3
1 file changed
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1195 | 1195 | | |
1196 | 1196 | | |
1197 | 1197 | | |
1198 | | - | |
| 1198 | + | |
1199 | 1199 | | |
1200 | 1200 | | |
1201 | 1201 | | |
| |||
1263 | 1263 | | |
1264 | 1264 | | |
1265 | 1265 | | |
1266 | | - | |
| 1266 | + | |
1267 | 1267 | | |
1268 | 1268 | | |
1269 | 1269 | | |
| |||
1335 | 1335 | | |
1336 | 1336 | | |
1337 | 1337 | | |
1338 | | - | |
| 1338 | + | |
1339 | 1339 | | |
1340 | 1340 | | |
1341 | 1341 | | |
| |||
1404 | 1404 | | |
1405 | 1405 | | |
1406 | 1406 | | |
1407 | | - | |
| 1407 | + | |
1408 | 1408 | | |
1409 | 1409 | | |
1410 | 1410 | | |
| |||
0 commit comments