Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Displaying Sound Trace??

Started by bobbin Dec 11, 2000 at 10:57 AM 0 replies 850+ views
Original Post
bobbin
bobbin
I''m trying to display the wave pattern of a wav file (like the windows Sound Recorder display) using the JMF (Java Media Framework). Player.getVisualComponent wont work (cuss it only displays video data), does anyone know of a way to do this, or can give us a link to some doc''s (I have read everything from java.sun.com).. Thanks Robin.
felonius
felonius
A WAV file is just a small header and then the raw sound in the rest of the file.

So one way to make a sound wave on screen is to draw a graph that moves (very rapidly!) from the left to the right. You draw a dot on the right and move it one pixels left for every frame.

The height of the dot is simply given by the next value in the file. I it is a 8-bit recording you read 8-bit. If it is a 16-bit recording you read 16-bit and then place the dot in a height propertional with the value.

This is for mono. I don''t know how sterio is stored in the WAV file but you could probably find the fileformat on the net. It is a very simple format.

The problem know is to keep the graph in sync with the actual sound played. Given you know the sample rate then this is the number of reads from the file you need to make every second to make it match.

So let say the sample rate is 44.1k (CD quality) then you must real a value and print a pixel 44100 (approaximately - I can''t remember the exact number) times a second. It is of course impossible to have so high a frame rate so it is probably better to conect the canvas you are drawing on to a timer and every time that timer ticks you calculate the time since the program started and read the number of samples needed to match that time and show it on screen.

If the sound is small you might want to load it before hand to make updating faster.

Using the technique described here it shound be fairly easy for you make a visual wave in any way you want (in 3D using many colors?) or to make a small doll that dances to the beat (?!?)

Jacob Marner
Jacob Marner, M.Sc.Console Programmer, Deadline Games

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.