Pergunta

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.

Foi útil?

Solução

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. I could not find that Jar last time I went looking for it, but you can get it from my site at http://pscode.org/lib/mp3plugin.jar

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.

Outras dicas

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).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top