Unsigned multiplication problem

If you have a simple question and just want an answer.
User avatar
Mitchell
New User
Posts: 3
Joined: Mon May 19, 2014 3:25 pm

Unsigned multiplication problem

Post by Mitchell »

I am modifying the app_simple_avb_demo in order to do some sample processing at the end points. I am currently doing this in the media_output_fifo_to_xc_channel_split_lr method, contained in the media_output_fifo_support.xc unit. What I am trying to do is scale down audio samples that are received from the channel (as unsigned integers). It seems that floating point numbers are unavailable in XC so the way to achieve this is integer multiplication, followed by integer division. When I do multiplication on an unsigned integer, it results in an excessively large, unexpected result.

Does anyone have any recommendations about fixing this? I will post a screenshot of sample code showing the result of an example of this multiplication.

Thanks, Mitch
You do not have the required permissions to view the files attached to this post.


User avatar
Ross
XCore Expert
Posts: 968
Joined: Thu Dec 10, 2009 9:20 pm
Location: Bristol, UK

Post by Ross »

Sounds essentially like you are trying to program a volume control?

Sounds like you might want you use the macs...

{h, l} = macs(mult, sample, 0, 0);
 
 
 
User avatar
Mitchell
New User
Posts: 3
Joined: Mon May 19, 2014 3:25 pm

Post by Mitchell »

It's not the overflow that is causing the issues, there is something going wrong in the actual multiplication process. Here is a section of simple code that describes a few test situations, with outcomes. This works fine in a simple program but does not behave the same in the context of the XMOS AVB implementation.

signed int i1,i2,i3;
unsigned u1,u2,u3;
u1 = 0;
u2 = 0;
u3 = 0;
i1 = (40 * 10); //400
u1 = (unsigned)i1; //912
i2 = (50*10); //500
u2 = (unsigned)i2; //1012
i3 = (60*10); //600
u3 = (unsigned)i3; //1240
regards,
Mitch
peter
XCore Addict
Posts: 230
Joined: Wed Mar 10, 2010 12:46 pm

Post by peter »

This is a bug in the debugger. I will file an issue internally. If you do the following instead of printf("a"):

Code: Select all

printintln(test1);printintln(test2);
then you will find that the value is correct for both. The compiler will often optimise the code away since you are not using test1 or test2 in any following statement there is likely to not be any code associated with those two source lines. The debugger should have said that it can't find the variable if it has been optimised out, not just give an incorrect value.