[Galaxy S I9000 Android Development] supercurio:
Allright !

First of all, the wait was long. I'm sorry for that, I didn't mean to.

I'm cooler than yesterday, you could saw that I quite a bit excited by the discovery :D

What is this all about ?

It's all about analogic gain !

Android volume control is just a digital reduction of the amplitude's signal.

You cannot get higher volume for demanding high-impedance headphones, you cannot lower the hiss for sensitive earphones.

Linux sound system

Behind Android media server, there is still the whole Linux sound system. On the Galaxy S and most phone platforms, hardware is driven by software based on the ALSA model.

This driver architecture allow powerful controls, much more versatile than those used by the basic Android APIs.

Take control of the sound mixer

The program named amixer is the simplest interface to the hardware mixer exposed by ALSA sound cards.

Samsung's WM8994 sound driver allows some parameters to be controlled :

Here is the complete list :

Simple mixer control 'Codec Tuning',0
Capabilities: enum
Items: 'OFF' 'ON'
Item0: 'OFF'
# alsa_amixer
Simple mixer control 'FM Radio Path',0
Capabilities: enum
Items: 'FMR_OFF' 'FMR_SPK' 'FMR_HP' 'FMR_SPK_MIX' 'FMR_HP_MIX' 'FMR_DUAL_MIX'
Item0: 'FMR_OFF'
Simple mixer control 'Playback',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 0 [0%]
Front Right: 0 [0%]
Simple mixer control 'Playback Headset',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 54 [86%]
Front Right: 54 [86%]
Simple mixer control 'Playback Path',0
Capabilities: enum
Items: 'OFF' 'RCV' 'SPK' 'HP' 'BT' 'DUAL' 'RING_SPK' 'RING_HP' 'RING_DUAL' 'EXTRA_DOCK_SPEAKER' 'TV_OUT'
Item0: 'OFF'
Simple mixer control 'Playback Spkr',0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 63
Front Left: 60 [95%]
Front Right: 60 [95%]
Simple mixer control 'Capture',0
Capabilities: cvolume cvolume-joined
Capture channels: Mono
Limits: Capture 0 - 239
Mono: Capture 192 [80%]
Simple mixer control 'Clock Control',0
Capabilities: enum
Items: 'OFF' 'ON'
Item0: 'OFF'
Simple mixer control 'Codec Status',0
Capabilities: enum
Items: 'FMR_VOL_0' 'FMR_VOL_1' 'FMR_OFF' 'REC_OFF' 'REC_ON'
Item0: 'FMR_VOL_0'
Simple mixer control 'Codec Tuning',0
Capabilities: enum
Items: 'OFF' 'ON'
Item0: 'OFF'
Simple mixer control 'MIC Path',0
Capabilities: enum
Items: 'Main Mic' 'Hands Free Mic'
Item0: 'Main Mic'
Simple mixer control 'Voice Call Path',0
Capabilities: enum
Items: 'OFF' 'RCV' 'SPK' 'HP' 'BT'
Item0: 'OFF'

The most useful control is named 'Playback Headset'.

It controls the analog gain of the amplifier driving the headphone output and the line output, depending on what's plugged in.

It accept 64 values : 0 to 63 but volumes from 0 to 31 are the same lowest level.

I guess the 'Capture' control will capture interest of some people here too ;)

Results

- For sensitives earphones or headphones :

With low gains, you can shrink the hiss down to some levels so low that the phone amplifier becomes black : no noise !

Yesterday I was amazed because I never experienced such sound with my earphones, for the first time, I had some great dynamic, appropriate level and noise were absent, even in pauses.

With isolating headphones, this is something very special :cool:

- For any other device :

Adjusting the analog ouput gains allow to obtain the best Signal to Noise Ratio.

Old Hi-fi headphones (some required almost a speaker amp) are no problem for the powerful amp included.

And for people who like strong effects or corrections, like +12 EQ on some bands, this is cool because you can still get enough juice and the effect without saturation.

But ?

Too bad ! there is a but !

Right now this is a proof of concept, and there is a giant flaw :

Standard output gain (volume 56) is restored each time :

- you plug / unplug the 3.5" jack

- the phone plays a notification sound

- there is a pause with no sound played during 2s : the amp power down. when powered up, standard gain comes back.

BIG FAT WARNING :

You can destroy your ears (ok, not exactly because of the radiations).

How you could loose your ability to hear :

- Plug your favorite 140db/mW sensitivity in-ear headphones.

- Set the analog volume to 10

- Set the volume to the 15 (maximum) in the media player app.

- Receive a mail

- You have 1/10s to grab the cable and extract the jack from your phone.

- If you did not proceed, this is official : you're now deaf !

SNR Gains

I had troubles today with measurements. Something produced noise around and I did not get the usual SNR in the default configration.

Instead of 90dB, I had 87.5.

But you'll see in this graph the effect of increasing the output gain at the line-out level (without headphone attached)

Volume 56 (default) : 0dB (reference)

Volume 60 : 0.7dB SNR improvement

Volume 61 : 2.1dB SNR improvement

Volume 62 : 4dB SNR improvement :cool:

Volume 63 work but distortions levels increase abruptly (this need to be verified, the level is so high that it could saturate my sound card line-in even at minimum record gain)

HOWTO

Now that you know the risks here is how to test the current progress :)

- Download the attached archive : alsa-utils-binaries.zip and put it on your internal sdcard.

- as root :

cd /
busybox tar zxvf /sdcard/alsa-utils-binaries.tar.gz.zip
alsa_amixer set 'Playback Headset' 56

56 is the default Volume. Adjust it like you want, but remember the radioactive warning !

What's next ?

You know, I wanted to publish for you a solution and not just a new experiment.

This I why I took the time to study what's behind the scene.

I couldn't figure it out just in time so I choose to show you the current state anyway.

Another French developer, gilsken joined me on IRC and he tries to reverse-engineer how Service Mode work.

The ideal solution would be gaining full access over DAC features without the need to be root or flash a custom kernel ! And his work is key to that.

Meanwhile, he published the simple app named SamServMode. Thanks to him we don't have to type *#*#197328640#*#* anymore :)

See you soon !

PS : what is the default volume on your phone (which firmware/country)