sync video output to audio files

Started by abstauber, Tue 09/06/2009 14:15:55

Previous topic - Next topic

abstauber

Hi there,

I've been meditating on this for days and I still can't find a solution, so I hope some of you guys can help me out.

I'd like to play a midifile and like to display it's notes on the screen. Therefore I converted it to a txtfile and read it into a quite big array.

Now my problem is: I don't know how to calculate the speed of the notes. E.g. if the tempo of the songs changes, I need to adjust the graphical output too.

There is a formula:
distance = velocity * time. But I can't figure out the velocity either. Maybe it's something, which comes out as pixels per loop  ???
edit: thx GuyAwesome

I'm definately lost here...
Anyone else who hasn't slep in physics?  ;D


GuyAwesome

#1
I thought it was 'speed = distance / time', e.g. 40 m/s, and velocity is speed with a direction ('the rate at which an object changes position'), e.g 40 m/s east. So, speed and velocity are the same at any given time, so 'velocity * time' would just be distance. I think. I was awake during physics, but it was a long time ago... ::)

Anyway, could you use GetMIDIPosition (returns the current beat of the midi file), and maybe GetGameSpeed (game loops per second) to get the 'distance' into the file and the time taken? Sorry, don't really understand the question, but they seem to be the obvious speed related functions.

Edit, after below:
Ah, I totally misunderstood the question, then. And I don't know enough (anything) about midi files to be any use now I only slighty misunderstand it, sorry.

abstauber

#2
In general I'd only like to display notes on the screen which start to scroll, as the music advances.
I can already display notes right on time, what I can't do is to move them in an appropriate speed.

Right now, I simply increment their x-value with a guessed value which I'd like to calculate in the future.

And of course you're right, s is "Strecke" in german, which means distance. And I kinda rushed my post (which doesn't mean it is solved, yet  ;) )


Trent R

IIRC, Guy is on the right track. Do you have the notes all displayed on the screen? (A screenshot for us perhaps?) What is the distance in pixels between the notes?

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

abstauber

Or maybe I was on a completely wrong track. Everytime a note had to be played, I emitted a particle and simple guessed its speed. But of course, since I know the current track position in milliseconds, I can calculate each note's position again. This way I only need to  define, how many milliseconds, one pixel represents.

So it should be: "current song position" - "time, of the note position" / milliseconds per pixels.

As for the screenshot, think of: guitar hero or frets on fire ;)

abstauber

#5
Sorry, I have to bother you again. My solution somewhat worked, but now the movement of the notes is terribly choppy  :-\

So maybe the speed calculation is still the right track?

Btw. it's only the movement, I'm missing. I already have milliseconds of everything and the gamespeed is set to 40, which means 25 msecs per loop.


update:
I've now found out, that the approach is fine, audiochannel.PositionMs is just updated on a base, I don't understand yet.

If I use my own timer, it works fine - if there weren't that sync issue.

My gamespeed is set to 40, which means:  25 ms per loop. So I have a counter in rep_exec, which increments  25 every loop. So this should be a kind of stop watch.

Here's what happens, when I start playing an audiofile and start my timer at the same time:


After a short time, they get out of sync (lower part). The more I stress my PC in the background, the bigger the gap gets (upper part). Is this supposed to happen?

Still thanks for any help :)

GuyAwesome

It could be that the game isn't quite running at full speed, so your 25 ms/loop calculation is off causing the sync issue. (Especially likely if more 'stress in the background' means bigger sync issues.)
Is there some way to return the actual current running speed, not just the game speed as set? If so, you might be able to use that to change the increment value as needed. That is, var += (1000/FPS) instead of var += 25. Or, I might be barking up the wrong tree entirely.


Pre-emptive Edit after a quick search:
Looks like Scoriorus wrote a GetFPS function you could try, but it's a few years old so you'll have to update the GetRawTime command.

abstauber

#7
Hey, thanks for that function :)

You were totally right, my game's only running at about 37 seconds and can drop down to 20 (I even spotted 2 FPS once).

But when I'm using this function:
var += (1000/FPS)

I'm too fast for the audio playback, the gap just switched sides ;)

edit
I've finally fiddled it out. I now check for the gap and if it gets bigger than 300 ms, I simple reset the timer to the song position again. At least it does the job...

Thank you all for the help (and at least I've learned about FPS).

SMF spam blocked by CleanTalk