Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
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 2186 times)
0 Members and 1 Guest are viewing this topic.
Offline DarkwingGT

Senior Newbie




Java games rock!


« Posted 2003-04-05 17: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

Innocent Bystander




Java games rock!


« Reply #1 - Posted 2003-04-15 21: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 01: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 02: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 13: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.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (27 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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!