Soft Volume Adjustment

Here you are welcome to post Setvol feature requests
Post Reply
Zaaphod
Posts: 3
Joined: Mon Jan 17, 2022 11:55 am

Soft Volume Adjustment

Post by Zaaphod »

Thank you for this great utility! I found it very difficult to control the volume under program control directly, and this works very well.

I am using it on a CNC machine to turn up the volume on my system when the machine is running, then turn it back down automatically when the machine stops.

The only issue I have is that the volume change is very sudden, and it would be much better if it took some time to get to the new desired volume level, instead of just slamming it all the way to the target suddenly. This is how the automatic volume adjustment in my car works.. when I stop, it gradually turns the volume down, and when I get going again, it gradually turns it back up.. it's not a sudden change.

I tried to do this on my own, but unfortunately it takes too long for SetVol to return from a volume change, so I can either do a very slow transition, or the steps need to be very coarse. From what I can tell, it changes the volume very fast, and then a delay before I get control back.. and the delay is not always the same amount of time. I'm hoping that this feature could be implemented with SetVol itself, then it could send the volume changes in increments at a specified rate, and the exit delay would not matter.

The Way I would implement something like this is to just add a rate specifier, where you specify the rate in Seconds for Full swing.... that way it would always be consistent and happen the same way no matter how far it had to go. So a Rate of 10 would take 10 seconds to go from 0% to 100%... so if the volume was at 35 and you did SetVol 75 Rate 10, it would take 4 seconds to go the 40% from 35 up to 75... and if the volume was 15 when you ran SetVol 75 Rate 10, it would now take 6 seconds to go the 60% from 15 to 75.. but after it crossed 35, the change would be the same as the previous 35 to 75 example. because at that point it would still have 4 seconds left to finish the change.

The math for this is pretty straight forward, just do
Delay_time = ((Target_Volume - Start_Volume)/Rate)/(Target_Volume - Start_Volume)
then just change volume 1% at a time with a timer of Delay_Time between them.

Thank You for your consideration.
RobLatour
Site Admin
Posts: 1023
Joined: Mon Feb 19, 2018 11:43 am

Re: Soft Volume Adjustment

Post by RobLatour »

Interesting idea, I will need to think on this.
Zaaphod
Posts: 3
Joined: Mon Jan 17, 2022 11:55 am

Re: Soft Volume Adjustment

Post by Zaaphod »

Here is the code I use, It's Pascal, but you will get the idea.
This method automatically compensates for any delays in processing and the timer doesn't accumulate any error.
The problem I have is when I run this, say with an Initial Volume of 58 and a Target of 17, it only runs the loop 4 times... 47, 36, 24, 17 so it's not a very smooth transition, but the method provides uniform timing even if delays in the system prevent you from hitting every percentage.

Code: Select all

A_Second=1/24/60/60;
AProcess := TProcess.Create(nil);
AProcess.Executable := 'Setvol.exe';
AProcess.Options := AProcess.Options + [poWaitOnExit];
AProcess.Parameters.Add('Report');
AProcess.Execute;                                           //Runs SetVol.Exe
Initial_Volume:=AProcess.ExitCode;
Writeln('Volume Was: ',Initial_Volume);

Volume_Start_Time:=Now;
Previous_Volume:=Initial_Volume;
Volume_Time_Percentage:=(Abs(Target_Volume-Initial_Volume)/100)*Volume_Rate;

Repeat
   Volume_Time_Percentage:=1-(((Now-Volume_Start_Time)/A_Second)/Soft_Volume_Rate);
   If Volume_Time_Percentage <= 0 then 
      Volume_Time_Percentage := 0;
   Volume_Level:=Round(Target_Volume+(Initial_Volume-Target_Volume)*Volume_Time_Percentage);
   If Volume_Level <> Previous_Volume Then
      Begin
         Previous_Volume:=Volume_Level;
         AProcess.Parameters.Clear;
         AProcess.Parameters.Add(InttoStr(Volume_Level));
         Writeln('Volume : ',Volume_Level);
         AProcess.Execute;                                  //Runs SetVol.Exe
      End
   Else
      Sleep(100);
Until Volume_Level = Target_Volume
AProcess.Free
RobLatour
Site Admin
Posts: 1023
Joined: Mon Feb 19, 2018 11:43 am

Re: Soft Volume Adjustment

Post by RobLatour »

Actually, I just coded something for the next release that should do the trick.

If you would like to try a beta, please let me know.
Zaaphod
Posts: 3
Joined: Mon Jan 17, 2022 11:55 am

Re: Soft Volume Adjustment

Post by Zaaphod »

Yes, I would like to test the beta version.

Thanks for looking into this idea.
RobLatour
Site Admin
Posts: 1023
Joined: Mon Feb 19, 2018 11:43 am

Re: Soft Volume Adjustment

Post by RobLatour »

ok - I will email you a link in a moment.
RobLatour
Site Admin
Posts: 1023
Joined: Mon Feb 19, 2018 11:43 am

Re: Soft Volume Adjustment

Post by RobLatour »

Thanks again for your suggestion and review of this Zaaphod.

Setvol version 3.3 is now generally released with the change.

For example, you can now say:
setvol 50 over 30
and SetVol will now change the level to 50, by increments of 1 spread out evenly as required, over a total of 30 seconds.
Post Reply