Archive: Adding 'x' millisecond delay between beat and Visualisation reaction


28th September 2006 04:38 UTC

Adding 'x' millisecond delay between beat and Visualisation reaction
Hello fellow AVS user,

I know that the AVS source has been released for a while now, and I was wondering if there is ANY way to ADD an 'x' millisecond delay/lag to the display of the visualization?

The audio coming from my PC is about 100milliseconds slower than the Visuals on the screen, and I was wondering if anyone could tell me how to write a routine/edit the source in order to create a delay in the vis output. Or if such a plugin exists.

Please dont suggest using Line-In and another Winamp/Vis Combo as I cant use that in this case.

I would prefer to have a small input box, where I can set the number of milliseconds for the vis to lag by, or if thats difficult to do, Im happy to hardcode it as a constant and recompile source each time if thats easier for someone to explain 'how to' for me.

Thanks for your time, :)
Ice


28th September 2006 11:18 UTC

Making the change algorithmically is easy, you simply have to cache the oscilloscope/spectrum data and use an n ms old version for the vis plugin. You could do this at the 'entry point' for the library where winamp passes the plugin the data pointers.

The actual implementation isn't hard but requires you to know some API calls and understand C++ in general. You can look these things up for yourself because explaining them all here would be fruitless. Part of being a programmer is looking up libraries and functions and working out what to do with them yourself.


If I were you though I would try to work out why my audio has a delay of 100ms...


28th September 2006 11:41 UTC

Thanks Jheriko.

I know why my audio has a delay - its passing through some VERY tough VST plugins to shape the sound. So I'm not worried about that aspect, infact I WANT it. :)

Regarding using old data... is there any way to make the renderer render 'x' milliseconds late? or is that a harder thing than what you have described?

I do know a little about programming, but I dont have time to learn how to do this right now (although its probably not too complex, its still beyond my knowledge)... If someone was able to do it instead, Id be very grateful. Its not that I dont want to learn, but Ive got to get this project ready so soon :(.


30th September 2006 03:07 UTC

Anyone???

I have DL'ed the AVS source and the Winamp SDK and I have Visual Studio... any hints on how to actually do this?

Thanks
Ice


2nd October 2006 03:22 UTC

which API calls should I look at specifically?


18th October 2006 13:41 UTC

Try QueryPerformanceCounter and QueryPerformanceFrequency. Everything else you need is in the core c++ spec.

Since you sound like you are struggling to think of an algorithm as well:

Create a 'buffer' array to hold the old visdata and the value of the performance counter that needs to be reached when Nms will have passed. this buffer will need to be initialised with Nms of fake data

Store the frequency of the performance counter in some variable, this lets you convert the ugly LARGE_INTEGER into a number of seconds, and hence also milliseconds. This is a constant and doesnt need to be updated

Then in this order per frame:

1.) queryperformancecounter and store the value in some var

1.) store the visdata into the buffer with the necessary number. the number is the stored result above + N*0.001*queryperformancefrequency (which we stored already) which is a minimum value for the return value of queryperformancecounter to return after Nms

2.) check through the stored numbers to see which of them exceeds the current value from queryperformancecounter
then replace this frames visdata with the visdata from the corresponding buffer entry

3.) because of variable framerate 2.) might not always work if we throw away the oldest entry the instant we use it. so we don't discard the oldest buffer entry until the next oldest buffer entry satisfies the test in 2.)

4.) thats it!



Note: I recommended the QueryPerf... functions because they are extremely accurate, most of the other timing API functions have resolutions like 10ms, which is pretty poor for doing anything accurately in realtime. Some of them use ugly methods too, requiring callback functions or message handling.

Hope this helps.



EDIT: I would do it for you but I am at work and its not convenient to build or test here. Maybe when I get home I will come back here and take a look. It does look like it should be a trivial fix.


18th October 2006 14:45 UTC

Thanks Jheriko...

I read ur post and I'm getting a little (a lot) lost in the programming terms. I understand the principle, but I havent done programming since Pascal back in highschool :P. I tried to look for any hints in the Milkdrop forum (as I wanted to make a similar thing for MilkDrop), but I quickly realised that this is over my head. :(

It would be awesome if you had some time to give this a shot.. but your work definitely comes first.

