[Google Pixel XL Themes, Apps, and Mods] bjrmd:
Project Purposes: Optimize sound quality of Pixel/XL when played through the headset port at moderate to low volumes, especially using low impedance, high sensitivity in ear monitors. The optimization will mainly affect signal to noise ratio, noise floor, perhaps THD. In addition, real time Spl monitoring on any device has been added for hearing protection, curiosity and viewing the dynamic range of music tracks(full implementation pending). Integration of the Biquad equalization/filter mod by [MENTION=2760454]chdloc[/MENTION] as a parametric equalizer(full implementation pending). The equalizer is capable of 5 bands, different left and right parameters and clipping protection.

This is a derivative of my Gain control app. Please see that post and following comments to better understand what follows.

Potential Users: Listen to music with high efficiency headphones/IEM and music volume generally below 2/3 max. Low distortion, noise important. Will also provide a finer granularity to the volume heard, about 1 dB increment change vs 3 dB through android volume control. Ability to make custom equalization filters for anything that plays through the headset jack.

Requirements: Rooted Pixel or XL, custom kernel supporting sound control(only tested with Elementalx-thanks to [MENTION=4684315]flar2[/MENTION]), custom mixerpaths if using biquads (thanks to [MENTION=2760454]chdloc[/MENTION]).

This app supports Neutron, Poweramp, Spotify and Google play music. Other music play apps should work using a “polling” method to detect if they are playing. In order to detect when music is playing a “helper” app needs to be installed.

Setup:

Unzip both sets of files(just an xda upload thing-would not take them singly)

Install the Pixel audio control app, and the app "Intent Trigger".

Place mixer_paths in system/etc (not in su/etc). You may want to rename the original to ....old.

Place audio_effects.conf and audio_policy_configuration in system/etc---if you are interested in using the visualizer engine to look at accurate Spl and dynamic range of your tracks. You may want to rename the originals to ....old

In addition for the USB Dac control to work, ALSA needs to be installed. A folder "USR" containing the ALSA files needs to be placed inside of the su folder, and alsa_amixer placed inside of su/bin and su/xbin

Note-if you want to just control gains and not biquads, the mixerpaths should not be needed

Reboot.

Open the main app(not playing music), no setup is required for basic operation, as you can see just move the sliders to change android vol, analog and digital gain. The purpose of the app is to keep analog gain low and digital as close to 0 as possible (to attain the given net output you want). The program will try to keep android vol at 15 (0 dB), analog at 0 and gradually boost by 1 dB another digital register (RX digital volume). Decreasing net output is in reverse. At this point you may want to confirm that analog vol is set to 0 and Digital to perhaps -15.

Note, adjusting the main android vol slider without the headset in will adjust the speaker vol, not the headset vol.

Close the screen-either menu close, or back button

Next, put in a headset, and play music-keep the headset out of your ears just in case .

A notification bar should pop up.

There are choices on the bar if you pull it down further, up, down or sliders to control the volume. It should remember the last setting on play, pause and reboots.

Pressing the Bar Name-Gain should bring up a menu of other screens

This is the sliders choice

The 3 dot option brings up the main menu:

Setup option:

In addition I have added a switch to enable automatic reapplication of the "Biquad" mod on each pause/play. This is a brilliant piece of work done by my friend [MENTION=2760454]chdloc[/MENTION] that creates a 5 band parametric equalizer on the qualcomm platform. His post has the details of how to implement the feature and further instructions are below.

Music polling-certain music apps don’t broadcast play pause info that this app can catch(Pandora). By choosing the polling method a loop will be set up on headset insertion that “listens” for music playing every 4 secs--only use this if you must.

“Say text” on or off to verbally read text messages or not during music play.

