- AVS
- Help with Code! on/off detection
Archive: Help with Code! on/off detection
spyduck
24th July 2003 01:09 UTC
Help with Code! on/off detection
Let me first say that Ive been studying AVS through Jheriko's Hi-RES, AVS pack and the things I am learning are incredible!
Anyways, I was attempting a remix of "Jheriko - HiRES - Warped"
AVS preset, and I wanted a way to stop certain renders when the music stopped, so this is my code to get a 0 (meaning music is stopped)
or 1(music is still going). Please tell me if im being incredibly foolish and oversighting something.
--------------
In superscope
Per Frame: on=above(abs(v),0);
--------------
I am sure this is somewhat wasteful as its im doing one assignment, a comparison, and an absolute value operation more than 30 times a second.
attached is my Remix of the amazing jheriko's "Warped" from his Hi-Res pack. Try stopping and playing the music. Am i doing this on/off thing correctly?
Jaheckelsafar
24th July 2003 04:08 UTC
Well, v is a point variable. It's the level at acertain point on the spectrum or osciliscope. Your best bet would probably to get the data using getosc() or getspec(). Just make sure you grab data from a wide enough spectrum.
anubis2003
24th July 2003 04:17 UTC
Or you could put it in the POINT box, depending on how high the n value is - that may be better than using many getosc's.
sidd
24th July 2003 07:11 UTC
something like
on=if(getosc(0,1,0),1,0)
you can use the getosc and getspec commands in perframe, as they dont operate using point data.
dirkdeftly
24th July 2003 09:13 UTC
this won't work because of a very small bug in avs that causes *any* signal to raise getosc very slightly. (or lower it, i actually don't know the exact amount.) so if anything is playing - and thus any signal being sent to avs - then your switch will be on. point being that if anything it should be getspec(0.5,1,0), and that might not even work. however, i don't really think that it should be a straight on/off switch because it would do the same thing for very quiet as very loud...which isn't exactly reactive. *unless* you're turning a scope off when there's no music. the only problem with this is that you get fps spikes when you turn a song off; you'll have to decide for yourself if that's acceptable in your preset or not.
sidd
24th July 2003 10:47 UTC
ok, how about on=above(getspec(0,1,0),0.01)
im not sure what you meant excactly, but i cant see how getspec(0.5,1,0) would do anyhting of use, seeing as the bands are between 0 and 1 only, and this looks for 0.5 -> 1.5
And i think he is looking for a way to turn the scope off completely , only when there is no sound, not necessairly no mp3 playing, if you follow. Its just meant to be a switch, not a thing to make a scope more reactive.
spyduck
24th July 2003 11:41 UTC
As of right now, the above(abs(v),0) is doing the job in my per frame box, if you care to look at the preset i included the scopes have a reaction, but then sometimes during a techno song when if for some reason the music gets all quiet (like, say the interlude or whatever u call it part) then all of sudden the abs(v) is 0 and then the on code triggers so you have a moment of inactivity.
anubis2003
24th July 2003 12:16 UTC
Yeah. Actually, it should work. It's taking the v value for the last pixel drawn during the last frame. It will have a little [unnoticable] lag, but above(abs(v),0) should work.
UnConeD
24th July 2003 12:48 UTC
I am sure this is somewhat wasteful as its im doing one assignment, a comparison, and an absolute value operation more than 30 times a second.
You're kidding right? 30 times a second... as opposed to a 100 point scope's code which gets executed 3000 times per second, or a 20x20 DM which is executed 12000 times per second?
If you really want to and you don't need the beat-detection (or have your own), you could set up a custom BPM and use the onbeat code instead (it's only executed as often as you set it).
Magic.X
24th July 2003 13:21 UTC
Why dont you do this:
init
n=600; val=0.05;
per frame:
m=if(below(val,Abs(Ev/n)),2,0); Ev=0;
per point:
x=i*2-1;
y=v/2+m;
Ev=Ev+v;
This will sum up all v's for one frame. If this is below a certain tolerance value then the scope is drawn outside the visible area (no fps spikes);
Just alter this to your needs.
spyduck
24th July 2003 14:22 UTC
Originally posted by UnConeD
You're kidding right? 30 times a second... as opposed to a 100 point scope's code which gets executed 3000 times per second, or a 20x20 DM which is executed 12000 times per second?
If you really want to and you don't need the beat-detection (or have your own), you could set up a custom BPM and use the onbeat code instead (it's only executed as often as you set it).
I was also thinking of that too, by putting in the on selector
in the onbeat code, but the details of making that worked escaped me.
the way i concieved of the onbeat code was this
init: on=0;
on beat :adjust on value on v
so starting the preset will synch with the music, but then if you stop the song, the on beat detection code won't trigger..unless you mean the arbitrary custom bpm, which yea, that would work, but then i would have to add in a custom bpm to run, im not so sure im better off now since i have no idea how many cycles the custom bpm is.
jheriko
24th July 2003 14:23 UTC
You could get avs to do the summing for you internally per frame (or beat) with a getspec(0,0,0) checking if this is below a small value would be a good way to see if the music is 'playing' or not.
e.g.
on=above(getspec(0,0,0),0.02);
Its nice to see that someone enjoys my HiRes bonus pack and has learned something from my usually incomprehensible code.
Magic.X
24th July 2003 14:48 UTC
Getspec'ing one point in spectrum won't get a good result.
You could set getspec(0.5,1,0) to get a broadband value of the music actually playing.
jheriko
24th July 2003 15:34 UTC
i heard that getspec(0,0,0) is the volume. can't remember where... i've been using it as if it were for ages.
sidd
24th July 2003 18:22 UTC
getspec(0,1,0) is volume.
It takes an average of all the available bands.
and why does everyone keep using getspec(0.5,1,0)?
^means that 0.5 is the start of a sample with width 1.
in otherwords, its getting data from 0.5 -> 1.5.
trying to get band data from outside 0->1 returns nothing.
the code should be getspec(0.5,0.5,0) (pretty much useless) or getspec(0,1,0)
unless im missing something, in which case i humbly appologise.
dirkdeftly
25th July 2003 02:05 UTC
umm
since when does getspec(a,b,c) average a..a+b? i'm damned sure it's a-b/2..a+b/2.
sidd
25th July 2003 06:16 UTC
hmm.. damned if i can think of a sure way to check this.
You could well be right, it does make sense.
Ive been using the other way since i started, and ive never run into a problem with it.
Magic.X
25th July 2003 06:49 UTC
This is because you take a range from -0.5 to +0.5 then. But as the major sound generated is within this range (bass and middle range) it works as well although its not really perfect.
Btw, i got this explanation out by searching the Forums. I think UCD told this once.
sidd
25th July 2003 17:21 UTC
:) thanks
Shock Value
25th July 2003 18:57 UTC
Personally, I usually do something like this:
Per Frame:
gg=gg*.925+abs(getosc(.5,1,0))*.075;
on=above(gg,.005)
This way you get some time to make sure that the music is really stopped if there happens to be some momentary silence during a song. Otherwise, the render will stop even if there is a period of silence in the milliseconds, which would make the scope look like it's blinking.