EDIT: Just a thought.... Would it be possible/easier to make a plugin which loaded into winamp as a visualisation and sat between Winamp and the actual VIS. Basically, you select which actual plugin you wanna see in the settings menu in this plugin, and it just passes x millisecond delayed audio/beat data to whatever plugin you chose?

Winamp VIS = Delayer
Delayer[loads 'Actual Vis']

Cheers
Ice


19th October 2006 16:25 UTC

I was really tired when I got home yesterday... I will maybe try to sort something out over the weekend. The plugin idea sounds good, but I'm not exactly sure if it will be that quick to implement... I would need to make some reasonably useful UI for that.


19th October 2006 16:44 UTC

No problem dude. The assistance is greatly appreciated! :)

The UI could just have a box for millisecond delay, and a List box to select which VIS plugin (as per the Winamp Vis directory setting).

Could leave the "settings" part up to the main Vis window in winamp. So they do their setting up by selecting the Actual vis they want, then clicking Configure.... then switch over to the delayer plugin and select that vis within Delayer and off they go.


23rd October 2006 16:17 UTC

I will get around to this!

Like most of the Windows API UI coding is counter-intuitive and involves functions and constants with long, poorly descriptive names that are difficult to remember. Every time I need to make a list box or combo box I have to go and look it up again, because even with resources they managed to f*ck it up somehow. :P

You raise a good point about configuration screens and such though. It would be pretty awkward to handle nicely since the 'configure' button would need to behave specially when clicked. The simple solution would be to make the 'configure' for the delayer display some choice of which vis plugin to use before turning over to the actual plugin's configuration screen/routine.


23rd October 2006 16:33 UTC

Every now and then I think about trying to program this myself...and each time I open the SDK I end up 'dazed and confused'. I dont feel so bad though, as, if you are saying that its a pain in the *ss to do.. then I really had no chance of doing it. :P

Can't wait to see what you come up with.

Cheers
Ice


7th November 2006 08:13 UTC

Jheriko,

Just wondering if you've had any more time to look at this?

Cheers Mate,
Ice


7th November 2006 09:50 UTC

Yeah, in honesty I had forgot. I had devastating computer problems last weekend that sort of distracted me. I'm busy tonight but hopefully I will make a prototype later this week.


17th November 2006 01:09 UTC

Howd the prototype go mate?
Hope you managed to get all your computer stuff fixed.


17th November 2006 10:31 UTC

I'm criminally lazy and have still done nothing :p

Keep doing other things instead... I'll get around to it though. Sorry for being so unreliable. :p


27th November 2006 09:19 UTC

I hear ya!

I'm lazy too.. unless its something for my benefit... then Im super efficient :p lol.

Gimme a buzz when you get around to it.

Cheers


18th December 2006 12:51 UTC

Hey Jheriko,

Just giving you a nudge to let you know Im still around.
I know its getting to the busy part of December so I wont be holding my breath for anything till next year.

Have a good Xmas/New Year
Ice


18th December 2006 13:15 UTC

I hate to be the one to break it to you Icey, but J is never going to get around to doing this.

This whole thread is a complex web of lies and broken promises.


18th December 2006 15:47 UTC

Not really, my computer is still wrecked. I need to replace the failing hard drive still... True, I could have worked on this last week maybe or the week before and it probably wouldn't have taken much effort, but at the moment I don't even have a (good) installation of Visual Studio to work with.. that and it is hard to motivate myself to do something that I don't actually want myself...

I do have a nasty habit of saying I will do something then not doing it though. I really need to stop. So I WILL make this plugin.


18th December 2006 18:38 UTC

lies and broken promises


18th December 2006 20:03 UTC

Originally posted by jheriko
I do have a nasty habit of saying I will do something then not doing it though. I really need to stop. So I WILL make this plugin.
are you sure you're not me? ;)

-daz

20th December 2006 11:19 UTC

Originally posted by jheriko
So I WILL make this plugin.
Heh, in any event, sounds good to me! :)

7th January 2007 04:24 UTC

Hows the plugin coming mate?


7th January 2007 18:56 UTC

Originally posted by PAK-9
lies and broken promises

7th April 2007 06:38 UTC

Guess you guys were right! :(

Anyone else interested in reviving a plugin which can do this?
Ta