• Welcome to Dark Bit Factory & Gravity.
 

[C++/SDL/OpenGL/BASS] Help with Synchronizing video and audio

Started by S0lll0s, April 04, 2013

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

S0lll0s

I am starting my first (2d) demo now, and I get along pretty well except for major synchronization problems.

I do not have a graphics timer, I base all my graphics on the current audio time as I only play a mp3 for my first demo.

The libraries I use are SDL with OpenGL and BASS as an Audio Library. I am creating my own engine from scratch.
The music for my demo is Awolnation - Sail, so you should go ahead and obtain a mp3 of that song (legally of course) and put it as sail.mp3 in the binary folder if you want to test it.

I know that Sail is 119 BPM and my Syncing works pretty well for the first ~50seconds, but then it slowly drifts off and gets really bad. It should draw a green Hexagon every when the kick starts (and every 2nd bar before that too).

This is how I check if the kick just kick'd:

       int millis = (int)( time * 1000.0f ); //time is the playback pos in seconds (double)
        int everyX = (int)( 119.0 / 60.0f * 1000.0f ); //everyX is the time it takes for a bar to pass
       
        if ( ( millis + everyX / 4 + everyX ) % ( everyX * 2 ) < 80 ) //The song starts with an offset and I want every 2nd bar
            return true;


-
For another question, how do I draw "thick" lines in OpenGL? And after that, how do I do 90° turns with those and make them grow?

Really looking forward to any help,
S0lll0s

hellfire

Quotemy Syncing works pretty well for the first ~50seconds, but then it slowly drifts off and gets really bad.

Hi S0lll0s,

I picked the track from youtube (this) and opened it in some random wave editor.
The track starts at 0.175s.
Between 33.424 and 65.692 are exactly 8 sequences, makes 4.0335 seconds per sequence.
Let's assume 8 beats per sequence (which results in 119.003 bpm).
Now I simplified your main loop to the following:

  float nextBeat= 0.175f; // start of the track
  float secondsPerBeat= 4.0335f / 8.0;

  while( true )
  {
    ...
   
    glClear( GL_COLOR_BUFFER_BIT );
     
    musicTime = BASS_ChannelBytes2Seconds( sailMusic, BASS_ChannelGetPosition( sailMusic, BASS_POS_BYTE ) );

    if (musicTime >= nextBeat)
    {
         nextBeat += secondsPerBeat;
         callback2();
    }

    SDL_GL_SwapBuffers();
  }


And a green hexagon is flashing to the beat.
Should be possible to get the rest working from here on.


Quote from: S0lll0s on April 04, 2013
how do I draw "thick" lines in OpenGL?
You call glLineWidth with the desired width.

Quote from: S0lll0s on April 04, 2013
And after that, how do I do 90° turns with those

???  ???

Quote from: S0lll0s on April 04, 2013
and make them grow?

;D  ;D
Challenge Trophies Won:

S0lll0s

Quote from: hellfire on April 07, 2013
Quotemy Syncing works pretty well for the first ~50seconds, but then it slowly drifts off and gets really bad.

Hi S0lll0s,

[...]
And a green hexagon is flashing to the beat.
Should be possible to get the rest working from here on.
Thank you, I moved on with the graphics but synchronization still didn't work, I will try this now.

Quote from: hellfire on April 07, 2013
Quote from: S0lll0s on April 04, 2013
how do I draw "thick" lines in OpenGL?
You call glLineWidth with the desired width.
Quote from: S0lll0s on April 04, 2013
And after that, how do I do 90° turns with those
I meant curves that look smooth, like the grey in this one:


Quote from: hellfire on April 07, 2013
Quote from: S0lll0s on April 04, 2013
and make them grow?

;D  ;D
[/quote]
okay, I by growing I mean starting very short and progressively get longer. This is of course easy for straight lines, but how do I do this with the 90° curved ones?

hellfire

Quote from: S0lll0s on April 08, 2013
I meant curves that look smooth, like the grey in this one:

Curves are usually drawn by subdividing the round parts into many small line segments.
The more segments you use, the smoother it looks.
In your case it's probably enough to keep a bit of space between two lines and connect them with a quarter of a circle.
You might want to look up splines, too.

Quote from: S0lll0s on April 08, 2013by growing I mean starting very short and progressively get longer.
Well, I guess you're already able to draw a short line and a long line.
So I'm pretty sure you can draw any length in between, too...
And what you're asking for is varying the length over time.
Challenge Trophies Won:

S0lll0s

Quote from: hellfire on April 08, 2013
Quote from: S0lll0s on April 08, 2013by growing I mean starting very short and progressively get longer.
Well, I guess you're already able to draw a short line and a long line.
So I'm pretty sure you can draw any length in between, too...
And what you're asking for is varying the length over time.
quote author=S0lll0s link=topic=5995.msg79273#msg79273 date=1365427656]This is of course easy for straight lines, but how do I do this with the 90° curved ones?[/quote]

Anyways, thanks for that link. I tried to find a good introduction to splines and this seems worth the read, I could only find spline librarys and extremely mathematical info.

hellfire

Challenge Trophies Won: