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

Loops in Flowstone

For general discussion related FlowStone

Loops in Flowstone

Postby martinvicanek » Sun May 03, 2020 8:21 pm

Hi stoners,

I put together a little tutorial on loops (as a programming structure, not as repeating audio fragments) in Flowstone. It is quite elementary for now, I might elaborate more if there is interest. Your comments and suggestions are welcome!
Attachments
LoopTut.fsm
Added nested loops
(4.9 KiB) Downloaded 1005 times
Last edited by martinvicanek on Sun May 10, 2020 4:36 pm, edited 2 times in total.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: Loops in Flowstone

Postby tulamide » Sun May 03, 2020 10:12 pm

I can't say anything about DSP and ASM code loops, but I trust your expertise in that regard. I agree on green loops. I strongly disagree on Ruby loops, and hope, you trust my expertise in that regard.

Never use for-loops in Ruby. It's so contrary to the concept of Ruby that it is just bad. A Ruby for-loop actually is amethod of the object class and a very complicated way to do
Code: Select all
range.each
Just try it:
Code: Select all
x = 0
r = for i in 0..9
  x += i
end
Very strange right? Very ugly as well. And so un-Ruby'ish. So what happens here? Well, as a method, a for loop returns an object. r holds the returned object, and it is, as you might have guessed, the range passed to the for method.
Code: Select all
r #will show '0..9' in the inspector pane
x #will show '45'
That it returns a range, gives us a hint on what happens in a for method. For calls ::each, which is a method of the enumerator class. A for method is nothing else but a complicated and slow wrapper of the each method.
Code: Select all
## slow and non-Ruby
x = 0
for i in 0..9
  x += i
end

##fast and Ruby
x = 0
(0..9).each do |i|
  x += i
end


There is a looping method of the object class, however, that is constructed in C (the underlying code base of Ruby) with a for loop.
Code: Select all
x = 0
i = 0
while i < 9
  i += 1
  x += i
end

x #will show '45' in the inspector pane
While does not make use of a block. That makes it a very fast loop. Under certain circumstances faster than ::each. And you can use while much more specific, like this
Code: Select all
x += 1 while x < 10


Since your schematic is a tutorial, you should definitely refrain from using 'for' as a Ruby example!
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Loops in Flowstone

Postby martinvicanek » Mon May 04, 2020 6:31 am

Thanks Tula. I removed the Ruby section.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: Loops in Flowstone

Postby Spogg » Mon May 04, 2020 7:07 am

Many thanks Martin and tulamide!

Whenever I've come across the Green looper I'm always surprised at how fast it seems to run. No idea why...

Cheers

Spogg
User avatar
Spogg
 
Posts: 3358
Joined: Thu Nov 20, 2014 4:24 pm
Location: Birmingham, England

Re: Loops in Flowstone

Postby tektoog » Mon May 04, 2020 11:41 am

Hey,
Thanks Martin! very enlightening with the comments you included ;) :)
"Essential random order for chaotic repetitive sequences"
User avatar
tektoog
 
Posts: 141
Joined: Sat Oct 30, 2010 11:49 pm
Location: Geneva - Switzerland

Re: Loops in Flowstone

Postby BobF » Mon May 04, 2020 1:43 pm

Thanks Martin,

Just what I have been looking for, very well presented . I am trying to learn to use the code box and the more examples I can study the better. This is great, I hope you keep these lessons comming! Anyone else interested in seeing more?

Thanks again, BobF.....
BobF
 
Posts: 598
Joined: Mon Apr 20, 2015 9:54 pm

Re: Loops in Flowstone

Postby RJHollins » Mon May 04, 2020 5:23 pm

Absolutely !
RJHollins
 
Posts: 1571
Joined: Thu Mar 08, 2012 7:58 pm

Re: Loops in Flowstone

Postby HughBanton » Sun May 10, 2020 10:17 am

Hi Martin,

I note in the very last example you said "It has advantages to let the loop counter run backwrds". Interesting .. but I can't see why - can you elaborate?

Afraid I live permanently in FS4 world these days .. don't think any of my stuff works in 3.06 any more. :oops: Wherein (in FS4), you've been able to do variable loop lengths, and indeed nested loops, inside a DSP box for quite a while, I've used both extensively.

Admittedly I invariably rely on hanging a text box onto the DSP box 'S' output to start me off in assem, it's the ideal way to start to learn how assembler works I reckon. Worked for me anyway - it's almost like a built-in tutorial.

Presumably it would be possible to do nested loops in FS3 inside an Assem box?

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Re: Loops in Flowstone

Postby martinvicanek » Sun May 10, 2020 4:37 pm

Thanks guys for your responses. I have added nested loops, refer to the top post.
User avatar
martinvicanek
 
Posts: 1328
Joined: Sat Jun 22, 2013 8:28 pm

Re: Loops in Flowstone

Postby HughBanton » Tue May 12, 2020 8:49 pm

Wowzer!

Some real-life examples would be helpful I expect. If I can get my head around all the pushes & pops, and with Martin's new info, I'll see if any of my earlier efforts can be smartened up enough to be presentable. A simple example I've used a number of times is an interpolator that generates, say, 61 values for a keyboard, derived instantly from the top and bottom note values. (Assembler runs at ludicrous-speed, not at green-speed :shock: ).

When I first moved things into FS4 last year I had several DLL modules in my scheme, almost all of them for generating obscure arrays of one kind or another. Of course they didn't work at first because they were all 32-bit, but I pretty soon discovered I could replace every one of them with 'dsp + signal-analyser pairs' without any of the dll hassle, very much easier. (Have never gone back to dll's).

And .. FS4 allows nested loops inside DSP! Mind you setting such things up directly in assembler like Martin does still looks pretty daunting to me, but I'll keep staring at it until something clicks.

So I basically always rely on the 'S' output from DSP modules to get a working basic assembler code and then proceed from there - MyCo has revised this feature considerably from the 3.0.x versions, his explains what's going on with all the movaps and the xorps much better than in the past.

However I note that in my current nested loops, as produced by FS4, ebx never makes an appearance; any internal loops are always achieved (I think!) by yet more pushes & pops of eax.

I can see that using ebx instead is a major simplification so there's my second challenge right there ....

Oooeck ... :?

H
User avatar
HughBanton
 
Posts: 265
Joined: Sat Apr 12, 2008 3:10 pm
Location: Evesham, Worcestershire

Next

Return to General

Who is online

Users browsing this forum: No registered users and 48 guests