-
Notifications
You must be signed in to change notification settings - Fork 151
Description
oto version: v3.3.3 (also tried 3.3.2)
ebitengine version: v2.8.8 (also tried 2.8.6)
On some Linux machines, if 44100 sample rate is used, an error is given:
oto: ALSA error at snd_pcm_hw_params: Invalid argument
This error is returned by a call to ebiten.RunGame.
Let's see if it's a sample rate problem:
$ speaker-test -r 48000
speaker-test 1.2.9
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 192 to 1048576
Period size range from 48 to 524288
Using max buffer size 1048576
Periods = 4
was set period_size = 262144
was set buffer_size = 1048576
0 - Front Left
48k works fine
$ speaker-test -r 44100
speaker-test 1.2.9
Playback device is default
Stream parameters are 44100Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 44100Hz (requested 44100Hz)
Buffer size range from 176 to 963379
Period size range from 44 to 481690
Using max buffer size 963376
Unable to set buffer size 963376 for playback: Invalid argument
Setting of hwparams failed: Invalid argument
44100 does not work even outside of ebitengine/oto context.
I can fix that by using 48000 sample rate when creating an audio context:
audio.NewContext(48000)
But there is a problem: what if 48k doesn't work on some machines as well?
We need to be able to know which sample rate we can safely use, otherwise the game will crash when any sound is attempted to play. Or maybe there is a way to make 44100 work even if alsa gives that error (I am not familiar with snd_pcm_hw_params error).
Ideally, 44100 would just work, but maybe it's not possible. Then oto/ebitengine users would try to support at least 2 (?) sample rates - a default 44100 and 48000 if 44100 doesn't work (but it is a lot of efforts though).
Some system info:
!!ALSA Version
!!------------
Driver version: k6.11.0-29-generic
Library version:
Utilities version: 1.2.9
!!DMI Information
!!---------------
Manufacturer: LENOVO
Product Name: 21NX0079GX
Product Version: ThinkPad X1 Carbon Gen 13
Firmware Version: N4MET20W (1.07 )
System SKU: LENOVO_MT_21NX_BU_Think_FM_ThinkPad X1 Carbon Gen 13
Board Vendor: LENOVO
Board Name: 21NX0079GX
I think the hardware supports 44100:
$ alsa-info --with-devices --stdout --no-upload
Codec: Realtek ALC287
Address: 0
AFG Function Id: 0x1 (unsol 1)
Vendor Id: 0x10ec0287
Subsystem Id: 0x17aa2340
Revision Id: 0x100002
No Modem Function Group found
Default PCM:
rates [0x560]: 44100 48000 96000 192000
bits [0xe]: 16 20 24
formats [0x1]: PCM
But some of the nodes (?) list only 48k:
Node 0x03 [Audio Output] wcaps 0x41d: Stereo Amp-Out
Control: name="Headphone Playback Volume", index=0, device=0
ControlAmp: chs=3, dir=Out, idx=0, ofs=0
Amp-Out caps: ofs=0x57, nsteps=0x57, stepsize=0x02, mute=0
Amp-Out vals: [0x41 0x41]
Converter: stream=0, channel=0
PCM:
rates [0x40]: 48000
bits [0xe]: 16 20 24
formats [0x1]: PCM
Power states: D0 D1 D2 D3 EPSS
Power: setting=D0, actual=D0
I can provide extra info if needed.
Potentially relevant: https://discourse.osmc.tv/t/sound-problems-dropouts-with-alsa/92331/4