Previous topicNext topic

Oscilloscope fully in Magic

Questions, comments, feedback, etc.
Post Reply
tongleiter
Posts: 7
Joined: Sat Dec 17, 2016 11:04 am

Oscilloscope fully in Magic

Post by tongleiter »

Dear Magic community

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

Cheers,
Silvan
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Oscilloscope fully in Magic

Post by artnik »

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/sha ... 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.
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

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 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 605 times
XY Oscilloscope2b.fs
My quick hack of https://www.shadertoy.com/view/4tdXzX
(3.14 KiB) Downloaded 581 times
eg xy scope.magic
Example Magic project. Will need audio input to be specified in the Audio/MIDI Window.
(1.68 KiB) Downloaded 652 times
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

... 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 14026 times
artnik
Posts: 268
Joined: Tue Jan 05, 2016 5:33 pm

Re: Oscilloscope fully in Magic

Post by artnik »

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;
}
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

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 628 times
TEHK
Posts: 56
Joined: Mon Mar 12, 2018 9:04 pm

Re: Oscilloscope fully in Magic

Post by TEHK »

Found this post incredibly useful !! THANK YOU!
I borrowed the oscilloscope code to create a video for my latest mix:
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

TEHK wrote: Wed Feb 28, 2024 1:49 pm Found this post incredibly useful !! THANK YOU! ...
You're welcome! It's by far my favourite effect.

Thanks for the thanks! :D
377 downloads and yours is the first in seven years!

I really like your mix. I'm going to find it (and your other podcasts) a very inspiring source of audio when I'm working on Magic effects, and I'm very glad the 'scope module is useful for your videos. I love using waveforms to accompany music, and I'm certain you can develop this more - imho it really suits the type of music I hear on your YouTube channel.

Here's an example, made to accompany one of my son's remixes. You'll recognise the centre element! All done in Magic.
TEHK
Posts: 56
Joined: Mon Mar 12, 2018 9:04 pm

Re: Oscilloscope fully in Magic

Post by TEHK »

Terry Payman wrote: Thu Feb 29, 2024 5:01 pm
TEHK wrote: Wed Feb 28, 2024 1:49 pm Found this post incredibly useful !! THANK YOU! ...
You're welcome! It's by far my favourite effect.

Thanks for the thanks! :D
377 downloads and yours is the first in seven years!

I really like your mix. I'm going to find it (and your other podcasts) a very inspiring source of audio when I'm working on Magic effects, and I'm very glad the 'scope module is useful for your videos. I love using waveforms to accompany music, and I'm certain you can develop this more - imho it really suits the type of music I hear on your YouTube channel.

Here's an example, made to accompany one of my son's remixes. You'll recognise the centre element! All done in Magic.
Some pretty interesting uses of Magic in the videos you have, thanks for sharing them -- sure to give me some more inspiration!

Just dropped in to share that the oscilloscope works REALLY well on square videos as in this one...
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

Thanks!

A square format also works really well for the Waveform module in Circle mode.

Many of my projectors are 4:3 aspect ratio, some are 16:9 or 16:10.
I sometimes stretch a circular scene horizontally to fit the wider display, giving an oval shape. This too also works well imho.
sameloop
Posts: 41
Joined: Thu Oct 27, 2016 5:58 pm

Re: Oscilloscope fully in Magic

Post by sameloop »

Terry Payman wrote: 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.
Hi there. Sorry for a stupid question, but I can't work out how to actually make this (XY Oscilloscope2b.fs) work with audio...I've got the module up in MMV, but not sure how to proceed. Thanks for any help! Cheers.
Terry Payman
Posts: 720
Joined: Sun Sep 14, 2014 8:15 am
Location: UK
Contact:

Re: Oscilloscope fully in Magic

Post by Terry Payman »

See my post(s) above.
There's a screenshot showing how to pass audio to the oscilloscope module.

viewtopic.php?p=5129#p5129
sameloop
Posts: 41
Joined: Thu Oct 27, 2016 5:58 pm

Re: Oscilloscope fully in Magic

Post by sameloop »

Oh, thanks so much - sorry, I didn’t see that! Cheers.
Post Reply