summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorKyle Repinski <repinski23@gmail.com>2014-12-01 23:57:59 -0600
committerZiyan <jaraidaniel@gmail.com>2016-01-15 12:26:57 +0100
commit7076f48493d57f39cb50c35cc2b12626ba210962 (patch)
treedf9bd83ce0fd41f5a7d3fa5fd181b881d4f83540 /audio
parentfc5a515f9b0f9a9c471edea3ad29bdf90e7fd37a (diff)
downloaddevice_samsung_tuna-7076f48493d57f39cb50c35cc2b12626ba210962.zip
device_samsung_tuna-7076f48493d57f39cb50c35cc2b12626ba210962.tar.gz
device_samsung_tuna-7076f48493d57f39cb50c35cc2b12626ba210962.tar.bz2
audio: Add ability to disable built-in out stream resample.
This needs further testing before enabling by default, but so far it's been OK. Conflicts: audio/audio_hw.c Change-Id: Ic4f86440ff4d01ab4d0d9f977bdec22f10f60555
Diffstat (limited to 'audio')
-rw-r--r--audio/Android.mk3
-rw-r--r--audio/audio_hw.c22
2 files changed, 25 insertions, 0 deletions
diff --git a/audio/Android.mk b/audio/Android.mk
index bdb47de..eed0c27 100644
--- a/audio/Android.mk
+++ b/audio/Android.mk
@@ -27,5 +27,8 @@ LOCAL_C_INCLUDES += \
LOCAL_SHARED_LIBRARIES := liblog libcutils libtinyalsa libaudioutils libdl libsecril-client
LOCAL_MODULE_TAGS := optional
+# Comment to disable out stream resampler.
+LOCAL_CFLAGS += -DOUT_RESAMPLER
+
include $(BUILD_SHARED_LIBRARY)
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index ba8a81d..45f4c44 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -678,8 +678,10 @@ struct tuna_stream_out {
pthread_mutex_t lock; /* see note below on mutex acquisition order */
struct pcm_config config[PCM_TOTAL];
struct pcm *pcm[PCM_TOTAL];
+#ifdef OUT_RESAMPLER
struct resampler_itfe *resampler;
char *buffer;
+#endif
size_t buffer_frames;
int standby;
struct echo_reference_itfe *echo_reference;
@@ -1437,12 +1439,16 @@ static int start_output_stream_low_latency(struct tuna_stream_out *out)
if (success) {
out->buffer_frames = pcm_config_tones.period_size * 2;
+#ifdef OUT_RESAMPLER
if (out->buffer == NULL)
out->buffer = malloc(out->buffer_frames * audio_stream_out_frame_size(&out->stream));
+#endif
if (adev->echo_reference != NULL)
out->echo_reference = adev->echo_reference;
+#ifdef OUT_RESAMPLER
out->resampler->reset(out->resampler);
+#endif
return 0;
}
@@ -1473,8 +1479,10 @@ static int start_output_stream_deep_buffer(struct tuna_stream_out *out)
return -ENOMEM;
}
out->buffer_frames = DEEP_BUFFER_SHORT_PERIOD_SIZE * 2;
+#ifdef OUT_RESAMPLER
if (out->buffer == NULL)
out->buffer = malloc(out->buffer_frames * audio_stream_out_frame_size(&out->stream));
+#endif
return 0;
}
@@ -1962,6 +1970,7 @@ static ssize_t out_write_low_latency(struct audio_stream_out *stream, const void
}
pthread_mutex_unlock(&adev->lock);
+#ifdef OUT_RESAMPLER
for (i = 0; i < PCM_TOTAL; i++) {
/* only use resampler if required */
if (out->pcm[i] && (out->config[i].rate != DEFAULT_OUT_SAMPLING_RATE)) {
@@ -1974,6 +1983,7 @@ static ssize_t out_write_low_latency(struct audio_stream_out *stream, const void
break;
}
}
+#endif
if (out->echo_reference != NULL) {
struct echo_reference_buffer b;
@@ -1987,13 +1997,17 @@ static ssize_t out_write_low_latency(struct audio_stream_out *stream, const void
/* Write to all active PCMs */
for (i = 0; i < PCM_TOTAL; i++) {
if (out->pcm[i]) {
+#ifdef OUT_RESAMPLER
if (out->config[i].rate == DEFAULT_OUT_SAMPLING_RATE) {
/* PCM uses native sample rate */
+#endif
ret = PCM_WRITE(out->pcm[i], (void *)buffer, bytes);
+#ifdef OUT_RESAMPLER
} else {
/* PCM needs resampler */
ret = PCM_WRITE(out->pcm[i], (void *)out->buffer, out_frames * frame_size);
}
+#endif
if (ret)
break;
}
@@ -2067,6 +2081,7 @@ static ssize_t out_write_deep_buffer(struct audio_stream_out *stream, const void
out->use_long_periods = use_long_periods;
}
+#ifdef OUT_RESAMPLER
/* only use resampler if required */
if (out->config[PCM_NORMAL].rate != DEFAULT_OUT_SAMPLING_RATE) {
out_frames = out->buffer_frames;
@@ -2077,9 +2092,12 @@ static ssize_t out_write_deep_buffer(struct audio_stream_out *stream, const void
&out_frames);
buf = (void *)out->buffer;
} else {
+#endif
out_frames = in_frames;
buf = (void *)buffer;
+#ifdef OUT_RESAMPLER
}
+#endif
/* do not allow more than out->write_threshold frames in kernel pcm driver buffer */
do {
@@ -3296,6 +3314,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
out->stream.set_volume = out_set_volume;
}
+#ifdef OUT_RESAMPLER
ret = create_resampler(DEFAULT_OUT_SAMPLING_RATE,
MM_FULL_POWER_SAMPLING_RATE,
2,
@@ -3304,6 +3323,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
&out->resampler);
if (ret != 0)
goto err_open;
+#endif
out->stream.common.set_sample_rate = out_set_sample_rate;
out->stream.common.get_channels = out_get_channels;
@@ -3357,10 +3377,12 @@ static void adev_close_output_stream(struct audio_hw_device *dev,
}
}
+#ifdef OUT_RESAMPLER
if (out->buffer)
free(out->buffer);
if (out->resampler)
release_resampler(out->resampler);
+#endif
free(stream);
}