joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.59k stars 376 forks source link

All audio in Impulse Tracker is playing back at a incorrect rate/pitched down #3333

Closed KynikossDragonn closed 1 year ago

KynikossDragonn commented 2 years ago

Code of Conduct & Contributing Guidelines

Have you checked that no other similar bug report(s) already exists?

What operating system(s) this bug have occurred on?

Void Linux x86_64 (Linux Kernel 5.15.28)

What version(s) of DOSBox-X have this bug?

0.83.24 SDL2 x86_64 commit 05ed306681e212121ba211c45c1e404804ce8a36

Describe the bug

In Impulse Tracker using Sound Blaster 16 (it doesn't matter if you use the regular driver or the MMX driver) the audio is played back at a incorrect pitch, almost like the sample rate is wrong.

IT reports the mixing rate is 45454 Hz. But, the audio sounds 25% slower.

I've tested the normal, dynamic_x86 and dynamic_rec cores and machine type pentium and pentium_mmx, audio sounds slow regardless of these settings.

cputype=pentium_mmx is required for ITSB16.MMX driver.

This problem doesn't occur in mainline DOSBox 0.74.3 however.

Expected behavior

Audio shouldn't sound slowed down as if the audio sample rate is mismatched between IT and the SB16 emulation.

Steps to reproduce the behaviour

  1. Download the official "it214v5.zip" and extract it somewhere.
  2. Set cputype=pentium_mmx to allow using the MMX driver.
  3. Start IT either without switches or with /sITSB16.MMX to load the MMX code.
  4. Hit SHIFT-F5 to change driver operating modes. (enable filters in the MMX driver for example)
  5. Hit F9 to load a module, any of the modules that come with Impulse Tracker will do.
  6. Attempt playback with F5.

Used configuration

[sdl]
fullscreen        = false
fulldouble        = false
fullresolution    = desktop
windowresolution  = original
windowposition    = 
display           = 0
output            = openglnb
videodriver       = 
transparency      = 0
maximize          = false
autolock          = false
autolock_feedback = beep
middle_unlock     = none
clip_mouse_button = right
clip_key_modifier = shift
clip_paste_bios   = default
clip_paste_speed  = 30
sensitivity       = 100
usesystemcursor   = false
mouse_emulation   = locked
mouse_wheel_key   = -1
waitonerror       = true
priority          = normal,normal
mapperfile        = mapper-dosbox-x.map
usescancodes      = auto
overscan          = 0
titlebar          = 
showbasic         = false
showdetails       = false
showmenu          = false

[log]
logfile     = 
debuggerrun = debugger

[dosbox]
language                  = 
title                     = 
fastbioslogo              = true
startbanner               = false
bannercolortheme          = default
dpi aware                 = true
quit warning              = auto
working directory option  = custom
working directory default = /home/kynikos/dosbox-x
show advanced options     = false
resolve config path       = true
hostkey                   = mapper
mapper send key           = ctrlaltdel
ime                       = auto
synchronize time          = false
machine                   = vgaonly
captures                  = capture
autosave                  = 
saveslot                  = 1
savefile                  = 
saveremark                = true
forceloadstate            = false
a20                       = mask
memsize                   = 63
nocachedir                = false
freesizecap               = cap

[render]
frameskip      = 0
aspect         = false
char9          = true
euro           = -1
doublescan     = true
scaler         = none
glshader       = none
pixelshader    = none
autofit        = false
monochrome_pal = green

[pc98]
pc-98 BIOS copyright string     = false
pc-98 fm board                  = auto
pc-98 enable 256-color          = true
pc-98 enable 16-color           = true
pc-98 enable grcg               = true
pc-98 enable egc                = true
pc-98 bus mouse                 = true
pc-98 force ibm keyboard layout = auto
pc-98 try font rom              = true
pc-98 anex86 font               = 

[dosv]
dosv             = off
getsysfont       = true
fontxsbcs        = 
fontxsbcs16      = 
fontxsbcs24      = 
fontxdbcs        = 
fontxdbcs14      = 
fontxdbcs24      = 
showdbcsnodosv   = auto
yen              = false
del              = true
fepcontrol       = both
vtext1           = svga
vtext2           = xga
use20pixelfont   = false
j3100            = off
j3100type        = default
j3100colorscroll = false

[video]
vmemsize                = 8
vmemsizekb              = 0
high intensity blinking = true

[vsync]
vsyncmode = on
vsyncrate = 60

[cpu]
core           = dynamic_x86
fpu            = true
segment limits = true
cputype         = pentium_mmx
cycles         = max 105%
cycleup        = 100
cycledown      = 100
turbo          = true
apmbios        = true
isapnpbios     = true

[keyboard]
aux                     = true
allow output port reset = true
controllertype          = auto
auxdevice               = intellimouse

[ttf]
font         = 
fontbold     = 
fontital     = 
fontboit     = 
colors       = 
outputswitch = auto
winperc      = 60
ptsize       = 0
lins         = 0
cols         = 0
righttoleft  = false
wp           = 
bold         = true
italic       = true
underline    = true
strikeout    = false
printfont    = true
autodbcs     = true
blinkc       = true
gbk          = false
chinasea     = false
dosvfunc     = false

[voodoo]
voodoo_card   = false
voodoo_maxmem = true
glide         = false
lfb           = full_noaux
splash        = true

[mixer]
nosound         = false
sample accurate = true
swapstereo      = false
rate            = 48000
blocksize       = 1024
prebuffer       = 0

[midi]
mpu401          = none
mpubase         = 0
mididevice      = none
midiconfig      = 
samplerate      = 48000
mpuirq          = -1
mt32.romdir     = /home/kynikos/muntstatic
mt32.model      = cm32l
fluid.driver    = default
fluid.soundfont = 

[sblaster]
sbtype                       = sb16
sbbase                       = 220
irq                          = 7
dma                          = 1
hdma                         = 5
enable speaker               = false
sbmixer                      = true
oplmode                      = none
oplemu                       = nuked
oplrate                      = 48000
oplport                      = 
retrowave_bus                = serial
retrowave_port               = 
hardwarebase                 = 220
goldplay                     = false
blaster environment variable = true

[gus]
gus               = false
gusrate           = 48000
gusmemsize        = -1
gus master volume = 0.00
gusbase           = 240
gusirq            = 5
gusdma            = 3
gustype           = classic
ultradir          = C:\ULTRASND

[innova]
innova     = false
samplerate = 48000
sidbase    = 280
quality    = 0

[speaker]
pcspeaker    = false
pcrate       = 48000
tandy        = off
tandyrate    = 48000
disney       = false
ps1audio     = off
ps1audiorate = 48000

[joystick]
joysticktype = none
timed        = false
autofire     = false
swap34       = false
buttonwrap   = false

[mapper]
joy1deadzone0- = 0.60
joy1deadzone0+ = 0.60
joy1deadzone1- = 0.60
joy1deadzone1+ = 0.60
joy1deadzone2- = 0.60
joy1deadzone2+ = 0.60
joy1deadzone3- = 0.60
joy1deadzone3+ = 0.60
joy1deadzone4- = 0.60
joy1deadzone4+ = 0.60
joy1deadzone5- = 0.60
joy1deadzone5+ = 0.60
joy1deadzone6- = 0.60
joy1deadzone6+ = 0.60
joy1deadzone7- = 0.60
joy1deadzone7+ = 0.60
joy2deadzone0- = 0.60
joy2deadzone0+ = 0.60
joy2deadzone1- = 0.60
joy2deadzone1+ = 0.60
joy2deadzone2- = 0.60
joy2deadzone2+ = 0.60
joy2deadzone3- = 0.60
joy2deadzone3+ = 0.60
joy2deadzone4- = 0.60
joy2deadzone4+ = 0.60
joy2deadzone5- = 0.60
joy2deadzone5+ = 0.60
joy2deadzone6- = 0.60
joy2deadzone6+ = 0.60
joy2deadzone7- = 0.60
joy2deadzone7+ = 0.60

[serial]
serial1       = dummy
serial2       = dummy
serial3       = disabled
serial4       = disabled
serial5       = disabled
serial6       = disabled
serial7       = disabled
serial8       = disabled
serial9       = disabled
phonebookfile = phonebook-dosbox-x.txt

[parallel]
parallel1 = disabled
parallel2 = disabled
parallel3 = disabled
parallel4 = disabled
parallel5 = disabled
parallel6 = disabled
parallel7 = disabled
parallel8 = disabled
parallel9 = disabled
dongle    = false

[printer]
printer     = false
dpi         = 360
width       = 85
height      = 110
printoutput = png
multipage   = false
device      = -
docpath     = .
fontpath    = FONTS
openwith    = 
openerror   = 
printdbcs   = auto
shellhide   = false
timeout     = 0

[dos]
xms                             = true
xms handles                     = 0
shell configuration as commands = false
hma                             = true
hard drive data rate limit      = -1
floppy drive data rate limit    = -1
ansi.sys                        = true
log console                     = false
share                           = true
file access tries               = 0
network redirector              = true
minimum mcb free                = 0
ems                             = true
umb                             = true
quick reboot                    = false
ver                             = 
lfn                             = auto
fat32setversion                 = ask
shellhigh                       = auto
automount                       = true
automountall                    = false
mountwarning                    = true
autofixwarning                  = false
startcmd                        = false
starttranspath                  = true
startwait                       = true
startquiet                      = false
int33                           = true
keyboardlayout                  = auto
customcodepage                  = 
dbcs                            = true
dos clipboard device enable     = false
dos clipboard device name       = CLIP$
dos clipboard api               = true

[ipx]
ipx = false

[ne2000]
ne2000  = false
nicbase = 300
nicirq  = 3
macaddr = AC:DE:48:88:99:AA
backend = auto

[ethernet, pcap]
default value will be used.
realnic = list
timeout = default

[ethernet, slirp]
ipv4_network    = 10.0.2.0
ipv4_netmask    = 255.255.255.0
ipv4_host       = 10.0.2.2
ipv4_nameserver = 10.0.2.3
ipv4_dhcp_start = 10.0.2.15

[ide, primary]
enable = true
pnp    = true

[ide, secondary]
enable = true
pnp    = true

[ide, tertiary]
enable = false
pnp    = true

[ide, quaternary]
enable = false
pnp    = true

[ide, quinternary]
enable = false
pnp    = true

[ide, sexternary]
enable = false
pnp    = true

[ide, septernary]
enable = false
pnp    = true

[ide, octernary]
enable = false
pnp    = true

[fdc, primary]
enable = false
pnp    = true
mode   = ps2

[4dos]
rem = This section is the 4DOS.INI file, if you use 4DOS as the command shell

[config]
rem         = This section is DOS's CONFIG.SYS file, not all CONFIG.SYS options supported
break       = off
numlock     = 
shell       = 
dos         = high, umb
fcbs        = 100
files       = 200
country     = 
lastdrive   = a
set path    = Z:\;Z:\SYSTEM;Z:\BIN;Z:\DOS;Z:\4DOS;Z:\DEBUG;Z:\TEXTUTIL
set prompt  = $P$G
set temp    = 
install     = 
installhigh = 
device      = 
devicehigh  = 

[autoexec]

Emulator log

$ SDL_AUDIODRIVER=pipewire ./dosbox-x 
LOG: Early LOG Init complete
LOG: DOSBox-X's working directory: /home/kynikos/dosbox-x
LOG: Logging init: beginning logging proper. This is the end of the early init logging
LOG: Logging: No logfile was given. All further logging will be discarded.
LOG: DOSBox-X version 0.83.24 (Linux SDL2)
LOG: Host keyboard layout is now us (US English)
LOG: Mapper keyboard layout is now us (US English)
LOG: SDL2 reports desktop display mode 1920 x 1080
LOG: Configured windowposition: 
LOG: SDL: Current window pixel format: SDL_PIXELFORMAT_RGB888
LOG: SDL: You are running in 24 bpp mode, this will slow down things!
LOG: X11 main window is 640 x 400 maximized=0
LOG: X11 extension XRANDR is available
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(640,340) size=(640,400) match=(960,540)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: ISA BCLK: 8333333.333Hz (25000000/3)
LOG: monopal: green, 
LOG: Active save slot: 1 [Empty]
LOG: USING AVI+ZMBV
LOG: Max 3670016 sz 64512
LOG: Final 64512
LOG: MIDI:Opened device:none
LOG: Pentium CMPXCHG8B emulation is enabled
LOG: VOODOO LFB now at d0000000
LOG: Serial1: BASE 3f8h
LOG: Serial2: BASE 2f8h
LOG: GetDesktopResolution reading X11 desktop resolution
LOG: Root window (ID 1900) is 1920 x 1080
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(640,340) size=(640,400) match=(960,540)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: Allocated APM BIOS pm entry point at f000:ce20
LOG: Writing code to fce20
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(640,340) size=(640,400) match=(960,540)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: ISA Plug & Play BIOS enabled
LOG: VGA ROM BIOS init callback
LOG: WARNING: No translation support (to host) for code page 0
LOG:          0 ERROR BIOS:Keyboard layout file auto not found
LOG:          0 ERROR BIOS:Keyboard layout file auto not found
LOG: XMS: 50 handles allocated for use by the DOS environment
LOG: EMS page frame at 0xe000-0xefff
LOG: COMMAND.COM env size:             720 bytes
LOG: COMMAND.COM environment block:    0x0701 sz=0x002d
LOG: COMMAND.COM main body (PSP):      0x072f sz=0x009a
LOG: COMMAND.COM stack:                0x0749
LOG: pixratio 1.350, dw false, dh false
LOG: Aspect ratio: 720 x 540  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: X11 main window is 720 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(640,340) size=(720,400) match=(1000,540)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: font texture id=2 will make 128 x 256
LOG: X11 main window is 720 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(595,316) size=(720,400) match=(955,516)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: Fast Forward OFF
LOG: pixratio 1.200, dw false, dh false
LOG: Aspect ratio: 640 x 480  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(595,316) size=(640,400) match=(915,516)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: font texture id=2 will make 128 x 256
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(635,316) size=(640,400) match=(955,516)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG:      20163 ERROR DOSMISC:DOS:0x43:Illegal subfunction 70
LOG: pixratio 1.350, dw false, dh false
LOG: Aspect ratio: 720 x 540  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: X11 main window is 720 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(635,316) size=(720,400) match=(995,516)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)
LOG: font texture id=2 will make 128 x 256
LOG: X11 main window is 720 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(595,316) size=(720,400) match=(955,516)).
LOG:   Goes to output 0: name='DP-1' size_mm=(476 x 268)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (476.000 x 268.000 mm) (18.740 x 10.551 in) (102.454 x 102.358 DPI)

