[Asterisk-Users] RX/TXgain on bristuff/zaptel ?

Michael Neuhauser mike at firmix.at
Fri Jan 20 12:27:37 MST 2006


On Thu, 2006-01-19 at 03:15 +0100, Pisac wrote:
> I compiled it, and it's WORKING. 
> Thanks.
>  
> But, I would realy realy realy like that somebody explain to me how is
> exactly that bug hidden in those two segments? Where is difference? 
> Anybody?
>  
> 1)
> if (!IS_DIGITAL(ast->transfercapability)) {
> set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain, p->txgain,
> p->law); 
> } else { 
> set_actual_gain(p->subs[SUB_REAL].zfd, 0, 0, 0, p->law); }   
>  
> 2)
> if (IS_DIGITAL(ast->transfercapability)) {
> set_actual_gain(p->subs[SUB_REAL].zfd, 0, 0, 0, p->law); 
> } else {
> set_actual_gain(p->subs[SUB_REAL].zfd, 0, p->rxgain, p->txgain,
> p->law); }   

The problem results from the way the IS_DIGITAL() macro is defined in
include/asterisk/transcap.h:

	#define IS_DIGITAL(cap)\
        	(cap) & AST_TRANS_CAP_DIGITAL ? 1 : 0

So the expression

	!IS_DIGITAL(foo)

expands to

	!(foo) & AST_TRANS_CAP_DIGITAL ? 1 : 0

which is equivalent to

	( !(foo) ) & AST_TRANS_CAP_DIGITAL ? 1 : 0

while one would like to have

	!( (foo) & AST_TRANS_CAP_DIGITAL ? 1 : 0 )

Rewriting the original statement removes the "!" operator and everything
is fine.

The two "if" statements would be equivalent (and both correct) if the
definition in transcap.h followed best practices to avoid problems with
operator precedence and looked like this:

	#define IS_DIGITAL(cap)\
        	((cap) & AST_TRANS_CAP_DIGITAL ? 1 : 0)

Regards,
	Mike

-- 
Dr. Michael Neuhauser                phone: +43 1 789 08 49 - 30
Firmix Software GmbH                   fax: +43 1 789 08 49 - 55
Vienna/Austria/Europe                      email: mike at firmix.at
Embedded Linux Development and Services    http://www.firmix.at/




More information about the asterisk-users mailing list