diff options
author | Misael Lopez Cruz | 2016-12-02 17:31:39 -0600 |
---|---|---|
committer | Praneeth Bajjuri | 2017-01-17 18:57:44 -0600 |
commit | 0d38c17a03636c63be4c68a1d0d1fe5e3242c426 (patch) | |
tree | a5658a26d73708624457c90ad3543f996275c7d9 | |
parent | 458ac2f4f1c76f4ada2db7c58ac96de0dd7b6431 (diff) | |
download | device-ti-am57xevm-0d38c17a03636c63be4c68a1d0d1fe5e3242c426.tar.gz device-ti-am57xevm-0d38c17a03636c63be4c68a1d0d1fe5e3242c426.tar.xz device-ti-am57xevm-0d38c17a03636c63be4c68a1d0d1fe5e3242c426.zip |
audio: primary: Allocate temporary buffer for resampling
Resampling and remixing requires a temporary buffer to read
audio frames at native format (i.e. stereo, 44.1kHz). This
temporary buffer was being allocated for remixing but not
for resampling.
The buffer is now being allocated for the worst case, which
is when resampling and remixing are both required.
Change-Id: I0e5eb0a45906067f04bd93313cd51e8cdc0d1a9a
Signed-off-by: Misael Lopez Cruz <misael.lopez@ti.com>
-rw-r--r-- | audio/primary/audio_hw.c | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/audio/primary/audio_hw.c b/audio/primary/audio_hw.c index ab87dfa..95f0f06 100644 --- a/audio/primary/audio_hw.c +++ b/audio/primary/audio_hw.c | |||
@@ -1543,6 +1543,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev, | |||
1543 | { | 1543 | { |
1544 | struct j6_audio_device *adev = (struct j6_audio_device *)dev; | 1544 | struct j6_audio_device *adev = (struct j6_audio_device *)dev; |
1545 | struct j6_stream_in *in; | 1545 | struct j6_stream_in *in; |
1546 | int buffer_size; | ||
1546 | int ret; | 1547 | int ret; |
1547 | 1548 | ||
1548 | UNUSED(handle); | 1549 | UNUSED(handle); |
@@ -1590,21 +1591,10 @@ static int adev_open_input_stream(struct audio_hw_device *dev, | |||
1590 | /* in-place stereo-to-mono remix since capture stream is stereo */ | 1591 | /* in-place stereo-to-mono remix since capture stream is stereo */ |
1591 | if (in->requested_channels == 1) { | 1592 | if (in->requested_channels == 1) { |
1592 | ALOGV("adev_open_input_stream() stereo-to-mono remix needed"); | 1593 | ALOGV("adev_open_input_stream() stereo-to-mono remix needed"); |
1593 | |||
1594 | /* | ||
1595 | * buffer size is already enough to allow stereo-to-mono remix | ||
1596 | * and resample if needed | ||
1597 | */ | ||
1598 | in->buffer = malloc(2 * in->config.period_size * in->hw_frame_size); | ||
1599 | if (!in->buffer) { | ||
1600 | ret = -ENOMEM; | ||
1601 | goto err1; | ||
1602 | } | ||
1603 | |||
1604 | ret = setup_stereo_to_mono_input_remix(in); | 1594 | ret = setup_stereo_to_mono_input_remix(in); |
1605 | if (ret) { | 1595 | if (ret) { |
1606 | ALOGE("adev_open_input_stream() failed to setup remix %d", ret); | 1596 | ALOGE("adev_open_input_stream() failed to setup remix %d", ret); |
1607 | goto err2; | 1597 | goto err1; |
1608 | } | 1598 | } |
1609 | } | 1599 | } |
1610 | 1600 | ||
@@ -1622,6 +1612,24 @@ static int adev_open_input_stream(struct audio_hw_device *dev, | |||
1622 | &in->resampler); | 1612 | &in->resampler); |
1623 | if (ret) { | 1613 | if (ret) { |
1624 | ALOGE("adev_open_input_stream() failed to create resampler %d", ret); | 1614 | ALOGE("adev_open_input_stream() failed to create resampler %d", ret); |
1615 | goto err2; | ||
1616 | } | ||
1617 | } | ||
1618 | |||
1619 | /* | ||
1620 | * buffer size needs to be enough to allow stereo-to-mono remix | ||
1621 | * and resample if needed | ||
1622 | */ | ||
1623 | if (in->resampler || in->remix) { | ||
1624 | buffer_size = in->config.period_size * in->hw_frame_size; | ||
1625 | if (in->resampler) | ||
1626 | buffer_size *= 2; | ||
1627 | if (in->remix) | ||
1628 | buffer_size *= 2; | ||
1629 | |||
1630 | in->buffer = malloc(buffer_size); | ||
1631 | if (!in->buffer) { | ||
1632 | ret = -ENOMEM; | ||
1625 | goto err3; | 1633 | goto err3; |
1626 | } | 1634 | } |
1627 | } | 1635 | } |
@@ -1631,9 +1639,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev, | |||
1631 | return 0; | 1639 | return 0; |
1632 | 1640 | ||
1633 | err3: | 1641 | err3: |
1634 | free(in->remix); | 1642 | release_resampler(in->resampler); |
1635 | err2: | 1643 | err2: |
1636 | free(in->buffer); | 1644 | free(in->remix); |
1637 | err1: | 1645 | err1: |
1638 | free(in); | 1646 | free(in); |
1639 | return ret; | 1647 | return ret; |
@@ -1651,17 +1659,13 @@ static void adev_close_input_stream(struct audio_hw_device *dev, | |||
1651 | 1659 | ||
1652 | if (in->resampler) | 1660 | if (in->resampler) |
1653 | release_resampler(in->resampler); | 1661 | release_resampler(in->resampler); |
1654 | in->resampler = NULL; | ||
1655 | 1662 | ||
1656 | if (in->remix) | 1663 | if (in->remix) |
1657 | free(in->remix); | 1664 | free(in->remix); |
1658 | in->remix = NULL; | ||
1659 | |||
1660 | in->dev = NULL; | ||
1661 | adev->in = NULL; | ||
1662 | 1665 | ||
1663 | free(in->buffer); | 1666 | free(in->buffer); |
1664 | free(in); | 1667 | free(in); |
1668 | adev->in = NULL; | ||
1665 | } | 1669 | } |
1666 | 1670 | ||
1667 | static int adev_dump(const audio_hw_device_t *device, int fd) | 1671 | static int adev_dump(const audio_hw_device_t *device, int fd) |