Jump to content

  • Log In with Google      Sign In   
  • Create Account

[java] Sa..Sa...Sound


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
15 replies to this topic

#1 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 June 2001 - 12:00 PM

You mean to tell me that there is not sound in Java 1.1 without a special plugin? I hope this is not entirely true, what kind of sound files/formats are compatable with Java 1.1 Thanks you, weekend have that

Sponsor:

#2 buh   Members   -  Reputation: 122

Like
Likes
Like

Posted 08 June 2001 - 03:11 PM

If it's an applet use play() or getAudioClip() in Applet. If it's an app use Applet.newAudioClip(). I think it only supports au files in 1.1. May use wav too. Don't know. I always give up before I add sound to my games.

Oh crap, that newAudioClip method is 1.2 only. Oops. Disregard

But why would you write an application in 1.1? The user would have to download a JRE anyway. I guess you could want to take advantage of jview.exe that everyone with IE has...

There are that com.sun.audio package though...

Edited by - buh on June 8, 2001 11:41:16 PM

Edited by - buh on June 8, 2001 11:44:16 PM

Edited by - buh on June 10, 2001 1:35:46 PM

#3 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 June 2001 - 06:12 AM

Thanks for the pointers,
using 1.1 for maximum portability

I will check out com.sun.audio (is that 1.1 ?)

I am familiar with .wav , what is "au" is that higer quality then .wav?

thanks all

#4 buh   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 June 2001 - 06:48 AM

Nope, .au files are crap. Actually I can't really hear any difference. Probably just not compressed as well. Don't see them around nowadays.

Sorry, guess it's just sun.audio. Using this little package kinda defeats the maximum portability thing though. It'll only work with Sun's 1.1 JRE. It'd probably be better to just use 1.3 or 1.4.

Edited by - buh on June 11, 2001 1:51:08 PM

#5 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 11 June 2001 - 09:12 AM

so, is the verdict .wav files only in Java 1.1?

I wonder what would be involved in writing a player
myself?

Has anyone tried this?



#6 Chaoslab   Members   -  Reputation: 116

Like
Likes
Like

Posted 11 June 2001 - 11:22 AM

The sun audio class can be used in 1.0 and 1.1

By using it you are not being 100% platform transperent aparently but I have had no problems with it....

I posted this ages ago....

import sun.audio.*;

Variables
byte play_snd_data[]; remember to fill it with something!
AudioData snd_audio;
AudioDataStream snd_stream;

to play
snd_audio = new AudioData(play_snd_data);
snd_stream = new AudioDataStream(snd_audio);
AudioPlayer.player.start(snd_stream);

to stop
AudioPlayer.player.stop(snd_stream);

and there is a method to play looping to





#7 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 June 2001 - 05:21 AM

Thanks Chaos, that helps

What kind of audio files will it play?

I am assuming this will work in an app?

Thanks for all your help.


#8 javanerd   Members   -  Reputation: 122

Like
Likes
Like

Posted 12 June 2001 - 08:46 PM

By default the JDK 1.1 sound API supports only the .AU (u-law compressed) format. But the nice thing is that if you use the "official hack" shown by Chaoslab, you are accessing some of the internal classes and you can implement support for other formats.

See how I''ve implemented .WAV support in my GameFrame for Java library (goto downloads section and download the 0.9.5 version).

The source code of interest can be found in source file src/gameframe/implementations/jdk11x/CSoundEngine.java

The loadSample method loads a WAV file and converts it to a format that is understood by the JDK 1.1 internal sound mixer. The SoundStream, LoopingSoundStream, RiffWavFile and ULawEncoder classes are used in the process.

#9 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 June 2001 - 05:18 AM

quote:
Original post by javanerd

By default the JDK 1.1 sound API supports only the .AU (u-law compressed) format. But the nice thing is that if you use the "official hack" shown by Chaoslab, you are accessing some of the internal classes and you can implement support for other formats.




I''m confused, what other formats?

So, Chaoslab''s example is an "official hack" of sun.audio?
Are there any pitfalls, do I need to worry about soundbank or anything like that?

I really appreciate everyones help 8)



#10 Chaoslab   Members   -  Reputation: 116

Like
Likes
Like

Posted 13 June 2001 - 10:58 PM

Well I don''t believe any hack is official!

;-)

I have read that it is not considered "pure java" but I have had no problems with it and I have a suspition that it''s what the applet.audioclip use''s anyway.

The only prob is you have to create the sounds from byte buffers (as you can see) which takes a bit more effort, but hay that also meens you can apply algorythms to them.

#11 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 June 2001 - 05:37 AM

quote:
Original post by Chaoslab

Well I don''t believe any hack is official!
;-)
hay that also meens you can apply algorythms to them.


Nice! so this code:

import sun.audio.*;

Variables
byte play_snd_data[]; remember to fill it with something!
AudioData snd_audio;
AudioDataStream snd_stream;

to play
snd_audio = new AudioData(play_snd_data);
snd_stream = new AudioDataStream(snd_audio);
AudioPlayer.player.start(snd_stream);

to stop
AudioPlayer.player.stop(snd_stream);


will enable me to play .wav files,and I could add a loop
I just got clearence from the sound and music guy to use
.wav files. I am assuming I will be able to play multiple
tracks simultaneously if I code it correctly?

Thanks All!





#12 Chaoslab   Members   -  Reputation: 116

Like
Likes
Like

Posted 14 June 2001 - 10:34 AM

Yes you can play multiple sounds con currently but don''t play to many as it can sound a bit crusty!

Of course if you like crust (And I don''t really mind it!)

Then all is good anyway!

:-)



#13 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 June 2001 - 12:01 PM

I owe you one Chaoslab


8) Robert Corrina
mailto:robertcorrina@patownsend.com





#14 javanerd   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 June 2001 - 06:59 PM

quote:
Original post by lupine
I''m confused, what other formats?

Sorry I wasn''t too clear on that. My post meant that you can write your own loader for any format.

One way to do this is to write your own AudioDataStream implementation that converts the audio format from the loaded format to U-law format (that JDK 1.1. understands) and then feeds JDK 1.1 audio engine with this stream.

JDK 1.1 doesn''t support WAV by itself. That''s why I pointed out the library code, because there you can see how I''ve implemented the conversion from WAV to AU upon loading the file. Also I''ve implemented a looping sound stream that allows me to loop the sound as needed.


#15 lilspikey   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 June 2001 - 10:39 PM

Do be careful using the sun.audio.* classes, they don''t work under java 1.3.
So it might be worth doing some checking to see if the relevant classes exist at runtime or not. You should be able to do a bit of cunning introspection/reflection to do this. That way people can still play the game, but they might not have any sound, which is better than it crashing.

John

#16 lupine   Members   -  Reputation: 122

Like
Likes
Like

Posted 15 June 2001 - 08:20 AM

Thanks for the information nerd 8)
Sounds like I'm gonna have to get a little fancy
to code this functionality. I feel squemish about
using outside libraries.

Thanks for the heads up lil'
Looks like I'll do a 1.1 with dodge(error handling)
and then I'll follow up with a different version
for 1.3 and beyond
This brings me to my distribution questions
I hope I can count on all your help in my next thread
8)



Edited by - lupine on June 15, 2001 3:22:37 PM




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS