CRAS: DSP - Make the conversion between int16_t and float better.

Reduce rounding error by adding 0.5 before truncating to integer.

Change the constant from 32767.5 to 32768, so the division can be
optimized into multiplication by the compiler.

BUG=none
TEST=make test

Change-Id: I32ca3dd439e106203b9695bc14ab7e2bb0b9ebe4
Reviewed-on: https://gerrit.chromium.org/gerrit/39588
Commit-Ready: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CRAS: jack UT - stub out get_interface.

This slipped by and was calling the actual alsa version.  That didn't
work when running unit tests from the chroot.

BUG=none
TEST=FEATURES="test" emerge-link adhd

Change-Id: Ic31ba14579c3824b158130f68a5530d56f2c41f8
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39487
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: Fix 32bit unit tests.

Make sure to use 64 bit numbers for tracking nano-seconds when running
on 23 bit machines.

BUG=none
TEST=make check on 32bit machine.

Change-Id: If9ba0c13fdc7ab45bd4226fbb388bbdbd2ebfe90
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39582
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: rclient - Check for frame rate of zero.

In case an iodev doesn't have any supported formats, or that a client
sends a bogus request, the frame rate could be set to zero.  Bail
early if that happens.

BUG=none
TEST=updated rclient unittest.

Change-Id: Ia84e5a6cef444e65394b0ceda642487e1d78e15e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39837
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: client - read message before checking server connected.

Before failing if the server doesn't respond, read the message sent
from the main thread.  The code was failing before reading the
message, causing it to be read after the server reconnected and an
error for it had already been returned.

BUG=chromium-os:37246
TEST=see bug, suspend resume with webcam, watch for crash.

Change-Id: I9abadafb5d762865a3ab1eea7743751f7ece7fea
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40008
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: iodev - track sleep correction in iodev.

Instead of tracking the sleep correction frame count in alsa io, move it
to iodev as more iodev implementations will need to use this.

BUG=chromium-os:35272
TEST=alsa_io_unittest, and manual: cras_test_client with differnt
latencies.

Change-Id: I84406f65f59922d74c053635a43a56c693f5d77c
Signed-off-by: Dylan Reid <dgreid@chromium.or
Reviewed-on: https://gerrit.chromium.org/gerrit/39832
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Add ucm config files for daisy_spring.

This is copied from daisy ucm config files.

BUG=chrome-os-partner:14490
TEST=Build daisy_spring image and play audio with 'aplay'.
     Plug in headset and see speaker muted; unplug and see speaker
     unmuted.

Change-Id: I13c2a29c458c0d4eab521474db5feb77ffc2cf72
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40074
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
cast time fields

On x32, the time fields are uint64_t, but long types are 32bit.
So using %ld to show times results in warnings.  Cast it up to
long long so the time shows correctly on all systems.

BUG=chromium-os:36866
TEST=`emerge-x32-generic adhd` now works
TEST=`emerge-x86-alex adhd` still works

Change-Id: I71a1787e625928de5acc29b61baa283a8130062d
Reviewed-on: https://gerrit.chromium.org/gerrit/40182
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Commit-Queue: Mike Frysinger <vapier@chromium.org>
CRAS: alsa_io - Have open/close take an iodev.

Instead of passing an alsa_io pointer to open and close, pass an iodev
pointer.  This will allow these functions to be called from the iodev
core without caring what type of iodev is being used.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I2133b4d2ecc0be1f6b87040c3dced47e38212a15
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39833
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: alsa_io - Add get/put buffer helpers.

Pull out getting and returning mmap buffers from alsa to helper
functions.  This will aid in refactoring the logic in the read/write
functions to be alsa-independent.  Once it is alsa independent it will
be able to be reused across other types of io devices.
Rework some types so that no alsa-specific types are used.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I81306a8aa54c599885ce6cbb5e8c1e6f7b673ed5
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39834
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
CRAS: alsa_io - Remove extra audio fetch.

During playback of two streams, if one is much higher latency than the
other, there was a slight optimization to fetch the audio early if
possible.  There was a bug in that this fetched audio from the low
latency stream the first time it ran, and since the fetches don't block
unless about to underrun, it didn't save anything.  Remove the extra
fetch.

BUG=chromium-os:35272
TEST=alsa_io_unittest, plus simultaneous playback of two streams one
with 10mS latency the other with 100mS latency, ensure no dropouts.

Change-Id: I2b5196babdcb68093d6383a0c80ce77c9ff74766
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39889
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Blacklist the "u1 cad" microphone using USB descriptor checksum.

BUG=chrome-os-partner:14825
TEST=insert CAD-u1 mic and test that audio remains playing
through built-in speakers.

Change-Id: Ic57ff8fbde86ede469681424ddef0611a77da3b7
Reviewed-on: https://gerrit.chromium.org/gerrit/40190
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Chih-Chung Chang <chihchung@chromium.org>
CRAS: alsa_io - factor out more alsa specifics from read/write.

Pull out checking the level and delay into functions so that the code
using the return values can be re-used for other iodevs.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I45eae3d15566dc9892364aa5318bbbb66dc6acd8
Reviewed-on: https://gerrit.chromium.org/gerrit/39890
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
Tested-by: Dylan Reid <dgreid@chromium.org>
CRAS: iodev - common time to sleep calculations.

Make the calculation of time remaining to sleep the same between input
and ouput in alsa io.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I30ca84775c29fbd099e98ebecf59b03f01321eac
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39891
Reviewed-by: Hsinyu Chao <hychao@chromium.org>
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: alsa_io - Pass iodev instead of aio.

Pass around an iodev pointer instead of an alsa_iodev pointer.  This
will allow refactoring much of this code into the iodev implementation
so it can be reused for new iodevs, such as synchronous ones and
bluetooth.

BUG=chromium-os:35272
TEST=alsa_io_unittest

Change-Id: I1641f3007e1de6a4f2a164a73aa86e84ba25c1c0
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/39892
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: alsa_io - Add callbacks to iodev struct.

Add callbacks for all alsa-specific ops used from the audio callback to
struct cras_iodev.  This will allow these device specific functions to
be set differently for each typeof iodev and for the calling functions
to be moved to a common place.

BUG=chromium-os:35272
TEST=alsa_io_unittest, manually play and record audio.

Change-Id: I7c50c0e2add0c591338dd807825a52397b8a0c77
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40060
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: alsa_io - Move open/close ops to iodev base.

Prepares for moving the functions calling these ops to a common place.

BUG=none
TEST=make check

Change-Id: Id9f166e227035262ec013f9d0d2138fc60312736
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40061
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: alsa_io - Pass iodev to terminate and message functions.

Instead of taking an alsa_io take an iodev as an argument so they can be
moved to a common place as they have nothing to do with alsa.

BUG=chromium-os:35272
TEST=make check

Change-Id: I7f3c9098d2de814ebf63c29e5c0e29bff0793a5e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40062
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: iodev - add is_open to iodev.

Add io_open to iodev and set/use if from alsa_io.  This removes the need
to check the alsa handle directly from the audio callback.

BUG=chromium-os:35272
TEST=make check

Change-Id: I2f6d7f4e15b199a35f92e05e2bab2448cf13116d
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40063
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>
CRAS: iodev - Add generic audio callback.

Add a callback pointer to iodev for processing audio samples, remove the
alsa-specific callback from alsa_io and use the generic iodev instead.
This will allow for the common threading code to be re-used.

BUG=chromium-os:35272
TEST=make check

Change-Id: Ib011591edef2d6b8cf2383a9ac14b6efa89e57ee
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/40064
Reviewed-by: Chih-Chung Chang <chihchung@chromium.org>