Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (480)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (546)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sound Synchronization  (Read 1715 times)
0 Members and 1 Guest are viewing this topic.
Offline Andrew2718

Junior Newbie





« Posted 2003-08-15 12:18:27 »

I'm trying to get sound and graphic synchronization when playing music using a SourceDataLine - the Java code is a sound editor I wrote over 2 years ago and I'm updating it to be more useful since I failed to work this out 2 years ago and I'm now trying to get it to work
Although this isn't a game, no doubt in a game you would want to be able to sychronize graphic events during a sound being played - so hopefully someone here knows the answer ...
I have graphic views of each wave being played and want to run a bar across the graphics as it is playing
Other than synchronization, everything works fine.
The bar is drawn by a separate thread that loops doing: delete the old bar, get the position of the new bar, draw the new bar then sleep 100ms
I've tried:
1) line.getFramePosition() or line.getMicrosecondPosition() but they appear to NOT be based on audio output, rather they seem to be the value of data written to the line
2) process a full buffer first, call line.start() then get System.currentTimeMillis() then write each buffer - in the loop use currentTimeMillis() to get the current time offset from start of audio ouput - this produces two results - sometimes it's very close to sync and other times it's out (audio behind sync) by the same amount
3) use a LineListener to catch START and get System.currentTimeMillis() as the time that audio output started - but in the START LineEvent the current frame is either around 500 (audio is behind by about 250ms) or around 4000 (sync almost correct) but for 44.1kHz - 250ms is approx 11000 frames so there is no obvious way to fix the time based on the frame position

As I said in 2) and 3) - the graphics is AHEAD of the audio - not lagging behind due to execution speed. I need to work out another way to do it properly or else work out how to calculate the sync offset in 2) or 3)

The audio is OK - no skips or jumps or drop outs (except on very rare occasions - and they are so rare that I don't care about them)

I run the sound editor on 2 different machines:
1) Athlon 1600+ 512MB using RedHat Linux 9 Java 1.4.2-b28
2) PIII500 384MB WinXP Home Java 1.4.1_02

On the PIII500: sync is worse in all cases
Offline aikarele

Senior Newbie





« Reply #1 - Posted 2003-08-15 18:01:46 »

I'm not sure if this helps, but at least you could try to use the high resolution timer in J2SE 1.4.2 instead of the inaccurate currentTimeMillis. You can read more about the high resolution timer here:
http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Tuning;action=display;num=1053157119
Offline Andrew2718

Junior Newbie





« Reply #2 - Posted 2003-08-17 10:21:18 »

OK, the bad new is ... it's the Linux Java implementation that's the problem  Sad
I only tested it a few times on Windows and I must have done that with hacks that I was trying to get to work but were wrong
Coz now when using line.getMicrosecondPosition() it does seem to be correct on Windows but not on Linux
I'm not 100% certain that it is exact on Windows but it does appear to be close enough that it could be OK
Also, I found that Juke.java in the JavaSound demo also displays a counter that is wrong on Linux but appears to be OK on Windows
Oh well, off to the sun bug parade ...
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline tortoise

Junior Member




<3 Shmups


« Reply #3 - Posted 2003-08-18 17:19:26 »

Quote

use a LineListener to catch START and get System.currentTimeMillis() as the time that audio output started - but in the START LineEvent the current frame is either around 500 (audio is behind by about 250ms) or around 4000 (sync almost correct) but for 44.1kHz - 250ms is approx 11000 frames so there is no obvious way to fix the time based on the frame position


Could you elaborate on that? I too am interested in this subject but am (very) new to audio programming.

Why can't you read the frame in the event and adjust the time returned from your timer based on the frame's value? Can't you use this value to determine when to start the graphics, and if they've already started how much to adjust them by?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

atombrot (20 views)
2014-08-19 09:29:53

Tekkerue (21 views)
2014-08-16 06:45:27

Tekkerue (21 views)
2014-08-16 06:22:17

Tekkerue (12 views)
2014-08-16 06:20:21

Tekkerue (19 views)
2014-08-16 06:12:11

Rayexar (55 views)
2014-08-11 02:49:23

BurntPizza (37 views)
2014-08-09 21:09:32

BurntPizza (27 views)
2014-08-08 02:01:56

Norakomi (35 views)
2014-08-06 19:49:38

BurntPizza (64 views)
2014-08-03 02:57:17
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!