CRAS: Ramping up/down for new stream and mute/unmute switching

Let alsa_io hold a cras_ramp member to control ramping.
The start/update of cras_ramp is done in audio thread.
The reset of cras_ramp is done in main thread when closing device.
Ramping is used in these places:

1. When the sample from new stream is ready, ramping up.
2. When system mute state is changed from unmute to mute, ramp samples down.
   Set a callback in cras_ramp so the callback can set mute state on device
   after ramping is done. This process let device plays samples that are
   close to zero before it is turned to mute state.
3. When system mute state is changed from mute to unmute, starts ramping
   up samples and switch mute control to unmute state. This process let
   device plays samples that are close to zero after it is turned to
   unmute state.

For example, when user mutes the system, the flow of 2 is:
 a. Mute state in cras_system_state changed.
 b. iodev_list asks audio thread to start ramping down.
 c. audio_thread gets the message and starts ramping down active
    devices.
 d. audio_thread updates ramped sample in cras_iodev_put_output_buffer
    in each output cycle.
 e. Ramping is done. audio_thread executes callback in cras_ramp to use
    cras_device_monitor_set_device_mute_state to ask main thread to set
    mute state on device.
 f. Main thread receives message and calls cras_iodev_set_mute on
    device to actually change device mute state using set_mute ops.

BUG=chromium:669662
TEST=make check
TEST=on samus, play sine tone in youtube, press mute and volume up
  repeatedly, observe the ramping up and down without pop noise.
TEST=On samus, play a sine tone in youtube, change volume to somewhere
  close to 0 and press "down down down up" quickly. Observe there is pop
  noise at unmute. This is to be solved in the next patch.

Change-Id: I71659edfa0a15d9aafa9db2e8b933c19ef48793f
Reviewed-on: https://chromium-review.googlesource.com/415012
Commit-Ready: Cheng-Yi Chiang <cychiang@chromium.org>
Tested-by: Cheng-Yi Chiang <cychiang@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
10 files changed