Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

DSP Code: Why Can't I Multiply a Streamin?

For general discussion related FlowStone

DSP Code: Why Can't I Multiply a Streamin?

Postby Perfect Human Interface » Wed Apr 17, 2013 10:38 pm

So I was putting together a bit of DSP code, and everything was working perfectly, but I realized that my code took an input range of 0-2 and I thought it might be nice to change that to 0-1.

Simple solution was to multiply the input by 2 and call it good.

So with my variable declared as "streamin x;"
I wrote the code "x = x * 2;"

And at that point the code self destructed, outputting a signal of infinite amplitude or something. I did not feed it an input value out of range (0-1). Why would it do this? Is it creating an infinite loop? I don't see how that's possible since the operation should only be performed the one time every time the code runs through and as far as I know values aren't remembered by the code after ever step. Commenting out this line makes it work as expected again.

Anyone know? Thanks.
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: DSP Code: Why Can't I Multiply a Streamin?

Postby nix » Thu Apr 18, 2013 3:17 am

Yeah, I think it creates a counter of some description, it feeds back.
Here is a code that you can use->
mult.fsm
(893 Bytes) Downloaded 898 times

just name the answer a different thing than the multiplier
User avatar
nix
 
Posts: 817
Joined: Tue Jul 13, 2010 10:51 am

Re: DSP Code: Why Can't I Multiply a Streamin?

Postby Perfect Human Interface » Thu Apr 18, 2013 9:14 am

Thanks for posting; I'll check that out later.
You know you could have just pasted the code in the forum too. :)
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm

Re: DSP Code: Why Can't I Multiply a Streamin?

Postby trogluddite » Sat Apr 20, 2013 8:40 pm

This problem has come up a few times over at the SM site in the past.
The simple rule to follow is this...

Never write to a streamin variable - i.e. treat them as 'read-only', and don't try to change their values within your code, always put the result into a different variable.

streamouts are much more robust - you can change them as many times as you like within a code block, and only the final value will be seen by 'the outside world'.

This is to do with the way that SM/FS works internally - the streamin's and streamout's are not truly 'local' variables. Rather than the input value from a link being 'copied' into the streamin variable, inputs, outputs and links work by sharing a common memory address between them (in the simple case of a single link).
So if you change the contents of a streamin variable, you are also changing the value of an incoming link, and possibly the value of streamout variables of preceding modules.
Very weird - I guess it saves a good few CPU cycles copying all those values around - but there's been quite a few cases of folks chasing their tails looking for bugs in their code because of this one!
All schematics/modules I post are free for all to use - but a credit is always polite!
Don't stagnate, mutate to create!
User avatar
trogluddite
 
Posts: 1730
Joined: Fri Oct 22, 2010 12:46 am
Location: Yorkshire, UK

Re: DSP Code: Why Can't I Multiply a Streamin?

Postby Perfect Human Interface » Sun Apr 21, 2013 1:23 am

Thanks Trog! Will remember that. :)
Perfect Human Interface
 
Posts: 643
Joined: Sun Mar 10, 2013 7:32 pm


Return to General

Who is online

Users browsing this forum: Google [Bot] and 89 guests