1

I want to show a wav file as an image, so the frequency is charted on screen like you would see in a wav editor. Any ideas?

skaffman
  • 398,947
  • 96
  • 818
  • 769
user501861
  • 51
  • 1
  • 2
  • 4
  • 1
    Use an AudioInputStream to read the data from the wAV file, then compute the FFT of that data and plot it. – Jim Brissom Nov 18 '10 at 11:31
  • http://stackoverflow.com/questions/1062968/display-sound-wav-mp3-as-graph-in-java – jmj Nov 18 '10 at 11:40
  • 1
    The above link is referring to audio display with no frequencies but the wave form. The question is a bit confusing in that respect. Most wave editors(!) actually show the wave form, but if you want to see frequencies(!) it's a slightly different topic. – AudioDroid Nov 18 '10 at 14:07

2 Answers2

5

This is a rough answer, you have to investigate a little more with these keywords...First you need an FFT-function ( http://en.wikipedia.org/wiki/FFT ), I'd suggest you try to find a lib or source-code, no need to reinvent the wheel. Then you apply that FFT-function to a moving window. So:

  1. take n-samples from your wav-file
  2. converts them using the FFT-function,
  3. convert the fft-values to absolute values (that's the spectrum)
  4. moves on m-samples
  5. go back to 1.

In the end each window stands for a x-value (time), and the values of the spectrum represent the y-value (frequencies). That way you have your image.

I hope this is half-way understandable. It's hard to explain with just a few words. Good luck. :-)

AudioDroid
  • 2,292
  • 2
  • 20
  • 31
  • 1
    I would suggest you DEFINITELY don't reinvent the wheel. FFTs are a solved problem. Don't even bother trying, you won't get it right the first time and spend all of you time debugging the FFT instead of writing your snazzy display. I suggest this library: http://sites.google.com/site/piotrwendykier/software/jtransforms – basszero Nov 18 '10 at 14:09
  • @basszero: Thanks for the link. Can you tell me though if I can use the binary API-version of "JTransforms" without showing any source code to anybody? I already try to find an answer somewhere else, only left with confusion... :-/ – AudioDroid Nov 18 '10 at 15:15
  • IANAL but here goes my best guess. The library I linked is licensed under the MPL/LGPL/GPL tri-license. Assuming you get to choose, LGPL allows you to use the library without having to make your application disclose source. – basszero Nov 23 '10 at 20:54
  • AudioDroid really nice answer ! Even though I'm not sure it answers the question (I think the OP meant "the waveform"), it's very interesting to read, so I still upvote ! – Dinaiz Jun 07 '12 at 05:28
0

See Chapter 10 Page 379 in Swing Hacks for an example.

Note it doesn't display the frequencies in the signal. You probably want to draw the amplitude of an audio signal, as an wav-editor would do.

stacker
  • 68,052
  • 28
  • 140
  • 210
  • The above link is referring to audio display with no frequencies but the wave form. The question is a bit confusing in that respect. Most wave editors(!) actually show the wave form, but if you want to see frequencies(!) it's a slightly different topic. – AudioDroid Nov 18 '10 at 14:09
  • @AutoDroid (+1) I agree ,but ".. charted on screen like you would see in a wav editor" made me belive that he meant wave form instead of frequency. – stacker Nov 18 '10 at 22:53
  • @stacker : +1. If you just change the word "frequency" his whole question makes sense ;) – Dinaiz Jun 07 '12 at 05:29