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

Math Stereo Reverb and Filter (Ruby)

Post any examples or modules that you want to share here

Math Stereo Reverb and Filter (Ruby)

Postby User108 » Tue May 14, 2024 5:19 pm

Here's a Ruby stereo reverb with some basic low-pas filter..
Attachments
Math Reverb 1.5 stereo.fsm
(102.32 KiB) Downloaded 642 times
HiAsm - A Visual Programming IDE for ALL programming languages:
https://hiasm.com
User avatar
User108
 
Posts: 37
Joined: Thu Apr 18, 2013 9:52 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby User108 » Thu May 16, 2024 12:00 pm

I fixed some bug with nil variables and updated schematics.
HiAsm - A Visual Programming IDE for ALL programming languages:
https://hiasm.com
User avatar
User108
 
Posts: 37
Joined: Thu Apr 18, 2013 9:52 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby Tepeix » Fri May 17, 2024 12:19 pm

That's very impressive to do this with Ruby !
But one drawback specially with this type of effect is that Ruby is slow,
i don't understand what really do your code but i suspect that it take more cpu than a code in assembler or dsp.
On flowstone 3.6 i get 20% cpu, on flowstone alpha 4%.

I get a bug when i use it, a lot of noise. The sound is interresting appart that.
That's maybe because instead of using the ds in primary sound (i don't know how to use this..) i connect a synth to the mono to frame, then i have to connect also a M2f to the synth or there's no sound.

I could see on the scope where seams the problem, that's very strange.
When i play some notes the sound seams normal but after some while, i could see that each 256 samples there's some sample that are zero like they are not calculated, here with a 512 sample scope :
When i play again, the problem disappear then come back..
Attachments
512Sample.png
512Sample.png (508.29 KiB) Viewed 12502 times
Tepeix
 
Posts: 361
Joined: Sat Oct 16, 2021 3:11 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby User108 » Fri May 17, 2024 1:15 pm

Sure DSP or ASM are more appropriate for this kind of processing, but they are not as flexible and easy to understand as Ruby. So it will do for some prototyping. But due to difficulty of DSP \ ASM coding I think some really complex code / processing would neve be created outside Ruby.

Also this code is just to prove a concept and needs improving a lot. For example, I changed this:

Code: Select all
### Feedback ###
@insnd.size.times do |s| # feedback summing
@insnd[s] = @insnd[s] + ( @feedbR[s].to_f * @FeedbackR)
end

to this:

Code: Select all
### Feedback ###
@insnd.each_index { |i| @insnd[i] = @insnd[i] + ( @feedbR[i].to_f * @FeedbackR) } #new algo 16.05.2024


My CPU is at 30%.. 4 Ghz Core i7 but older version.

Also I'm not shure if I should shift array for 256 bits or 255, but I checked frame array size it showed it is 256 elements long, so I used this. I do not notice any glitches using live mic audio, so may be those errors come from your synth.. I also have fed a sinewave instead mic and noticed no distortions to sine..

I will place comments in my code later, I thought it was self-explanatory and easy to understand..
Last edited by User108 on Fri May 17, 2024 1:22 pm, edited 2 times in total.
HiAsm - A Visual Programming IDE for ALL programming languages:
https://hiasm.com
User avatar
User108
 
Posts: 37
Joined: Thu Apr 18, 2013 9:52 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby tulamide » Fri May 17, 2024 3:26 pm

User108 wrote:Sure DSP or ASM are more appropriate for this kind of processing, but they are not as flexible and easy to understand as Ruby. So it will do for some prototyping. But due to difficulty of DSP \ ASM coding I think some really complex code / processing would neve be created outside Ruby.

Also this code is just to prove a concept and needs improving a lot. For example, I changed this:

Code: Select all
### Feedback ###
@insnd.size.times do |s| # feedback summing
@insnd[s] = @insnd[s] + ( @feedbR[s].to_f * @FeedbackR)
end

to this:

Code: Select all
### Feedback ###
@insnd.each_index { |i| @insnd[i] = @insnd[i] + ( @feedbR[i].to_f * @FeedbackR) } #new algo 16.05.2024


My CPU is at 30%.. 4 Ghz Core i7 but older version.

Also I'm not shure if I should shift array for 256 bits or 255, but I checked frame array size it showed it is 256 elements long, so I used this. I do not notice any glitches using live mic audio, so may be those errors come from your synth.. I also have fed a sinewave instead mic and noticed no distortions to sine..

I will place comments in my code later, I thought it was self-explanatory and easy to understand..

It is such a shame that there is no jit compiler in Flowstone to translate Ruby into DSP/ASM. It would make my life so much easier.

Especially as those, who really understand DSP/ASM never teach anything. And so you sit there with their modules full of ASM opcodes, and have no clue what it actually does.

Regarding your code, you could further enhance readability and maintainability, like so:

Code: Select all
@insnd.each_with_index { |obj, i| obj += ( @feedbR[i].to_f * @FeedbackR) }


each_with_index exposes each object of the array, just assign a new value.
obj += is short for obj = obj +
index is still exposed as i
if either @feedbackR or @FeedbackR are already floats, there's no need for explicit conversion .to_f
float * int = float
int * float = float
float * float = float
int * int = int
@FeedbackR is not a valid variable name, as any variable has to be lower case. Upper case is reserved for classes and constants. It is a bad habit to have two variables of the same name. Call one @feedback_r and the other differently, for example @input_feedback_r, but better yet more descriptive names, maybe @feedback_buffer and @feedback_amount

