CRAS: Add a property disable_emphasis to disable emphasis/deemphasis

Emphasis/Deemphasis is going to be removed in Chrome. In order to
align the behavior of dsp and chrome, we need to enable
emphasis/deemphasis if user is using an old chrome version to
calibrate config files, and disable it if user is using a new chrome
version to calibrate config files.
This patch adds a property disable_emphasis to drc to disable
emphasis/deemphasis.

CQ-DEPEND=CL:186340
BUG=chromium:340870
TEST=1. Prepare a audio raw file sweeping from 10Hz to 22000Hz.
     2. Modify parameters in drc_test so three drc filters will clip
       audio that is larger than 0dB. Specifically, modify RATIO to
       999, KNEE and THRESHOLD to 0, POST_GAIN to 0. Also, add
       drc->emphasis_disabled = 1;
     3. run drc_test and check the waveform of output. The magnitude
       at high frequency remains roughly the same if
       drc->emphasis_disabled = 1. The magnitude at high frequency
       will be lowered if drc->emphasis_disabled = 0.

Change-Id: I98ff15a88fd198d0239fe1fa3f324eb0875642ba
Reviewed-on: https://chromium-review.googlesource.com/186073
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
CRAS: Modify dsp.ini config files which use [drc]

This patch adds a switch emphasis_disabled at input_4 port of [drc] in dsp.ini files
of boards that use drc.

CQ-DEPEND=CL:186073
BUG=chromium:340870
TEST=Check audio playback is normal on daisy_spring board.

Change-Id: Ibed84ca85115ab0d601bc65db7303e5d0ed08919
Reviewed-on: https://chromium-review.googlesource.com/186340
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Add ucm and cras config for daisy_skate

It still needs device specific tuning but it's a good start

BUG=chrome-os-partner:25737
TEST=AudioJack test

Change-Id: If353dbf8448204fa4a10ce500052e56acf70a2c3
Reviewed-on: https://chromium-review.googlesource.com/185810
Reviewed-by: Katie Roberts-Hoffman <katierh@chromium.org>
Commit-Queue: Katie Roberts-Hoffman <katierh@chromium.org>
Tested-by: Katie Roberts-Hoffman <katierh@chromium.org>
UCM config: Add UCM config for zako

Set two flags for Zako: NoCreateDefaultOutputNode
and NoCreateDefaultInputNode to '1'.
Note that UCM parser requires at least one section of device,
the empty 'Headphone' device is put for that reason.

BUG=chrome-os-partner:25066
TEST=manual on zako

Change-Id: I3fbe81b8b9f1d662b09b7f1eb9263d10551b7224
Original-Change-Id: I8edd62e35a95c185ab4fa66682024120ef911abe
Reviewed-on: https://chromium-review.googlesource.com/183340
Reviewed-by: Mohammed Habibulla <moch@google.com>
Commit-Queue: Gediminas Ramanauskas <gedis@chromium.org>
Tested-by: Gediminas Ramanauskas <gedis@chromium.org>
CRAS: audio_thread - move message definitions to c file

These aren't used outside of audio_thread.c.

BUG=none
TEST=still compiles.

Change-Id: I226ac57ca924d55f539b27a99df36ad5c586c17d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/186302
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: dump audio debug info from client.

Instead of dumping audio thread debug info to syslog, pass it back to
the client through shared memory.  The extra data in shared memory isn't
protected or synchronized, but only one client at a time should ever
access it.

Change-Id: Ie5864b1a3f82a079ed1182b119b05c86976aadda
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187006
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: audio_thread - Add an event log.

Log certain interesting events that happen in the audio thread, add this
log to audio debug info.  Change the test client to print this log when
dumping audio info.

Change-Id: I1b93cfd36731f2ee8b6700faba44fb36ead161e6
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187007
CRAS: audio_thread - Handle EINTR when waiting for streams.

