[Android Software Development] bjrmd:
Spl and Visualizer

As noted above, one of the purposes of this app/mod is to try to inform the listener about excess sound levels which will cause hearing loss. It does not limit or change the sound in any way but based on the gains(voltage put out by the phone), the headphone/amplifier output impedance and headphone sensitivity, calculates what a 1 kHz sine wave Spl would be. Depending on what you are listening to (silence, over compressed rock music, everything in between) the sound coming out of the headphone will be quite different. There is a class available in android that measures the peak and RMS audio levels on a real time basis. By using this measurement we can then compensate for whatever the played signal is for a much more accurate determination of Spl. Unfortunately there is a bug in the measurement process that makes levels only accurate at maximum android volume levels. With this app, we keep them there anyway so it is not an issue. However, if you do not do so the numbers put out will not be accurate.

Additional Feature:

On any android 4.4 or later device it is now possible to monitor the real time Spl/Dynamic Range as above. No root needed, the volume keys will provide the gain parameters. Of course, you still need to input the amplifier, headphone specs. In addition, the maximum output voltage will need to be measured(to figure out the maximum volume possible). A male to male headset connector, voltmeter and a 1 kHz full scale sine wave is needed(below). Play the sine wave at max volume(do not attach headphone), measure the voltage and that is used in the input screen. My Galaxy S6 only puts out .525 V so it's max Spl will be quite a bit different than the Note 4 (1 V).

The new Spl measurement process gets peak and RMS levels every 1.5 seconds and put these values in an array of 8 values. At the end of the 8th measurement, the array is averaged and saved to a text file on your root storage(about every 15 sec). The two files contain the peak values and RMS in dB. So lets say the track has a peak value at 1 minute into the song of 0 dB, and an RMS level of -7 dB. The dynamic range would be 7 and if the calculated Spl was 90 by the original OP formula, the new net Spl would be 83 dB. A very quite track may have a peak of -3 dB and RMS -16 resulting in a dynamic range of 13 and corrected Spl (90-16) of 74. More info on dynamic range calculations

The “visualizer” is enabled in the Spl setup screen.

Be extra careful which headphone sensitivity units are used--either dB/V or dB/mw. Enter either one but not both. The website of the manufacturer should have the specs. Note: Shure is in dB/mw and Sennheiser is dB/V.

The visualizer engine does take considerable CPU resources and battery use. If you don’t want/need it, keep it disabled. On my Note 4, there is no lag and minimal battery compromise but devices may vary. The following screenshot shows the effect on my Note 4, about an extra 5-7%.

[/IMG]

The values are in a separate notification bar, with the last 8 array members over the previous 15 seconds.

The graph icon will show a graph of the Spl and dynamic range over time. It uses google graph api, so an internet connection is needed. The graph is scrollable by dragging it. Every time the headphone is pulled a separate “session” begins and the graph zeros out. But the last session can still be seen by pressing the button noted. Very long sessions won’t function with the google graph api that is used so the data gets automatically resized to every other value. Pause/play stays in the same session.

The left side of the graph has units for Spl in dB, the right(which may need to be scrolled since it is off screen) has the legend for dynamic range. Most tracks will have a dynamic range of between 8-15 (corresponds to the DR album database of 5-12 values). Parts of a track may have more range than others and certainly will have different Spl values. I have placed a yellow caution line at about 78 dB and a red at 85.

I have enclosed a couple of papers from recent literature regarding safe/prolonged listening levels and hearing loss. This software does not “A” weight the Spl, which is what is seen in the literature, but it is not far off, based on my A vs C weight Spl meter comparing the levels.

Again, many thanks to [MENTION=2760454]chdloc[/MENTION] for helping me make this possible.

Additional information

Neutron users must enable generic driver in settings.

Poweramp working with gains and Spl, use the google music toggle in setup, make sure direct volume control off and MusicFx is on in settings

A word about the effect of equalization:

If you apply cuts using the equalizer, they will reflect accurately in the Spl (the visualizer responds depending on the amount of cut). But if you significantly apply gain, depending on the amount of clipping, the Spl will be underestimated. So in general apply boost sparingly and mainly cut the frequency bands you don't like(or to make the others sound louder). The brilliant codec mod by [MENTION=2760454]chdloc[/MENTION] is not reflected in the Spl either, so try to keep the boost/cuts equivalent to keep the Spl accurate (and the signal without clipping).