summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMisael Lopez Cruz2016-12-02 17:31:39 -0600
committerMisael Lopez Cruz2016-12-06 14:29:16 -0600
commit91eb97c309a2eb9b26c6bfb33de12535f2c27834 (patch)
treec89d6cded3bbdc6dff5e7038d5cb1a07c0588a22
parent05ef002289ae512ea4305910d70ef1e1d08f0b36 (diff)
downloaddevice-ti-jacinto6evm-91eb97c309a2eb9b26c6bfb33de12535f2c27834.tar.gz
device-ti-jacinto6evm-91eb97c309a2eb9b26c6bfb33de12535f2c27834.tar.xz
device-ti-jacinto6evm-91eb97c309a2eb9b26c6bfb33de12535f2c27834.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.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/audio/primary/audio_hw.c b/audio/primary/audio_hw.c
index 1724f55..a0cdc5e 100644
--- a/audio/primary/audio_hw.c
+++ b/audio/primary/audio_hw.c
@@ -1574,6 +1574,7 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
1574{ 1574{
1575 struct j6_audio_device *adev = (struct j6_audio_device *)dev; 1575 struct j6_audio_device *adev = (struct j6_audio_device *)dev;
1576 struct j6_stream_in *in; 1576 struct j6_stream_in *in;
1577 int buffer_size;
1577 int ret; 1578 int ret;
1578 1579
1579 UNUSED(handle); 1580 UNUSED(handle);
@@ -1621,21 +1622,10 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
1621 /* in-place stereo-to-mono remix since capture stream is stereo */ 1622 /* in-place stereo-to-mono remix since capture stream is stereo */
1622 if (in->requested_channels == 1) { 1623 if (in->requested_channels == 1) {
1623 ALOGV("adev_open_input_stream() stereo-to-mono remix needed"); 1624 ALOGV("adev_open_input_stream() stereo-to-mono remix needed");
1624
1625 /*
1626 * buffer size is already enough to allow stereo-to-mono remix
1627 * and resample if needed
1628 */
1629 in->buffer = malloc(2 * in->config.period_size * in->hw_frame_size);
1630 if (!in->buffer) {
1631 ret = -ENOMEM;
1632 goto err1;
1633 }
1634
1635 ret = setup_stereo_to_mono_input_remix(in); 1625 ret = setup_stereo_to_mono_input_remix(in);
1636 if (ret) { 1626 if (ret) {
1637 ALOGE("adev_open_input_stream() failed to setup remix %d", ret); 1627 ALOGE("adev_open_input_stream() failed to setup remix %d", ret);
1638 goto err2; 1628 goto err1;
1639 } 1629 }
1640 } 1630 }
1641 1631
@@ -1653,6 +1643,24 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
1653 &in->resampler); 1643 &in->resampler);
1654 if (ret) { 1644 if (ret) {
1655 ALOGE("adev_open_input_stream() failed to create resampler %d", ret); 1645 ALOGE("adev_open_input_stream() failed to create resampler %d", ret);
1646 goto err2;
1647 }
1648 }
1649
1650 /*
1651 * buffer size needs to be enough to allow stereo-to-mono remix
1652 * and resample if needed
1653 */
1654 if (in->resampler || in->remix) {
1655 buffer_size = in->config.period_size * in->hw_frame_size;
1656 if (in->resampler)
1657 buffer_size *= 2;
1658 if (in->remix)
1659 buffer_size *= 2;
1660
1661 in->buffer = malloc(buffer_size);
1662 if (!in->buffer) {
1663 ret = -ENOMEM;
1656 goto err3; 1664 goto err3;
1657 } 1665 }
1658 } 1666 }
@@ -1662,9 +1670,9 @@ static int adev_open_input_stream(struct audio_hw_device *dev,
1662 return 0; 1670 return 0;
1663 1671
1664 err3: 1672 err3:
1665 free(in->remix); 1673 release_resampler(in->resampler);
1666 err2: 1674 err2:
1667 free(in->buffer); 1675 free(in->remix);
1668 err1: 1676 err1:
1669 free(in); 1677 free(in);
1670 return ret; 1678 return ret;
@@ -1682,17 +1690,13 @@ static void adev_close_input_stream(struct audio_hw_device *dev,
1682 1690
1683 if (in->resampler) 1691 if (in->resampler)
1684 release_resampler(in->resampler); 1692 release_resampler(in->resampler);
1685 in->resampler = NULL;
1686 1693
1687 if (in->remix) 1694 if (in->remix)
1688 free(in->remix); 1695 free(in->remix);
1689 in->remix = NULL;
1690
1691 in->dev = NULL;
1692 adev->in = NULL;
1693 1696
1694 free(in->buffer); 1697 free(in->buffer);
1695 free(in); 1698 free(in);
1699 adev->in = NULL;
1696} 1700}
1697 1701
1698static int adev_dump(const audio_hw_device_t *device, int fd) 1702static int adev_dump(const audio_hw_device_t *device, int fd)