But that's up to you.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Math Stereo Reverb and Filter (Ruby)

Postby User108 » Fri May 17, 2024 6:42 pm

tulamide wrote:tulamide
thank you for your advices. I'm a newbee in Ruby. Rythms great)
@feedbR[i] and @FeedbackR are different - 1-st is a feedback buffer array, and the 2-nd is the feedback level variable. And all two have different names. As to using uppercase for naming input vars - I saw somewhere someone named input var @Frame, so I just followed that example, which nevertheless works just fine.
And I used .to_f conversion of an array because during my experiments with code it showed me some error sayng about nil coercion or something. Although array was not empty. But when I added .to_f error dissapeared..
Last edited by User108 on Sat May 18, 2024 12:19 pm, edited 1 time in total.
HiAsm - A Visual Programming IDE for ALL programming languages:
https://hiasm.com
User avatar
User108
 
Posts: 37
Joined: Thu Apr 18, 2013 9:52 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby tulamide » Sat May 18, 2024 5:12 am

User108 wrote:
tulamide wrote:tulamide
thank you for your advices. I'm a newbee in Ruby. Rythms great)
@feedbR[i] and @FeedbackR are different - 1-st is a feedback buffer array, and the 2-nd is the feedback level variable. And all two have different names. As to using uppercase for naming input vars - I saw somewhere someone named input var @Frame, so I just followed that example, which nevertheless works just fine.
And I used .to_f conversion of an array because during my experiments with code it showed me some error sayng abot nil coersion or something. Although array was not empty. But when I added .to_f error dissapeared..

Yes, I know that they are different, and you basically explained their usage as I laid them out in my example (buffer and amount). But my point is, that you should improve readability, not logic. two variables, of which one is called feedbR and the other FeedbackR might make sense to you specifically. But for people (incl. yourself), who look at the code in a few years, it is just confusing.

Yes, there are quite some bad examples of people using upper case for variables. This is, because the creators of Flowstone had no knowledge of ruby and therefore allowed to automatically convert an input label with an upper case letter at the start into an instance variable. It was never fixed. You can get away with it, when the upper case letter is not at the start or the variable an instance variable. However, when it is at the start you will run into issues, that are hard to track later on. For example, every class, constant, local variable, instance variable, global variable and in some cases even methods automatically generate a so-called symbol. For local variables, Ruby checks for upper case (try removing the "@" in front of FeedbackR). Before I get into any details, I rather suggest to read and use the official Ruby Style Guide, which tells you in detail, what you can and can't use:
https://rubystyle.guide/

Yes, the error disappeared, because you silenced an error. You have a NIL exception in your code, but instead of handling it and fixing the error, you forced Ruby to convert NIL.to_f, which results in 0.0 and doesn't generate an eexception anymore. But the issue is still there. Here's a little article, why it is dangerous to use this type of coercion:
https://solnic.dev/be-cautious-with-ruby-coercion-methods

All in all, Ruby is good at hiding its complexity. That's why we sometimes get into issues, that we wouldn't havem if we were aware of the complexity behind it. So don't worry, it will all come with time. Experience in Ruby will make you better at creating clean code automatically.
"There lies the dog buried" (German saying translated literally)
tulamide
 
Posts: 2714
Joined: Sat Jun 21, 2014 2:48 pm
Location: Germany

Re: Math Stereo Reverb and Filter (Ruby)

Postby Tepeix » Sat May 18, 2024 11:45 am

Hum, it could not be the synth i use. That's the vsti prim a very simple one,
it worked with ton of stuff and never fail.
I made another test creating a vst with it and trying it with Lmms getting the same noise.

I don't know much about the mono to ruby voice thing, but maybe there's something in your code that set the size of the buffer, making an error when a computer have another size ?

Sorry to give bad new, but they might be a way to fix this or if there's not we might ask Myco to fix it on alpha.

oups, sorry for the anotation in assembler, once we learn and use it we forget how much it looked chinese before.
Also it's not easy because everything might be done with register. Once we do a calculation it's no more a variable with a clear name but a xmmx or a eax, ebx, and even more with alpha.. So we forget that xmm1 was a+b.
I have problem myself when coming back after a while to a code.
Tepeix
 
Posts: 361
Joined: Sat Oct 16, 2021 3:11 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby User108 » Sat May 18, 2024 12:17 pm

tulamide, i totally agree with you, and thank you for sharing your knowledge. I'll try to keep to Ruby specs, and try to fix my code.
Tepeix, yes may be your DS buffer differs from mine which is 256. Try experimenting with array.shift(256) method and put there some other buffer length and see if if fixes your distortion. Also, could you share your schematics to reproduce that?
HiAsm - A Visual Programming IDE for ALL programming languages:
https://hiasm.com
User avatar
User108
 
Posts: 37
Joined: Thu Apr 18, 2013 9:52 pm

Re: Math Stereo Reverb and Filter (Ruby)

Postby Tepeix » Sat May 18, 2024 4:44 pm

Here it is.
I tried other number and also "@insnd.size" but is what not better
Attachments
Math Reverb 1.5 stereo with synth.fsm
(147.21 KiB) Downloaded 608 times
Tepeix
 
Posts: 361
Joined: Sat Oct 16, 2021 3:11 pm

Next

Return to User Examples

Who is online

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