mirror of
https://github.com/devgianlu/go-librespot.git
synced 2026-04-26 05:15:49 +03:00
[GH-ISSUE #160] go-librespot works with driver that support C.SND_PCM_FORMAT_FLOAT_LE only #100
Labels
No labels
bug
enhancement
pull-request
spotify-side
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/go-librespot#100
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pilollipietro on GitHub (Jan 13, 2025).
Original GitHub issue: https://github.com/devgianlu/go-librespot/issues/160
I'm using C.SND_PCM_FORMAT_S16_LE
I attach here code to support it. The patch must be applied to git tag v0.1.3.
go-librespot-SND_PCM_FORMAT_S16_LE.patch.txt
@devgianlu commented on GitHub (Jan 16, 2025):
You are welcome to make a PR to merge this into the codebase! If you can't/don't want to do it let me know and I'll merge it.
@pilollipietro commented on GitHub (Jan 20, 2025):
go-librespot-SND_PCM_FORMAT_S16_LE.patch.txt
Honestly, it's the first patch I've made in go and I don't know rust, I use git for work but I've never used github. I would prefer in the first instance if you can that you did it yourself. Place the patch aligned to the current master
@devgianlu commented on GitHub (Jan 20, 2025):
I have created a PR with your changes, but I had to change the code a little bit and now it does not seem to work. Specifically, errors from
configureAdaptiveBufferwere not handled and now it seems to fail there. Can you have a look?@pilollipietro commented on GitHub (Jan 28, 2025):
Thank you. The problem seems to be that in the else branch the err var is not initializated.
The logic might be
The logic should be that if it fails snd_pcm_hw_params_get_buffer_size it goes to the else branch and prints the error, in reality it might be a warning because in some situations it could work including the one in which you have min fuffer size and max buffer size it could work. I have added some comments in this chunk code I have put some fake comment HEREEEE in the relevant code lines.
If you see my patch I have simply initialize err before the first if. I think that it is all.
@devgianlu commented on GitHub (Jan 28, 2025):
I still don't get it because
snd_pcm_hw_params_get_buffer_sizereturns an error on my system, but thesnd_pcm_hw_params_set_buffer_time_nearandsnd_pcm_hw_params_set_period_size_nearcalls work anyway. Contrary to what you mention in the comment:@pilollipietro commented on GitHub (Jan 29, 2025):
ALSA Buffer Size Analysis
Ok may be that it is, my assumption is wrong.
FACTS (or believe?):
There are two kinds of sound card class devices:
If
snd_pcm_hw_params_get_buffer_sizefails, the algorithm to set parameters does not work correctly because the computation depends onbufferSize:The
ifbranch also fails ifsnd_pcm_hw_params_set_buffer_time_nearorsnd_pcm_hw_params_set_period_size_nearfail.Testing on Your System
Run the following command:
Replace
-Dwith your device found using:BUFFER_SIZE: [48 16384], thensnd_pcm_hw_params_get_buffer_sizeandsnd_pcm_hw_params_set_buffer_sizemight work.BUFFER_MIN_SIZEandBUFFER_MAX_SIZE, then theifbranch could not work, as you cannot usesnd_pcm_hw_params_get_buffer_sizeandsnd_pcm_hw_params_set_buffer_size.(Reference)
May be that not all drivers follow the same behavior. Some allow setting a specific buffer size within the min-max range, while others auto-adapt. You might want to mention that this depends on the ALSA implementation for the specific hardware.
Assumption
If the card supports
snd_pcm_hw_params_get_buffer_size_minandsnd_pcm_hw_params_get_buffer_size_max, it might be adaptive (ALSA does not explicitly document this behavior or I have not found it). In this case, setting these parameters is not useful, as the buffer size changes automatically.Proposal
We could wrap the old (if branch) code in a
try-catchequivalent and log all errors as warnings.Curiosity: Did you write this code? Does this conversation seem familiar to you?
@pilollipietro commented on GitHub (Jan 31, 2025):
Read the FFmpeg Alsa code it has a similar logic, and I'm pretty sure that it works on all systems.
Reading this code it seems that they don't set buffer time and they set buffer size to max. May be a reasonable choice.
@pilollipietro commented on GitHub (Jan 31, 2025):
This code works perfectly on my two laptops and on the ARM TV box connected to the DAC of the HiFi system. It is similar to the original code, with key differences: it does not read the bufferTime variable and sets the largest possible buffer. If I uncomment the setBufferTime, setting it to a valid parameter causes the ALSA driver to crash on initialization with a generic hwParams error. I think the problem lies in the consistency between bufferTime and bufferSize; in any case, I believe this is the best option.
@devgianlu commented on GitHub (Sep 3, 2025):
It took a while, but I merged support for more PCM formats. I did not include the adaptive buffer part, please open a separate issue if that's still an issue for you.
@Gerrelt commented on GitHub (Sep 26, 2025):
Thank you for the merge! The new version 0.4.0 solved my problem as mentioned in #200 .