How do I get the current volume/amplitude in a MediaPlayer?

前端 未结 7 872
孤街浪徒
孤街浪徒 2020-12-13 20:26

I\'m working on an app that will both record an audio file, and then have the option to play back that file once it\'s been recorded. The UI has an EQ component that animat

7条回答
  •  有刺的猬
    2020-12-13 20:49

    You have to implement getLevel() in DataLine. This is as close to the bus as it gets in Java.

    This involves calculating a running average of amplitude (waveform) data from the sound stream buffer.

    This causes a lot of bus traffic to access the buffer, so left as abstract method.

    Root Mean Square (RMS) is one approach:

    https://community.oracle.com/message/5391003

    DSP with FFT (eg. Visualizer class) gives a complete frequency spectrum, but consumes much more CPU resources.

    Don't slam on full DSP if all you need is RMS (eg. simple beat detection). Limit the quality of your samples to improve performance.

提交回复
热议问题