In the setup screen is a spinner controlling the RX digital gain "cut off" point when using the up and down buttons. Both [MENTION=2760454]chdloc[/MENTION] and I have noted that the audio codec introduced some distortion when the RX digital gain reaches about -15 dB+- and worsens as it nears 0. Interestingly, the default mixerpath setting places a maximun of -7 dB on this value and if you add in the normal digital headroom in a tracks mix, this distortion is avoided. Some music apps, Neutron in particular, allow you to normalize tracks to the EBU128 standard, which is between 14 and 20 dB down. So even if your setting is at 0 dB digital gain, the music app is playing lower than this (due to it's own attenuation).

For people who would like to avoid this range however, I placed a way to bypass it. So if you choose 10 dB in the setting and started to ramp up the volume by the gain buttons, once you hit -10dB, analog gain would start increasing-leaving you always at -10 dB RX digital. The slider controls ignore this.

Biquad Control:

One of the most significant accomplishments in regards to the qualcomm codec platform was the development of the Biquad filter/equalization system by [MENTION=2760454]chdloc[/MENTION]. This give us either a hard coded fixed equalizer(see his post for the mixerpath mods) or (with a bit of work) an on demand custom 5 band parametric equalizer that you can totally control. In addition, the Pixel can sense headset impedance so we can use that info as a way to individualize equalization filters for each headset you own, or external amp.

Biquads app by [MENTION=2760454]chdloc[/MENTION], has been ported over but I put in some pre defined “bands” and 4 complete “final filters” that I use. Disabled, SE846(7.5 Khz cut with a midrange boost), Oriolus(7.5 Khz cut with a bass boost) and low pass(no high freq passed so you can test the usage out).

What my app will do is capture the numeric band codes from the Biquad app scripts, and take a screenshot of the frequency curve. [MENTION=2760454]chdloc[/MENTION] has done all the hard work.

A new twist on choosing a given equalizer filter for a particular headphone is the Pixels’s ability to sense the impedance of the inserted device.

The number is not totally correct but it does give a rough idea and a “signature” of sorts to identify it. If you enable biquads and insert a headset, a screen pops up asking for headset name, sensitivity(leave blank if don’t know), published impedance (leave blank if not sure-the app will use the sensed value), and which biquad composite to use. Enter to close. If you insert the headset again, the app should know the previous choices. If the entry screen opens again, look to see what the impedance is sensed as-if 0, just remove it and wait a couple of secs and try again. If a close number to the initial, just enter it again as above. I have noted a variation in sensed impedance and for now let's just duplicate the entry.

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.

Step 1 is to install Biquads app, make the required mixerpath mods and probably make an extreme filter(bad sounding) to make sure it actually works when we test it out.

Step 2- From this apps main menu open Biquad Bar.

Another notification bar will appear up top, back arrow or close the main menu for now.

Step 3- Open [MENTION=2760454]chdloc[/MENTION]’s Biquad app, design your filter and press “Design Biquad”.

It will calculate the filter and put up a nice graphic--do not close this! Go to the notification bar opened above and press the “Capture” button. A screenshot is taken and you are presented with a screen to name the filter. Call it something descriptive, ie +2 dB 4 Khz Q 2 lets say, then hit save. You can now go back to chdloc Biquad app, hit ok to put away the graphic and then design another. Note--all captures are done on biquad #1--so do not design on the others.

Step 4- Design “Multi filter”- from the main menu, choose that entry and a screen opens showing left, right channels and the previously added individual biquads are in the drop down positions in a grid form. By default, they are all disabled. Just pick one at a time. A few comments. After measuring my Shure 846 freq response I noted a bit of a channel imbalance. So I made a 2 dB boost at 4K in the R and 4 dB boost in the L. So each band does not need to have the same gaines L or R. Each line can also have just a unilateral change. So if you need a boost or cut in just one side, leave the other disabled.

To prevent clipping it is very important to cut the “preamp” (INP0) by whatever the max boost was in your filters. So if you are boosting low bass by 8 dB, INP0 reduction needs to be 8. The net Spl calculation will reflect this as well.

Step 5- Go back to Setup from the main menu and enable Biquads.

Step 6- From the Main menu click “Active Filter” or the “Biquads bar” in notifications(click on the icon-not the Home) will open the same window. You will see a list of all the filter composites you have made, including a disabled choice. Just click on the entry you want to be active and it will run some tinymix commands to implement it. The details of the “mix” will show below the choice list in case you forgot what you picked. Long clicking will delete any entry.

Step 7-optional-Biquad library- from the main menu again, this lists all the single filters we took from the Biquad app, with screenshots(not scaled) to get an idea of what each looks like. Long clicking will delete.

Once this is done, the overall filter/equalization will occur automatically on playing.

USB Dac control:

On DAC insertion you may see:

You must check the "always" box and hit OK.

First time use you will see:

The top box will populate with sound card devices and the Usb Dac will usually be device 1.

So enter 1 in "Device ID" field as shown.

Then the next scroll box will show the details of that sound card. We are interested in "PCM playback volume". Notice that the Numid is 3. That is entered in the next line as Numid.

Now, I have defaulted some boxes with my Dragonfly Red data but as shown, the Soundblaster E3 has markedly different values. The next part is critical. The "Range" must be put in (if not 64)--so in this case it's 12560. Then a Start Gain, this will trigger every time the Usb Dac is plugged--pick 5-10 percent of max, but this can be altered later. If you are interested in Spl levels, the voltage, impedance data etc must be put in. It is useful not only for ear protection but can help in loudness matching between headphone jack and Usb. The visualizer is explained above. The default player is Google music but the 3 dot menu can take you to "Setup" to change that.

When the Usb Dac is plugged, the notification bar will have a control similar to the qualcomm one. The up and down arrows will boost or decrease the Usb Dac gain by 1 dB (if the Range is 64) and the 3 lines on the right will take you to sliders that do the same.

Note- On rare cases there is a bug that leads to failure to sense when the USB Dac is pulled. As a work around, there is a "Quit" command in the main menu. Pull the Dac, Quit the app, then just restart it from the app tray and the app will be re initialized and ready to go.

If you do not want to have the Usb Dac control anymore, there is a Disable button on the control screen.

Spl monitoring:

Preface-One of my fears in many long years of listening, is what damage is being done in regards to permanent hearing loss. There are studies and recommendations as to time and volume levels that are safe. The SPL calc is an attempt to provide a rough estimate of the Spl(sound pressure level) coming out of the headphone using the following assumptions.

The full output of the codec is 1 V, the published headphone stats(sensitivity and impedance) and measured/published phone amplifier impedance are correct. The software will compute the Spl using the above and the gains selected. So you need the headphone’s published sensitivity( my Shure SE846 is 114 dB SPL/mW), some are published in dB/V so be careful with the entry box. The Spl window uses these units so be reasonably certain. The headphone out impedance is usually about 1 to10 Ohm (Note 4 is 1.4) but you should be able to find the value on the net or measure it yourself(here). The headphones impedance at 1 Khz is usually published but can be also taken from Goldenears.net reviews( again my SE846 is about 9 Ohm)

You should be able to raise/lower gain by 1 dB, monitor the Spl from the notification bar. If you are curious and have the right gear you can also use this in bench testing to easily compare different settings(high analog vs digital attenuation) but at the same Spl(gain). I have measured the actual Spl using a handheld meter, using a full-scale 1 kHz sine wave and the matching is very close. Actual music will be less but varies depending on what you are listening to. Informal observations show average music to be 5-6 dB down from the 1 kHz sine. Please consult published guidelines for safe listening.

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.

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 let's 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 quiet 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 Headphone Entry screen, if biquads are enable, it will pop up on any new headset insertion. The visualizer can also be enable in the SPL menu choice

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.

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.

Additional information

The Spl visualizer is now working with all(?) music apps but the effects and policy files above must replace the stock ones. If not, only google music will be picked up by the visualizer. In Neutron make sure you choose "generic" driver in the apps settings (it in no way alters the SQ). I have not tested Poweramp. Spotify is working fine.

There are also 2 mini apps--"Up" and "Down". These can serve in place as up or down clicks on the notification bar. They are good as "shortcuts" to put on the home screen, or even mapping the volume up/down keys using "xposed additions"(not yet for the pixel) or Button remapper. It works well but only with screen on. A single launch/click of the Up/Down app will change the gains by 1 dB according to the logical algorithm (keeping android vol/digital at or near 0 dB and analog gain as low as possible).

Many thanks as usual to [MENTION=2760454]chdloc[/MENTION] for all the help, guidance and for creating Biquads app. The mixer_paths and ALSA driver are his.

Also to [MENTION=4684315]flar2[/MENTION] for the kernel.