Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Snapclients are at 100% volume at first connect #37

Closed
nis65 opened this issue Dec 11, 2021 · 7 comments · Fixed by #74
Closed

New Snapclients are at 100% volume at first connect #37

nis65 opened this issue Dec 11, 2021 · 7 comments · Fixed by #74
Labels
enhancement New feature or request

Comments

@nis65
Copy link
Collaborator

nis65 commented Dec 11, 2021

I have not investigated yet if there is any possibility via command line / configuration files to set the initial volume to a certain level. I agree that for new setups it is easier to search for something to lower the volume than to start erratic debuging just to find out two hours later that it was just one (of the many) volume settings along the audio path set to 0...

But when you have a working setup and add a device (by simply adding a hostname to your inventory and running the playbook again) or rename the snapclient device name (add/edit some ansible variables...) it can get quite loud during the ansible run: At the moment the snapclient picks up the connection and starts to play music for the first time, you have 100% volume. Depending on what equipment you have connected (e.g. a hifiberry amp board with connected speakers), the only chance you have is to stop all inputs...

@nis65
Copy link
Collaborator Author

nis65 commented Dec 11, 2021

badaix/snapcast#910

Feature Request in snapcast project

@nis65 nis65 added the enhancement New feature or request label Dec 12, 2021
@nis65
Copy link
Collaborator Author

nis65 commented Dec 26, 2021

Possible solutions:

  • ansible: additional workaround role that turns the hardware alsa volume down. After first deployment, the user would have to do two things:
    • lower the snapclient volume in snapweb
    • login to the raspi and manually raise the alsa hardware volume back to the desired level. This might be needed anyway as you might not want a certain amp/speaker pair to operate over a certain volume.
  • snapcast: edit/recompile snapclient (and/or snapserver) to support a configurable initial volume (i.e. implement feature request linked in previous comment).

@nis65
Copy link
Collaborator Author

nis65 commented Jun 25, 2022

Success. The following diff against current master [v 0.26] solves the problem for me. I have now an additional parameter in /etc/snapclient.conf:

[server]
...
defaultvolume=21

And this is the volume in percent a brand new snapclient gets assigned on initial connect (i.e. the snapclient is not known to /var/lib/snapserver/server.json yet). If this parameter is not set, the volume assigned on initial connect will be 100 as before.

@nis65
Copy link
Collaborator Author

nis65 commented Jun 25, 2022

diff --git a/server/server.cpp b/server/server.cpp
index e1450f84..b6f3f61e 100644
--- a/server/server.cpp
+++ b/server/server.cpp
@@ -770,6 +770,11 @@ void Server::onMessageReceived(StreamSession* streamSession, const msg::BaseMess
         }
 
         ClientInfoPtr client = group->getClient(streamSession->clientId);
+        if (newGroup)
+        {
+             // override default volume set from constructor
+             client->config.volume.percent = settings_.server.default_volume;
+        }
 
         LOG(DEBUG, LOG_TAG) << "Sending ServerSettings to " << streamSession->clientId << "\n";
         auto serverSettings = make_shared<msg::ServerSettings>();
diff --git a/server/server_settings.hpp b/server/server_settings.hpp
index 31d87982..7ce7aea9 100644
--- a/server/server_settings.hpp
+++ b/server/server_settings.hpp
@@ -34,6 +34,7 @@ struct ServerSettings
         std::string user{"snapserver"};
         std::string group{""};
         std::string data_dir{""};
+        int default_volume{100};
     };
 
     struct Http
diff --git a/server/snapserver.cpp b/server/snapserver.cpp
index 4fd94c64..6271ea06 100644
--- a/server/snapserver.cpp
+++ b/server/snapserver.cpp
@@ -78,6 +78,7 @@ int main(int argc, char* argv[])
         conf.add<Value<string>>("", "server.user", "the user to run as when daemonized", settings.server.user, &settings.server.user);
         conf.add<Implicit<string>>("", "server.group", "the group to run as when daemonized", settings.server.group, &settings.server.group);
         conf.add<Implicit<string>>("", "server.datadir", "directory where persistent data is stored", settings.server.data_dir, &settings.server.data_dir);
+        conf.add<Value<int>>("","server.defaultvolume", "default volume for new snapclients", settings.server.default_volume, &settings.server.default_volume);
 
         // HTTP RPC settings
         conf.add<Value<bool>>("", "http.enabled", "enable HTTP Json RPC (HTTP POST and websockets)", settings.http.enabled, &settings.http.enabled);

@nis65
Copy link
Collaborator Author

nis65 commented Jun 26, 2022

Moved setting from server to streaming_client.initial_volume, added docu and created PR:

badaix/snapcast#1024

@nis65
Copy link
Collaborator Author

nis65 commented Jul 4, 2022

PR has been merged in snapcast to develop and will be in next release there.

I'll expand the current snapserver role to support the new parameter in snapserver.conf. This will be backwards compatible, as unknown config entries are simply ignored by snapserver.

@nis65
Copy link
Collaborator Author

nis65 commented Feb 27, 2023

And it's released in v0.27.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant