Add up two or more sinewaves together?

Fri Jun 04, 2021 11:23 am

Hey guys, i'm new and struggling with a simple task: mix two or more waveforms. I didn't find any math modules so i'm wondering if it's possible? Thanks
Attachments
Screenshot 2021-06-04 at 6.21.10.png
Screenshot 2021-06-04 at 6.21.10.png (373.26 KiB) Viewed 133 times
nick
 
Posts: 2
Joined: Sun May 30, 2021 2:32 pm

Re: Add up two or more sinewaves together?

Fri Jun 04, 2021 3:27 pm

This is somewhat outside my experience. I think someone else on this forum is likely to be able to help directly with this, but AFAIK and FWIW:

There's no math function plotting module native to Magic, so you can't plot the sum of two sines without finding or writing an add-in module.

Magic's support of ISF modules greatly facilitates the creation of custom functionality, and the following link has an example of plotting using GLSL (the language wrapped by the ISF format) https://yiwei.dev/function-plot-with-glsl/

With ISF it's easy to add adjustable/linkable parameters, so you could have variable frequency and phase for each of two (or more) sinewaves or specify a larger number of parameters for a different function.
Terry Payman
 
Posts: 620
Joined: Sun Sep 14, 2014 8:15 am
Location: UK

Re: Add up two or more sinewaves together?

Fri Jun 04, 2021 6:20 pm

Terry is right that the best way would be to put together a shader/ISF that takes two or more frequencies. However, you can do it directly in Magic with a few nodes. Dissect the attached.
add-waves.magic
(1.61 KiB) Downloaded 18 times
Sadler
 
Posts: 846
Joined: Sat Aug 02, 2014 7:10 pm
Location: London, UK

Re: Add up two or more sinewaves together?

Fri Jun 04, 2021 9:05 pm

Sadler has an elegant and ingenious solution, as is so often the case.

As a personal challenge I had an attempt at an ISF module (SineWaveDual.fs, attached) .
The default settings appear to be a single sinewave, but actually it's two summed together. Adjust Sine 2 Freq & Sine 2 phase to see.
I'm sure someone with better maths could add other functions, but I barely understood what was going on so my approach was somewhat empirical.
My changes were almost entirely confined to replacing "Function(float x)"

I'd tried using the plotting routine in my previous link, but couldn't get it working (doubtless due to a combination of ignorance and carelessness).
As an alternative I searched Shadertoy for "plot" (https://www.shadertoy.com/results?query=plot), and chose https://www.shadertoy.com/view/3sKSWc as a basis for development. It would be safe to assume that Shadertoy's default non-commercial licence applies to my derived version.

Vidvox's excellent ISF editor https://isf.vidvox.net/desktop-editor/ can import and convert many Shadertoy shaders , as can Magic's script https://magicmusicvisuals.com/utils/shadertoy_to_isf.php

In this case I imported using Magic's script, then added the controls and re-wrote a function using the ISF editor (which has excellent syntax checking).

The Speed control on this module currently has no effect. The Line Width adjustment was simply a quick hack, I'm sure it can be done better.
FWIW this module feeds nicely into the Circle Wrap Distortion ISF module.
Attachments
SineWaveDual.fs
A hacked version of https://www.shadertoy.com/view/3sKSWc, displaying the sum of two sine waves.
(3.74 KiB) Downloaded 15 times
Terry Payman
 
Posts: 620
Joined: Sun Sep 14, 2014 8:15 am
Location: UK

Return to General Discussion

© 2021 Color & Music, LLC • This web site is mobile-friendly