2

I am playing around with changing the volume in Asterisk. There are a few applications where I would benefit from this. Most of them are to increase the volume but there are also some scenarios in which I was looking to decrease the volume below the default.

I know someone uses SET(VOLUME(TX)=10) to achieve a very realistic sounding 1004 Hz test tone when someone calls his milliwatt line.

He also told me, he wasn't sure, but he thought that '3' was the normal volume for both TX and RX. I couldn't find any documentation to confirm or deny this. But I thought I would run a simple test:

[mf] ; This is "supposed" to increase the transmit volume (what the caller would hear), execute a subroutine, and then "reset" the channel volume back to normal
exten => start,1,SayAlpha(A)    
    same => n,SayAlpha(A)   
    same => n,SayAlpha(A)   
    same => n,SET(VOLUME(TX)=1) 
    same => n,GoSub(mfer,start,1(${ARG1}))
    same => n,SayAlpha(A)
    same => n,SayAlpha(A)
    same => n,SET(VOLUME(TX)=0.4)
    same => n,SayAlpha(A)
    same => n,SayAlpha(A)
    same => n,SET(VOLUME(TX)=3) ; return volume to original loudness ** is the original volume 3?
    same => n,SayAlpha(A)
    same => n,SayAlpha(A)
    same => n,Return()

I simply listened to the "A" digits to see if they got louder or softer.

To my surprise, the only differences were the last 2 sounded louder! The first 6 all sounded the same!

This tells me the "normal" channel volume is not 3 - it must be 2 or 1, and is probably 1.

Also the 0.4 did not make the channel softer, so this leads me to believe 1 is the smallest possible value.

So, is it possible to make transmit or receive volume softer than the default in Asterisk? It seems decimals are not supported so I'm not sure where to head now.

InterLinked
  • 2,406
  • 6
  • 29
  • 64

2 Answers2

1

Short answer:

To decrease the volume use negative integer less than or equal to -2. e.g.

same => n,SET(VOLUME(TX)=-4)

Long answer:

Disclaimer: My findings are based on reading the asterisk source code. I did not build nor trace the code, only read it, there is significant room for misunderstanding.

  • The default setting is zero 0. It disables calling the volume adjustment routine.
  • To increase the volume set the adjustment to integer greater than or equal to 2.
  • To decrease the volume set the adjustment to integer less than or equal to -2.
  • The adjustment is applied as short integer. Setting the adjustment to a decimal number at best might convert it to a short int, but I do not know what really happens there.
  • Using adjustment value of -1 or 1 has no effect on the resulting volume but wastes CPU cycles (see below for the reason), use zero 0 instead of -1 or 1.
  • Setting volume adjustment several times on same channel+direction(direction being TX or RX) does not have a compounding effect. Each execution to set the volume clears the previous adjustment on that channel+direction and sets the new adjustment.

Reasoning:

  • the adjustment ends up being stored as int and applied as short. I suspect there is no point trying to use decimals e.g. "1.5" nor "0.1". Stick to integers.
  • zero adjustment means no adjustment (default)
  • when the adjustment is positive then each sample is multiplied by the adjustment and clipped to 16 bit signed int.
  • when the adjustment is negative then each sample is divided by the modulus abs(adjustment).

If my understanding is right then:

; Reduce each sample to 50% the original value
same => n,SET(VOLUME(TX)=-2)

; Reduce each sample to 20% the original value
same => n,SET(VOLUME(TX)=-5)

; Reduce each sample to 10% the original value
same => n,SET(VOLUME(TX)=-10)

; Disable volume adjustments
same => n,SET(VOLUME(TX)=0)

; Waste CPU cycles by calling functions only to multiply by 1, the adjustment value of zero would achieve the same more efficiently
same => n,SET(VOLUME(TX)=1)

; Increase each sample to 200% of the original value
same => n,SET(VOLUME(TX)=2)

Note that perceived volume change and sample scaling are probably not the same thing, e.g. doubling each sample might not double perceived change in volume.

AnyDev
  • 126
  • 3
  • Do you mean the call was actually softer with negative volumes? How low and high can you go? – InterLinked Sep 23 '19 at 18:08
  • @InterLinked Yes, setting value to "-10" made the sound level noticeably quieter/softer/lower. As for "how low and high" is my problem too, the documentation does not mention it. – AnyDev Sep 24 '19 at 00:03
0

VOLUME functions works just okay.

Please ensure your endpoint(softphone or hardphone) have no function like "normilize sound level".

arheops
  • 1,355
  • 2
  • 11
  • 17
  • I have just standard telephones connected to an ATA. No such settings, obviously, are available. I also tested this out with others who confirmed my findings. – InterLinked Jan 24 '19 at 20:08
  • So your ATA in this case called "endpoint". I have tested Volume in real project and it worked. You can ensure by record conversation and open it in media player. – arheops Jan 25 '19 at 00:08
  • 1
    The answer is not helpful, no examples, no explanations. Comparable to "works for me" – AnyDev Sep 23 '19 at 07:35
  • Good luck. Will see what you answer on 1000th of same question. BTW, i am pretty sure issue was normalization at softphone, not what you writed as answer. Just experience. – arheops Sep 23 '19 at 14:35
  • @arheops I'm not scoring you nor the history of your answers. I commented on this answer only. OP's question is directly asking about reducing volume. The OP's example code does not attempt to use negative setting. A very helpful place to start would be to suggest the correct use of the function. The pointers like sound level normalization might be handy next steps, but while the original direct question remains unanswered such pointers are likely to send OP on a tangent. E.g. I came here with same question as OP, and I wish I did not have to dig into the source code. – AnyDev Sep 24 '19 at 01:55