If there select call in interrupted, retry it.  If there is an error
other than EINTR, break out of the waiting loop.

BUG=none
TEST=none

Change-Id: I3762ee6dca039a24236222dd6cb7df2f3bef44d7
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/187008
scripts: Initial commit for audio_tuning scripts

Add conf2ini2.py script to handle config file to ini file conversion.
The config file obtained from calibration webpage
http://audio-tuning.appspot.com should be converted to dsp.ini file
using this script.

BUG=chrome-os-partner:25940
TEST=run conf2ini2.py on config file generated by
  http://audio-tuning.appspot.com

Change-Id: I747952643def774090855f4fe63f9b7b3997bdc7
Reviewed-on: https://chromium-review.googlesource.com/186864
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
UCM daisy_spring: Modify EDID path for kernel 3.8

The EDID path is different when switch from kernel
3.4 to 3.8. This is causing problem that when external
monitor hotplugged, CRAS looked at incorrect path
trying to determine if the external monitor supports
audio output. As a result, it never report HDMI output
plug event to chrome to show on UI.

BUG=chromium:338927
TEST=Plug external monitor to daisy_spring, verify the
HDMI audio device is listed in UI and audio could
output to it.

Change-Id: I98ceb6c7120a599bdd08c962931178ee59329da4
Reviewed-on: https://chromium-review.googlesource.com/187620
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS alsa_jack: Add error log when EDID read timeout

When EDID read timeout happens for whatever reason,
log it so we can spot this in feedback log.

BUG=chromium:338927
TEST=None

Change-Id: I186fcbd3aa478807577cf3bbb6290233d7cc89b9
Reviewed-on: https://chromium-review.googlesource.com/187621
Reviewed-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS alsa_jack: ELD controls for HDMI/DP jack

For HDMI/DP jack, check if there is a ELD control for it.
This ELD control will be used to retrieve the name of the
connected external monitor in later changes.

BUG=chrome-os-partner:25101
TEST=Unittest. Test on Peppy, manual add log to verify
that we got an ELD control for each HDMI/DP alsa device.

Change-Id: I700c993450049697faf731c949484080d0b6abf4
Reviewed-on: https://chromium-review.googlesource.com/187100
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
CRAS alsa_jack: Refactor/rename EDID timer and callback

This refactor modifies the callback functions used for EDID
timer.  check_jack_edid() function is extracted so now it's
independent from the timers and callbacs. The new look allows
better integration with a later change adding poll and read
ELD mixer control.

The edid timer/retries/delay_cb and gpio change callback
are renamed to a more general name, so that they can be
reused in later change. E.g. 'edid_' prefix changed to
'display_info_'

BUG=chrome-os-partner:25101
TEST=Build and run on daisy, make sure the HDMI jack behavior
does not break.

Change-Id: I37e94fe00717803ade9a64c82755def2473575ff
Reviewed-on: https://chromium-review.googlesource.com/187419
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS alsa_jack: Poll ELD control

When HDMI jack plug event happens, the corresponding
ELD buffer will be updated after a delay. Reuse existing
timer callback to poll whether it is ready for read.

BUG=chrome-os-partner:25101
TEST=Manual test on Peppy, add log to verify that when
HDMI hotplug, the plug/unplug status is reported in a
few tries(within the max number of retries).

Change-Id: I1f28808443fe7177fc4cb9d6aed19bd1952b2e2f
Reviewed-on: https://chromium-review.googlesource.com/187101
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS alsa_jack: Add method to get monitor name from ELD

When ELD buffer ready, read the external monitor name
and update to the corresponding node. If the monitor name
fails to read, or at the unplug event, fallback to use
jack name.

BUG=chrome-os-partner:25101
TEST=gmerge adhd; Test on Peppy, verify the external monitor
name is displayed in audio device UI, instead of the jack
name "HDMI/DP ..."

