Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sound frequency and audio visualizations

843802May 22 2006
Hi, I�m trying to create a Java audio visualization applet with Audio Visualizations similar to something out of Winamp or Windows Media Player. Coming up with the animation is no problem once I get information from the song file, but I�m having trouble getting the raw data from the music.

First I have a PCM_UNSIGNED 11025.0 Hz, 8 bit, mono, 1 bytes/frame WAVE file called "file.wav"

I start by playing the file by:

AudioClip clip;

AppletSoundList soundList= new AppletSoundList (this, getCodeBase());

soundList.startLoading(�file.wav�);

clip soundList.getClip(�file.wav�);

clip.play();

The sound clip begins to play sucessfully.

Then I set up an AudioInputStream like this:

AudioSystem audio;
AudioInputStream audioIS;

try{

audioIS = audio.getAudioInputStream(file); //where file="file.wav"

audioIS.getFormat();

} catch(javax.sound.sampled.UnsupportedAudioFileException e){
System.out.println("UnsupportedAudioFileException");
}catch(java.io.IOException e){
System.out.println("IOException");
}

this is done sucessfully where getFormat() returns the correct infromation
of the audio file

I experimented a little with the AudioInputStream�s read() methods, but I don�t understand them

I need to be able to get information from the music such as the current frequency. Is there a way to find the frequency of the song at an instant while it is playng?

i read something from "myjavastick". he writes -
----" Then, using the read() methods, you can get an array of raw data.

From there, if it's a 16-bit little-endian PMC, every 2 bytes should look like this:
62Hz--31Hz--0--0--0--0--0--0--16KHz--8KHz--4KHz--2KHz--1KHz--500Hz--250Hz--125Hz
or
8KHz--16KHz--0--0--0--0--0--0--31Hz--62Hz--125Hz--250Hz--500Hz--1KHz--2KHz--4KH z

With 16-bit big-endian PMC, it should look like:
16KHz--8KHz--4KHz--2KHz--1KHz--500Hz--250Hz--125Hz--62Hz--31Hz--0--0--0--0--0--0
or
31Hz--62Hz--125Hz--250Hz--500Hz--1KHz--2KHz--4KHz--8KHz--16KHz--0--0--0--0--0--0

I'm completely unsure which order it is. Try both. The smaller ones (31Hz, 62Hz, etc.) should be the lowest, bassiest sounds."-----

i tired some of those read() methods, they return and integer value, but one of them apends a byte[] array with certain information. then i i tired to print that information, but it was a bunch of "-128"s

im not sure if im on the right track.
im not even sure what im doing.

does anyone know anything about this or, even have some code
samples of audio visualizations or similar applications?

i would apreciate any help. thx
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 19 2006
Added on May 22 2006
0 comments
232 views