3

I'm attempting to write a music visualizer. I've looked into it and sound.sampled looks like a good library for reading the data. However, the jdk can only load .wav files. So I'm looking for a flexible addon that'll enable me to load .mp3.

The classes I'll be using are here: http://uk.answers.yahoo.com/question/index?qid=20100125081723AAdnYzf

P.S. Lemme know if you've attempted music visualizers before.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Perry Monschau
  • 883
  • 8
  • 22

2 Answers2

2

However, the jdk..

It is not the JDK that matters, but the JRE.

..can only load .wav files. ..

It can load (a subset of) the types returned by AudioSystem.getAudioFileTypes(). If you check the docs for AudioFileFormat.Type in Java 7, you'll see a list of 5 types, but the ultimate check is what the JRE returns.

.. So I'm looking for a flexible addon that'll enable me to load .mp3.

The mp3plugin.jar of the JMF can be added to the run-time class-path to add support for MP3 decoding to JavaSound.

Lemme know if you've attempted music visualizers before.

Music Visualizer

Yup ;)


I made this wonderful starry background and thought the stars should twinkle and glow based on the music. Do you think it's possible to detect the odd instrument that's playing? Like drums or strings?

I recently broke my own player and am busy with other things, as such I'm using WinAmp to play my favorite tracks and watching some of the (300+) visualizations WinAmp offers. The reason I mention that is that my traces are of two types, 'oscilloscope' style & a 'Lissajous' style. Check the YouYube site linked above for examples of each.

WinAmp OTOH offers a plethora of seemingly quite different styles, some of which are closely tied to the music visually, and others which are entirely unrelated (just pretty animations in their own right). I figure the ones that have a linkage to the music (beyond representing the trace itself - like my software), are basing their graphics on the volume of the signal, which can then sometimes represent a beat.

The correct way to calculate the volume is to come up with a number in decibels (dB), but in my software I implemented a simpler algorithm to detect the RMS of each channel. You can see those volume bars in a Rasputina Track.

Visualization with RMS levels

They are not especially clear in (the lower left/right of) that image, but watch the video & I think you'll find they are easier to see & offer a good basis for the 'pulsating stars' type of effect you are after (a number to multiply a basic brightness by). To get stars to twinkle differently according to frequency (e.g. bass - low, violins - high) you'd need to look to something like spectrum analysis - a Fast Fourier Transform is one way to do that.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • I have dispraxia, so telling me it's the JRE won't help :P... thanks very much for the link. I made this wonderful starry background and thought the stars should twinkle and glow based on the music. Do you think it's possible to detect the odd instrument that's playing? Like drums or strings? – Perry Monschau Mar 18 '12 at 22:04
  • Yes I've looked into the fast fourier and I'm excited :D .. The difficult bit for me now is to find the time to actually get this working. – Perry Monschau Mar 18 '12 at 22:36
  • I've been trying to work with that mp3plugin that you mentioned and it's not going so well. I've tried a number of mp3 files from different sources and they're all getting this error: javax.sound.sampled.LineUnavailableException: line with format MPEG1L3 48000.0 Hz, unknown bits per sample, stereo, unknown frame size, unknown frame rate, not supported. – Perry Monschau Feb 18 '13 at 16:07
  • Try some of the MP3s shown [here](http://pscode.org/media/#sound). – Andrew Thompson Feb 18 '13 at 21:45
  • Same problem, I think it's the way I'm using it. I couldn't find any example code for using the plugin so I wrote code based on guesses. Shall I post my code as a new question on stackoverflow? – Perry Monschau Feb 19 '13 at 13:28
  • Yes, ask a new question. It seems like a class-path problem. If the Jar is on the run-time class-path, it should be able to provide decoding for basic MP3s. – Andrew Thompson Feb 19 '13 at 13:47
  • http://stackoverflow.com/questions/14959566/java-error-when-trying-to-use-mp3plugin-for-playing-an-mp3-file – Perry Monschau Feb 19 '13 at 14:17
1

Javazoom has a library for mp3 format.

http://www.javazoom.net/javalayer/javalayer.html

I've not used it myself. But I know others have done so successfully.

Tools for extracting instruments from a mix HAS become a reality, but I don't know if they have been realized in Java. I'm guessing it is possible but only with considerable effort and limited success at this point. One must contend with aspects of Java that make this sort of thing trickier than they might be in a "C" family language (lack of real-time guarantees: variance in garbage collection timing, thread switching).

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41
  • Calculations is more or less instant in java now. It's the drawing that takes up all the time. That is why I will be using open-gl. When it comes to garbage collection, I can create all the required objects first and then continuously use them, rather than creating new ones. If I make it as efficient as possible, it shouldn't have any problems. :D – Perry Monschau Mar 19 '12 at 10:02
  • Cool! Looking forward to seeing what you come up with. BTW, have you looked at Processing (aka Proce$$ing)? I've seen some mindblowing visualizers built with that, and it is built on top of Java. (example: work of flight404 http://vimeo.com/2120027) – Phil Freihofner Mar 19 '12 at 18:18
  • What exactly is this Proce$$ing you speak of? It looks promising. – Perry Monschau Mar 19 '12 at 21:56
  • Oops. I should have written Proce55ing. But the straight spelling works, too: http://www.processing.org/ I've only seen stuff on the demo pages and on various flight404's works that a friend linked to me--all seemed very impressive. It's in wikipedia, too. – Phil Freihofner Mar 19 '12 at 23:55
  • looks promising, but...I dunno, I've found when you get so high level, even with specialist languages, it tends to limit your capabilities...even if it's just a slight drop in efficiency. – Perry Monschau Mar 20 '12 at 09:50
  • Hey, you mentioned looking forward to seeing it so I thought I'd link you to some screenshots. http://i301.photobucket.com/albums/nn55/Merivo/6.png ^ replace the 6 with 7-9, 11-14 for the other shots. This was for my university project, I'm not sure if I'll work on it more now. – Perry Monschau Apr 21 '13 at 19:18
  • Nice! Thanks for the links. Is there a way to see it in action? – Phil Freihofner Apr 21 '13 at 23:34
  • Not as of yet. Once summer break starts I will get Fraps and video it. I tried setting up a runnable jar for it, but that wasn't working at all. – Perry Monschau Apr 23 '13 at 11:05
  • Am I 3 years too late? :P I never could get Fraps working, but if you're still interested, I've packaged my visualiser into a zip: https://www.sendspace.com/file/aofyqy – Perry Monschau Apr 24 '16 at 16:44