Additional context

DOSBox-X does not crash or hang when using pentium_mmx with Impulse Tracker. Resonance filters work as intended without errors/hangs/crashes. The only thing that's incorrect is the slowed down audio pitch. CPU cycles don't seem to matter in this either.

maron2000 commented 2 years ago

I think there is something wrong with the sampling rate conversion. Try IT m32000 (or any value smaller than 44100)

KynikossDragonn commented 2 years ago

Yeah, that makes things play at the proper "pitch".

Weird, I'm not getting this problem in games set to use "44100 Hz", like Blood and Duke Nukem 3D. And also Z.A.R. when run with the special MMX version.

Is it because of IT outputting at "45454" like the driver screen reports?

maron2000 commented 2 years ago

Looking at the code (sblaster.cpp), the upper limit is set to 44100Hz. You can disable that by adding the following option to the [sblaster] section in the conf file. This may also fix the pitch problem of ZSNES mentioned here #3178

[sblaster]
sample rate limits  = false
#default is true
KynikossDragonn commented 2 years ago

Adding this to the [sblaster] section does indeed make it work correctly at the full sample rate, thanks!

Someone did mention there's two ways to specify a sampling rate on a SB16, the "old" method which ends up with that weird 45454hz setting, and then a "direct" method which will result in actual 44100hz. I'm guessing IT and ZSNES uses the "old" method and games using Miles Sound System, HMI, Apogee Sound System, etc use the "direct" method atleast if you're using the actual Sound Blaster 16 drivers with those middlewares and not "SoundBlaster or 100% Compatible" or "SoundBlaster Pro or 100% Compatible".