Change-Id: I64e716c5ebe88780fc1c647c8f3f2a252f871574
Reviewed-on: https://chromium-review.googlesource.com/187102
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Hsinyu Chao <hychao@chromium.org>
CRAS client: Make sure client thread is stopped before closing socket.

Call cras_client_stop from cras_client_destroy: This stops the client
thread before shutting down the server socket.

Otherwise the client thread may detect an error, and reconnect to the
server, which causes recv in shutdown_and_close_socket to block
forever.

BUG=chromium:347997
TEST=In crosh, run
'while true; do cras_test_client --dump_server_info; done': this must
not hang (this should work on any platform, but used to hang on
daisy/daisy_spring).

Change-Id: I88bdc05fddc07fb055602d47b1c8dea0cbfb816e
Reviewed-on: https://chromium-review.googlesource.com/188449
Commit-Queue: <nicolas@boichat.ch>
Reviewed-by: <nicolas@boichat.ch>
Tested-by: <nicolas@boichat.ch>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
scripts: Add webpage source code for audio tuning

Initial commit for source code at http://audio-tuning.appspot.com/

BUG=chrome-os-partner:25940
TEST=serve audio.html webpage and connect to it to generate a config
  file.

Change-Id: Id05f08c300aec70dc502281a0f26b3135d68f60b
Reviewed-on: https://chromium-review.googlesource.com/186865
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
scripts: Modify audio.js for emphasis_disabled in drc

There is a new parameter "emphasis_disabled" in drc. This patch modifies
audio.js file in audio_tuning webpage such that it will check if
emphasis/disemphasis is disabled in chrome, then determine
drc.emphasis_disabled config value.

BUG=chrome-os-partner:25940
TEST=run audio_tuning webpage with modified audio.js. Checks that the
output config contains "drc.emphasis_disabled": 0 for chrome without
https://codereview.chromium.org/152333003/, and contains
"drc.emphasis_disabled": 1 for chrome with
https://codereview.chromium.org/152333003/.

Change-Id: I6ef355a1d7cd6a4ac340f711d4270a6a88d42b27
Reviewed-on: https://chromium-review.googlesource.com/186857
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
scripts: Modify conf2ini2.py script for emphasis_disabled in drc

There is a new parameter emphasis_disabled in drc. This patch modifies
conf2ini2.py script so it honors the "drc.emphasis_disabled" in config
file generated by new http://audio-tuning.appspot.com/ and generate
dsp.ini file containing emphasis_disabled in input_4 of [drc].

BUG=chrome-os-partner:25940
TEST=run conf2ini2 file on config file with "drc.emphasis_disabled": 0,
check output contains "intput_4=0      ; emphasis_disabled" in [drc]
section.

Change-Id: I12347f9a7215c2fbcdb65588a32f327cd29737e5
Reviewed-on: https://chromium-review.googlesource.com/186858
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
script: Add init_editor to edit ini files.

This patch adds a script ini_editor.py to ease the editing of dsp.ini
files. Now user can use this tool to inspect and edit dsp.ini file
content. Specifically, this tool can add a port into a section at
certain port index.
E.g. The command
"ini_editor.py -b all -n 'input_4=0 ; emphasis_disabled' -s drc -o
None" can insert "input_4=0 ; emphasis_disabled" to every dsp.ini file
under cras-config directory that has drc section, also the ports after
index 4 are shifted by one index.

BUG=None
TEST=run ini_editor_unittest.py.
     run ini_editor command to show/edit config files.
     ini_editor.py -i <dsp.ini file>   (show content of one file)
     ini_editor.py -b daisy_spring     (show content of one file)
     ini_editor.py -b daisy_spring -s drc (show one section)
     ini_editor.py -b all -s drc -n 'input_4=0 ; emphasis_disabled'
       (modify dsp.ini files for all boards)

Change-Id: I475b4e41adbd86ae018c320db8fec61549239120
Reviewed-on: https://chromium-review.googlesource.com/186074
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Commit-Queue: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>