Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (577)
games submitted by our members
Games in WIP (498)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: 1 [2]
  ignore  |  Print  
  [1.5.0]sampled stuff isn't working anymore  (Read 6262 times)
0 Members and 1 Guest are viewing this topic.
Offline Matzon

JGO Knight


Medals: 19
Projects: 2


I'm gonna wring your pants!


« Reply #30 - Posted 2004-11-10 07:26:55 »

and only java 1.4 & 1.5 does this - 1.3 doesn't.

Offline Bombadil

Senior Member





« Reply #31 - Posted 2004-11-10 07:54:17 »

+
Quote
That workaround isn't working for me :-/

Strange. So... since the software mixer has been the standard way to play Javasound prior to Java 1.5 (according to Yuri's article), how have you ever been able to hear Javasound before 1.5 ? :-)

Would you mind testing this small class; for me it works fine with Java 1.5 thanks to Yuri. You just need to call the constructor with some Sample.wav string for example, and then call "starte()" on the object.
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  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
import java.io.IOException;
import java.io.InputStream;
import javax.sound.sampled.*;

public class Klang
{
  private static Mixer mMixer;

  private byte[]        mSampledaten;
  private AudioFormat   mAudioformat;
  private DataLine.Info mDatlinInfo;

  static
  {
    Mixer.Info[] mixers = AudioSystem.getMixerInfo();
    for (int i = 0; i < mixers.length; i++) {
      if ("Java Sound Audio Engine".equals(mixers[i].getName())) {
        mMixer = AudioSystem.getMixer(mixers[i]);
      }
    }
  }

  /**
   * @param  Wav-Dateiname.
   */

  Klang(final String dateiname)
  {
    try
    {
      InputStream istrom = new BufferedInputStream(FileInputStream(dateiname));

      AudioInputStream tonstrom = AudioSystem.getAudioInputStream(istrom);
      mAudioformat = tonstrom.getFormat();

      int bytelänge = (int) (mAudioformat.getFrameSize() * tonstrom.getFrameLength());
      mSampledaten  = new byte[bytelänge];
      tonstrom.read(mSampledaten, 0, bytelänge);

      mDatlinInfo = new DataLine.Info(Clip.class, mAudioformat);
      if (! AudioSystem.isLineSupported(mDatlinInfo)) {
        System.err.println("Audio-Linie nicht unterstützt!");
      }
    }
    catch (UnsupportedAudioFileException ex) {
      System.err.println("Audio-Dateiformat nicht unterstützt: " + ex);
    }
    catch (IOException ex) {
      System.err.println(ex);
    }
  }

  /**
   * @return  Ob erfolgreich gestartet.
   */

  public boolean starte()
  {
    Clip klip;
    try {
      if (mMixer != null) {
        klip = (Clip) mMixer.getLine(mDatlinInfo);
      }
      else {
        klip = (Clip) AudioSystem.getLine(mDatlinInfo);
      }
      klip.open(mAudioformat, mSampledaten, 0, mSampledaten.length);
    }
    catch (LineUnavailableException ex)  {
      System.err.println("Klang konnte nicht gestartet werden: " + ex);
      return false;
    }

    klip.start();
    return true;
  }
}
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #32 - Posted 2004-11-10 15:39:49 »

Cheers Bombadil. Yea... it works... doh...

I had... private Mixer mix;... ok... and then later I had... Mixer mix=... Roll Eyes

My stupidity is unmatched! My sillyness knows no equal! Tongue

Ahyea... great. Grin

弾幕 ☆ @mahonnaiseblog
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Bombadil

Senior Member





« Reply #33 - Posted 2004-11-10 16:32:05 »

Quote
Cheers Bombadil. Yea... it works... doh...

Well, this is nice. So finally we've got a solid way to sound with Java 1.5: via the old mixer, hehe.

Quote
I had... private Mixer mix;... ok... and then later I had... Mixer mix=... ::)

Oh yes, I know this kind of error. A pity my favourite IDE JBuilder still doesn't mark it with a warning - although it knows "Audit" warnings for so many things (several of them pretty useless).
Offline Bombadil

Senior Member





« Reply #34 - Posted 2005-02-18 12:50:57 »

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5070730
(quotet before)

Status: "Closed, fixed"

Nice.
Offline oNyx

JGO Coder


Medals: 1


pixels! :x


« Reply #35 - Posted 2005-02-18 19:21:11 »

Ye, I was about to post the same Smiley

Meh... so what I'm supposed to do with that workaround? Remove it when a newer 1.5 appeared? Leave it there... forever?

弾幕 ☆ @mahonnaiseblog
Offline mumart

Junior Member


Medals: 1
Projects: 1


IBXM Java Music Player


« Reply #36 - Posted 2005-04-12 16:08:34 »

Have I hit the same bug?

I've written a seekable InputStream for my modplayer, and verified that it spits bytes out (so I should hear /something/, even if it is just noise Smiley.

The following code is silent:

1  
2  
3  
4  
5  
            AudioFormat format = new AudioFormat( rate, 16, 2, true, false );
            AudioInputStream ais = new AudioInputStream( new IBXMInputStream( i ), format, i.getSongLength() );
            Clip c = AudioSystem.getClip();
            c.open( ais );
            c.start();
Offline mumart

Junior Member


Medals: 1
Projects: 1


IBXM Java Music Player


« Reply #37 - Posted 2005-04-14 18:47:58 »

Quote
Have I hit the same bug?


No I haven't. A bug in my read method caused it to return 0 every time. I'm surprised I can get anything I write to work these days Embarrassed

Clips seem to work every time for me, although streaming mods through the clip interface is slow and takes up enormous amounts of memory. It's obviously not designed for that.

Quote
Have I hit the same bug?

I've written a seekable InputStream for my modplayer, and verified that it spits bytes out (so I should hear /something/, even if it is just noise Smiley.

The following code is silent:

1  
2  
3  
4  
5  
            AudioFormat format = new AudioFormat( rate, 16, 2, true, false );
            AudioInputStream ais = new AudioInputStream( new IBXMInputStream( i ), format, i.getSongLength() );
            Clip c = AudioSystem.getClip();
            c.open( ais );
            c.start();
Pages: 1 [2]
  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.

xsi3rr4x (18 views)
2014-04-15 18:08:23

BurntPizza (15 views)
2014-04-15 03:46:01

UprightPath (28 views)
2014-04-14 17:39:50

UprightPath (13 views)
2014-04-14 17:35:47

Porlus (29 views)
2014-04-14 15:48:38

tom_mai78101 (54 views)
2014-04-10 04:04:31

BurntPizza (111 views)
2014-04-08 23:06:04

tom_mai78101 (212 views)
2014-04-05 13:34:39

trollwarrior1 (181 views)
2014-04-04 12:06:45

CJLetsGame (187 views)
2014-04-01 02:16:10
List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:05:20
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!