librespot-org / librespot-java

The most up-to-date open source Spotify client
Apache License 2.0
380 stars 93 forks source link

Volume control via bypassSinkVolume #376

Closed snoopbird closed 3 years ago

snoopbird commented 3 years ago

First of all I would like to thank you for the great project, as Spotify does not want to implement an integration for the Apple HomePod.

With spocon, I send the "music" to owntone via PIPE. From there I can wonderfully send the music to the HomePods via Airplay. With the latest changes there are almost no more delays in play and stop! :-)

My configuration

[player]
    # Whether to apply the Spotify loudness normalisation
    enableNormalisation = true
    # Initial volume (0-65536)
    initialVolume = 5243
    # Whether librespot-java should ignore volume events, sink volume is set to the max
    bypassSinkVolume = true
    # Release mixer line after set delay (in seconds)
    releaseLineDelay = 20
    # Normalisation pregain in decibels (loud at +6, normal at +3, quiet at -5)
    normalisationPregain = 3.0
    # Output metadata in Shairport Sync format (https://github.com/mikebrady/shairport-sync-metadata-reader)
    metadataPipe = "/srv/music/spotify.metadata"
    # Autoplay similar songs when your music ends
    autoplayEnabled = true
    # Preferred audio quality (NORMAL, HIGH, VERY_HIGH)
    preferredAudioQuality = "VERY_HIGH"
    # Where librespot-java should search for local files
    localFilesPath = ""
    # Audio output device (MIXER, PIPE, STDOUT, CUSTOM)
    output = "PIPE"
    # Crossfade overlap time (in milliseconds)
    crossfadeDuration = 0
    # Whether the player should retry fetching a chuck if it fails
    retryOnChunkError = true
    # Audio output Java class name
    outputClass = ""
    # Mixer/backend search keywords (semicolon separated)
    mixerSearchKeywords = ""
    # Output raw (signed) PCM to this file (`player.output` must be PIPE)
    pipe = "/srv/music/spotify"
    # Log available mixers
    logAvailableMixers = true
    # Number of volume notches
    volumeSteps = 64

With the configuration: bypassSinkVolume = false I can change the volume, but it is very offset in time.

With bypassSinkVolume = true I can change the volume in Spotify, but this has no effect.

What am I doing wrong? Or is that a bug?

devgianlu commented 3 years ago

When you use bypassSinkVolume=true you are effectively saying to librespot-java to not react to volume changes, but dispatch them around. One of the places is to the DACP metadata pipe. The reason you are getting delayed volume updates with bypassSinkVolume=false is because the audio is being buffered a lot before getting to your speakers.

I think that there's some issue with the volume command not getting to owntone.

snoopbird commented 3 years ago

Thank you for your feedback signal! Can someone please tell me what I'm doing wrong? Or how do I get a solution?

devgianlu commented 3 years ago

@aleszczynskig @uvjustin

aleszczynskig commented 3 years ago

This is curious as it should work with the setup you have configured.

When playing from Spotify do you get the track metadata showing in the Owntone UI or remote app?

If you do then the volume data should be working and I would suggest to run owntone with debug logging to see what is going on.

If you don't this is the source of the problem. It could be permissions or owntone configuration. Again I think the clues would be in the owntone log, probably with debug logging turned on.

Also I presume that you can control the volume of your speakers from owntone normally when not using Spotify.

snoopbird commented 3 years ago

The artist / track is displayed in Owntone UI. image

I adjusted the log to DEBUG in owntone and looked in the log. That looks strange doesn't it?!

[2021-07-01 21:51:47] [DEBUG] raop: send_progress: Sending SET_PARAMETER to 'Küche' [2021-07-01 21:51:56] [DEBUG] player: Read Shairport metadata (type=73736e63, code=70766f6c, len=21) [2021-07-01 21:51:56] [DEBUG] player: Not applying Shairport airplay volume while software volume control is enabled (-12,90,0.00,0.00,0.00) [2021-07-01 21:51:59] [DEBUG] player: event_read_metadata() [2021-07-01 21:51:59] [DEBUG] player: Incomplete read, wanted 1764, got 116 (samples=29/time=657596), deficit 2184 [2021-07-01 21:52:01] [DEBUG] player: event_play_metadata()

The volume can be changed via owntone.

aleszczynskig commented 3 years ago

I'm not familiar with this but does indicate that owntone is receiving the volume commands. You might need to speak with the owntone dev to enquire what this means.

Do you use purely airplay devices with owntone?

snoopbird commented 3 years ago

I read the spotify.metadata with the shairport-sync-metadata-reader. Can anyone understand that? Is this a problem? In my head is pvol = volume? image

snoopbird commented 3 years ago

Someone an idea? 😃

aleszczynskig commented 3 years ago

pvol is the volume command. Check the documentation for shairport-sync-metadata-reader.

I don't think there is an issue with the communication between owntone and librespot-Java. The issue is that owntone is ignoring the command because of your owntone setup. That is where you need to focus your attention.

FYI - The metadata reader is not reliable for testing due to the way it has been implemented in c. The reasons for this are beyond my knowledge though.

snoopbird commented 3 years ago

In my owntone.conf only the values ​​are set. All others are commented out.

Sorry that I'm annoying you so much.

general {
    uid = "root"
    logfile = "/var/log/owntone.log"
    loglevel = info
    ipv6 = yes
}
library {
    name = "My Music on %h"
    port = 3689
    directories = { "/srv/music" }
    podcasts = { "/Podcasts" }
    audiobooks = { "/Audiobooks" }
    compilations = { "/Compilations" }
    compilation_artist = "Various Artists"
}
audio {
    nickname = "Computer"
}
spotify {
}
mpd {
}
sqlite {
}
streaming {
}
aleszczynskig commented 3 years ago

I'm not an expert on config for owntone but I believe you require an alsa section defining the card and mixer to use. If this is not the problem I'm afraid I don't have experience in this space.

One other option is to remove the audio section completely.

I hope this helps.

snoopbird commented 3 years ago

Hi @aleszczynskig, Thank you for your help! In the last few days I've tried to solve the problem for many hours, but I'm kind of stupid :sweat_smile:

With the RPI4, I can't manage to regulate the owntone volume with the alsamixer.

You don't have an RPI too?, so I can simply take over your alsa and owntone configuration? :smile:

snoopbird commented 3 years ago

I reinstalled rasbian today and now it works ?! Does not matter! The main thing is that it works! :-)