When using sonar, perform lullaby volume adjustment internally

Currently, using sonar makes lullabyes unusable, as both run on the same audio channel, and sonar sets the volume to max automatically.

Work around that by scaling the lullaby sound internally, so the sound is passed to Android already diminished.

Hello @Jostikas, many thanks for your feedback. Sharing of the stream is necessary as Sonar only works on the media stream reliably across devices…

But if you use internal lullabies we support a feature which will recalculate any volume changes to the lullaby internal volume in the app’s process…

So Sonar has a specified volume (called Signal strength in the sensor test). The Sonar service checks regularily for changes in the volume and enforces the configured volume. But if you run a lullaby the same process will calculate the difference in volume and prior to increasing the volume it calculates how much should the lullaby playback volume be decreased. It is not 100% as volume steps differ between devices so we adjusted that for stock Android and Pixel phones… but more or less it should work on all phones although there can be slight hearable changes in volume when you do that…

Of course this does not work with any 3rd party lullabies - Spotify etc…

BTW this issues is covered in https://docs.sleep.urbandroid.org/faqs/Volume_max.html