0

I am developing a music player and I am almost done. But I need to try something because I have seen there are more commercial music applications use different types of animations for volume up and down while playing the music.

I need something like this,


.

How can I do this? Can anybody help me? Thank you in advance.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 3
    The terms you need to search on are Decibel or Root Mean Square. I say 'search on' because this is far too broad for SO. – Andrew Thompson Mar 01 '19 at 05:46
  • @AndrewThompson Thank you for your answer. Can I know which language uses to develop commercial applications? How they build those applications? How can I learn them? Can you give me examples? I really appreciate that –  Mar 01 '19 at 06:27
  • 2
    A simple Java visualizer is cited [here](https://stackoverflow.com/a/54927406/230513). – trashgod Mar 01 '19 at 10:20
  • @trashgod Thank you very much. I will check it. –  Mar 01 '19 at 10:56
  • 1
    Most commercial music applications are built with some variant of C, but Java is quite capable. My general plan would be to output via a SourceDataLine, inspect the output values and post RMS values to an animation thread via loose coupling. But I am not up on all the latest tools and libraries that might be around to help. – Phil Freihofner Mar 02 '19 at 02:32
  • 1
    I think a JProgressBar that won't always show progress ;-) – Anthony Mar 02 '19 at 21:05
  • @PhilFreihofner Yeah I will check that. Thank you for your help. –  Mar 04 '19 at 03:33
  • @Anthony Yeah. For me that is the best solution. :D –  Mar 04 '19 at 03:34
  • 1
    If you do check out using a SourceDataLine, it might be good to look over the example at https://docs.oracle.com/javase/tutorial/sound/converters.html, the code snippet in the early section "Reading Sound Files". Note the point in code where there is a comment that says "// Here, do something useful". The useful thing would be to convert the bytes to audio values, use the values as part of an RMS calculation, and post, using loose-coupling, the values on the tools that displays the visualization. – Phil Freihofner Mar 04 '19 at 04:50
  • @PhilFreihofner It's very useful and Thank you very much for the source and idea. I can accept this as my answer. –  Mar 04 '19 at 05:30

1 Answers1

0

If you are outputting your audio via a SourceDataLine, it is possible to inspect the audio data as it is being processed. There is a useful code example of this presented in the Oracle Sound Trail tutorials, on the page Using Files and Format Converters, in the section "Reading Sound Files". The important point in the code is marked with a comment "// Here, do something useful"

At that point you would convert the bytes to audio values, and use the values as part of an RMS calculation. Details for the coversion and the RMS calculation should be searchable--I know I've seen explanations for both on stackoverflow.

Once you have an RMS value calculated, it can be sent to an independent thread that handles the graphics visualization. A loose-coupling pattern should be employed so that you minimize the amount of work being done on the audio thread, and so that you avoid any blocking that might hang up the audio.

For example, the visualization thread can have a setRMSValue method that simply updates an instance variable, without synchronization or blocking of any sort. The audio processing thread can call this method freely as it generates new RMS data points. The visualizer can simultaneously read the current instance variable at your animation rate. No synchronization needed. If the visualization thread skips a few RMS data points, it should not a problem.

Phil Freihofner
  • 7,645
  • 1
  • 20
  • 41