Roger Daley Well-Known Member Licensed User Longtime User Nov 29, 2022 #1 Hi All, I am trying to set the volume a Beep is played at and then restore the volume. I thought this would be simple but the compiler doesn't like my code. It looks straight forward but I'm missing something. Any help much appreciated. The relevant part of code. Code: Copy VolMus = Beep1.VOLUME_MUSIC 'Save current volume setting in integer ' Beep1.VOLUME_MUSIC = 5 'Set volume for Beep1' Beep1.Beep Sleep(21) Beep1.VOLUME_MUSIC = VolMus 'Restore setting' The Compiler shows the following: Compiling generated Java code. Error B4A line: 5974 Beep1.VOLUME_MUSIC = 5 src\b4a\configulator_calculator\main.java:9066: error: cannot assign a value to final variable VOLUME_MUSIC parent.mostCurrent._beep1.VOLUME_MUSIC = (int) (5); Click to expand... I've searched the Forum but failed. Thanks in advance Regards Roger
Hi All, I am trying to set the volume a Beep is played at and then restore the volume. I thought this would be simple but the compiler doesn't like my code. It looks straight forward but I'm missing something. Any help much appreciated. The relevant part of code. Code: Copy VolMus = Beep1.VOLUME_MUSIC 'Save current volume setting in integer ' Beep1.VOLUME_MUSIC = 5 'Set volume for Beep1' Beep1.Beep Sleep(21) Beep1.VOLUME_MUSIC = VolMus 'Restore setting' The Compiler shows the following: Compiling generated Java code. Error B4A line: 5974 Beep1.VOLUME_MUSIC = 5 src\b4a\configulator_calculator\main.java:9066: error: cannot assign a value to final variable VOLUME_MUSIC parent.mostCurrent._beep1.VOLUME_MUSIC = (int) (5); Click to expand... I've searched the Forum but failed. Thanks in advance Regards Roger
Erel B4X founder Staff member Licensed User Longtime User Nov 29, 2022 #2 VOLUME_XXX are constants that are passed to Beeper.Initialize2. They set the voice channel. You can se the volume with Phone.SetVolume. Make sure to wrap it in a Try / Catch block as there are cases where it will throw an exception. Upvote 0
VOLUME_XXX are constants that are passed to Beeper.Initialize2. They set the voice channel. You can se the volume with Phone.SetVolume. Make sure to wrap it in a Try / Catch block as there are cases where it will throw an exception.
Roger Daley Well-Known Member Licensed User Longtime User Nov 29, 2022 #3 Erel said: VOLUME_XXX are constants that are passed to Beeper.Initialize2. They set the voice channel. You can se the volume with Phone.SetVolume. Make sure to wrap it in a Try / Catch block as there are cases where it will throw an exception. Click to expand... Thanks Erel, I will give it a try. It seems an odd way to go when there is "XXXX.VOLUME_MUSIC". I don't think Beep comes through the Voice Channel, but through the Music channel. Regards Roger Upvote 0
Erel said: VOLUME_XXX are constants that are passed to Beeper.Initialize2. They set the voice channel. You can se the volume with Phone.SetVolume. Make sure to wrap it in a Try / Catch block as there are cases where it will throw an exception. Click to expand... Thanks Erel, I will give it a try. It seems an odd way to go when there is "XXXX.VOLUME_MUSIC". I don't think Beep comes through the Voice Channel, but through the Music channel. Regards Roger
Roger Daley Well-Known Member Licensed User Longtime User Nov 29, 2022 #4 Can anyone point me towards a working example of setting the volume for BEEP and restoring Volume Setting after beep? Regards Roger Upvote 0
Can anyone point me towards a working example of setting the volume for BEEP and restoring Volume Setting after beep? Regards Roger
kimstudio Active Member Licensed User Longtime User Nov 29, 2022 #5 Beep generates a SINE or PULSE wave internally according to frequency and play it with a certain amplitude, so @Erel can add a new parameter as volume for example between 0 to 1 and multiply it to the wave samples generated to control the Beep volume. It is the tiniest thing for Erel to make but it will change the Audio library API. Upvote 0
Beep generates a SINE or PULSE wave internally according to frequency and play it with a certain amplitude, so @Erel can add a new parameter as volume for example between 0 to 1 and multiply it to the wave samples generated to control the Beep volume. It is the tiniest thing for Erel to make but it will change the Audio library API.