Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (404)
games submitted by our members
Games in WIP (289)
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  
  OGG Help  (Read 1835 times)
0 Members and 1 Guest are viewing this topic.
Offline DarkwingGT

Senior Newbie




Java games rock!


« Posted 2003-04-05 19:08:11 »

Well, technically this is not really OGG related I don't think.  But I'm not sure where else to post this.  But I have the craziest thing, I have an AudioInputStream that eventually just blocks on a read and never comes back.  The crazy thing is the same class running on a different machine doesn't block!  And I'm using the same version of the JVM.  I'm going nuts trying to figure this one out.  I used the same OGG file to create the stream, have the same class, same jvm just different machines and on one machine the read blocks and the other the read returns an EOF properly.  Please, any help would seriously be appreciated as I'm going crazy on this one.  Here's the class I'm using:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
import javax.sound.sampled.*;
import java.io.*;

public class OggTest
{
      public static void main(String[] args)
      {
            try
            {
                  File songFile = new File(args[0]);
                  AudioInputStream ais = AudioSystem.getAudioInputStream(songFile);
                  AudioFormat afVorbis = AudioSystem.getAudioFileFormat(songFile).getFormat();
                  AudioFormat afPCM = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED,
                        afVorbis.getSampleRate(), 16, afVorbis.getChannels(),
                        afVorbis.getChannels() * 2, afVorbis.getSampleRate(), false);
                  ais = AudioSystem.getAudioInputStream(afPCM, ais);

                  DataLine.Info dli = new DataLine.Info(SourceDataLine.class, ais.getFormat());
                  SourceDataLine sdl = (SourceDataLine) AudioSystem.getLine(dli);
                  sdl.open(ais.getFormat());

                  sdl.start();
                  int bytesRead = 0;
                  byte[] byteBuffer = new byte[128000];
                  while (bytesRead != -1)
                  {
// The problem is this read blocks on the very last read and never returns
                       bytesRead = ais.read(byteBuffer, 0, byteBuffer.length);
                        if (bytesRead != -1)
                        {
                              sdl.write(byteBuffer, 0, bytesRead);
                        }
                  }

                  sdl.drain();
                  sdl.stop();
                  sdl.close();
            }
            catch (Exception e)
            {
                  e.printStackTrace();
            }
           
            System.exit(0);
      }
}
Offline alex31481

JGO Visitor



Java games rock!


« Reply #1 - Posted 2003-04-15 23:03:25 »

i am not sure if it works but i usually do this


int bytesRead = 0;
  byte[] byteBuffer = new byte[128000];
  while (( bytesRead = ais.read(byteBuffer, 0, byteBuffer.length))!= -1)
  {
 
    sdl.write(byteBuffer, 0, bytesRead);
 
  }
Offline DarkwingGT

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-04-16 03:37:51 »

I'm not quite sure I understand.  Isn't that just the same thing I have just syntactically shortened?  I appreciate your help but I'm not sure I catch your drift.  Could you further explain?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline leknor

Junior Member




ROCK!!!


« Reply #3 - Posted 2003-04-16 04:55:14 »

Alex didn't say anything new, just a stylistic preference.

I don't know why the code would hand in one spot liek that for you unless it  was a real JVM bug or you aren't showing us all your code.

The contract for InputStream.read(byte[], int, int) does state that: "This method blocks until input data is available, end of file is detected, or an exception is thrown." How a file is not available is beyond me.

Anyway, you may want to conider taking advantage of the InputStream. available() method.

I tried to run your code with the vorbis spi 0.6 and 0.7 but got no love. One thing you can do is press <ctrl>+<break> at the console and look at the output and figure out where the "main" thread is currently blocking.
Offline DarkwingGT

Senior Newbie




Java games rock!


« Reply #4 - Posted 2003-04-16 15:48:27 »

Ah, unfortunately this thread doesn't have what I posted in a different thread.  Too bad it can't automagically update all related posts Smiley

Anyhow, the problem lies in the fact that once converted to PCM, the AudioInputStream always returns -1 for getFrameLength() and available() always returns 0.  This is due to something deep deep in the Tritonus API where the AudioInputStream is actually reading from an internal TCircularBuffer.  This buffer blocks on the read with a
1  
 while (buffer.available() == 0) { Object.wait(); } 


Since available() is always 0 at the end it always blocks.  There's also a condition where if frameLength == -1 then it skips the EOF check based on frameLength.  When I found this out I was overjoyed and thought maybe I could fix it.  Then I tried a smaller file, about 1MB.  And lo and behold it worked perfectly fine.  In fact it only starts this problem once the input file size gets to around 3MB.  So I was back to square one.  I emailed the VorbisSPI who are responsible for the OGG to PCM conversion code but they haven't responded.  And it looks like Tritonus is all but dead considering they haven't updated in like 2 years.

P.S.  That's all the code necessary but you need to have the proper jars.  VorbisSPI 0.6 should have all of them and I can't get VorbisSPI 0.7 to recognize an OGG file and they haven't been any help on that bug either.

Of course they were really helpful for a different problem I have, so what can I expect for free Smiley  And it does work really well except for the bugs I'm battling now.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (32 views)
2013-05-17 21:29:12

alaslipknot (40 views)
2013-05-16 21:24:48

gouessej (71 views)
2013-05-16 00:53:38

gouessej (69 views)
2013-05-16 00:17:58

theagentd (78 views)
2013-05-15 15:01:13

theagentd (73 views)
2013-05-15 15:00:54

StreetDoggy (113 views)
2013-05-14 15:56:26

kutucuk (137 views)
2013-05-12 17:10:36

kutucuk (137 views)
2013-05-12 15:36:09

UnluckyDevil (145 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.212 seconds with 20 queries.