FastTracker II, atleast 8bitbubsy's patched versions, didn't require this setting under [sblaster] and sounded correct already.

joncampbell123 commented 2 years ago

Some DOSLIB tests done a few years ago suggest that the sblaster.cpp sample rate limits should be updated. Sound Blaster cards max out at 45454Hz whether SB16 DSP commands or SB Pro commands.

If you're wondering what the visible spikes are in the graphs, well... older SB16 cards have a bug in the DSP firmware that can miscalculate the sample rate when given very specific sample rate values, also note the visible stairstep since SB16 cards internally convert the DSP time constant to sample rate and then round to the nearest rate it can support. Later SB16 cards don't have those sample rate bugs.

Also notice that on SB16 cards, sample rates up to 45454Hz are possible without ever using the special "high speed" DSP playback commands.

Sound Blaster Live! PCI cards (with the resident MS-DOS SB16 emulation driver) don't cap the sample rate at all. Using the old DSP time constant commands you can go up to about 165KHz.

ESS AudioDrive chipsets cap the sample rate at 44.1KHz if you talk to it like a Sound Blaster. If you use the ESS-specific DSP commands instead, you can go as high as 200KHz, though on the laptop I tested on, any disk I/O causes drops in the sample rate because the ISA bus within can't handle both disk I/O and DMA that fast.

If you have a mid to late 90s laptop with the Yamaha OPL3-SAx chipset, which is Sound Blaster Pro compatible, the chipset does not cap the sample rate and you can go as high as 325KHz, though again, disk I/O will cause contention with the ISA bus and cause drops in sample rate.

http://hackipedia.org/browse.cgi/Computer/Platform/PC%2c%20IBM%20compatible/Sound%20and%20Music/Creative%20Labs/Sound%20Blaster/Collection/DOSLIB%20documentation/Creative%20Sound%20Blaster%2016%20CT1740/graphs/rates