Oscilloscope fully in Magic

Tue Jan 03, 2017 9:13 am

Dear Magic community

Did anyone of you manage to create an oscilloscope fully in Magic? If yes, how do you do it?

Cheers,
Silvan
tongleiter
 
Posts: 7
Joined: Sat Dec 17, 2016 11:04 am

Re: Oscilloscope fully in Magic

Tue Jan 03, 2017 4:26 pm

There are a couple of implementations of this at Shadertoy.com when you search for "oscilloscope":


Both of these should be convertable to V1 ISF with Eric's "Shadertoy-to-ISF" script, with minor tweaking: https://magicmusicvisuals.com/utils/shadertoy_to_isf.php

If you haven't messed with ISF scripting yet using this script and the live editor at http://www.interactiveshaderformat.com, it's a valuable skill to pick up. If you give it a go and run into issues, myself or someone else may be able to help. I'm just jammed today and can't give it a go right now.
artnik
 
Posts: 264
Joined: Tue Jan 05, 2016 5:33 pm

Re: Oscilloscope fully in Magic

Thu Jan 05, 2017 11:06 am

tongleiter wrote:..How did you manage to create the centered-animation (in red) from the video you have posted on vimeo - it looks much like an oscilloscope to me.. (in the external application "Shadertoy" I guess)?
(ref https://magicmusicvisuals.com/forums/viewtopic.php?f=4&t=1103#p5012 onwards)

I did indeed start my experiments in the Shadertoy environment, modifying https://www.shadertoy.com/view/4tdXzX. I then converted to ISF as detailed by Artnik, added the extra parameters and incorporated the mods I had tried in Shadertoy.

Here are the source files for my basic Magic project. The two ISF modules will need to be installed in an Additional Module Folder (see User's Guide). Audio input will need to be specified in the Audio/MIDI Window.

My XY Oscilloscope2b.fs module was just a very quick hack. I need to do more work on this (contributions welcome!) - especially in the light of the subsequently posted https://www.shadertoy.com/view/XttSzf that artnik found which I want to compare to the original https://www.shadertoy.com/view/MsXGDn
Attachments
Edge Blur.fs
A useful blur from the VidVox ISF collection at http://vidvox.net/rays_oddsnends/ISF%20files.zip
(5.14 KiB) Downloaded 224 times
XY Oscilloscope2b.fs
My quick hack of https://www.shadertoy.com/view/4tdXzX
(3.14 KiB) Downloaded 206 times
eg xy scope.magic
Example Magic project. Will need audio input to be specified in the Audio/MIDI Window.
(1.68 KiB) Downloaded 236 times
Terry Payman
 
Posts: 597
Joined: Sun Sep 14, 2014 8:15 am
Location: UK

Re: Oscilloscope fully in Magic

Thu Jan 05, 2017 11:08 am

... ref above, as I couldn't add this image as a fourth attachment.

Edit: I had made a few variants of the XY 'scope with different sample lengths as it seems impossible to have a variable length for-loop in GLSL. I settled for having a fixed "variable" to identify each variant clearly.

Smaller loops will give faster rendering, but at the expense of image quality. This is a very inefficient shader, and even my very fast GPU (GTX 1070) is heavily loaded.

In the ShaderToy environment I believe there is a "correct" setting for the ReturnTuning if one wishes to accurately plot the left audio channel against the right, but I don't think that's applicable in the Magic environment as AudioToImage presumably has a single channel output to match its single channel input.
Attachments
eg XY scope.jpg
eg XY scope.jpg (72.31 KiB) Viewed 3076 times
Terry Payman
 
Posts: 597
Joined: Sun Sep 14, 2014 8:15 am
Location: UK

Re: Oscilloscope fully in Magic

Thu Jan 05, 2017 5:10 pm

Variable FOR LOOPs are not impossible. :-)

In the header JSON, define a FLOAT that has the range of the number of loops you want. So in the following example NumSamples has a max value of 1000, and so the FOR LOOP is initialized with that. Then, you insert a break condition into the loop.

As far as I know, FOR LOOPS are unrolled on the GPU, in this case, it will unroll all the iterations as a monolithic chunk of code, but you can break out of it. Not the most elegant approach perhaps, but it works around the limitation of loops needing to be defined as a fixed length.

for( int i=0; i<1000; i++ )
{
if ( i > int (NumSamples) ) { break; } // The Magic happens here. :-)
YOUR CODE HERE;
}
artnik
 
Posts: 264
Joined: Tue Jan 05, 2016 5:33 pm

Re: Oscilloscope fully in Magic

Sat Jan 07, 2017 9:41 am

artnik wrote:Variable FOR LOOPs are not impossible... you can break out...


Thanks artnik, very effective :D

Updated version attached. Sample count can now be varied to facilitate tradeoff between resolution and speed.
Attachments
XY Oscilloscope2b.fs
Updated version, using artnik's technique to give adjustable sample count.
(2.86 KiB) Downloaded 224 times
Terry Payman
 
Posts: 597
Joined: Sun Sep 14, 2014 8:15 am
Location: UK

Return to General Discussion

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