summaryrefslogtreecommitdiffstats
path: root/audio
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2011-07-08 17:16:43 -0700
committerSimon Wilson <simonwilson@google.com>2011-07-14 09:50:04 -0700
commit371599a2cf7fedc6c8948f97b03641b15d040d7c (patch)
tree70043f5180eaba1de6d48003185d21136dcd7c51 /audio
parent314781b5ea11394f16247ae71482daad928db3a3 (diff)
downloaddevice_samsung_tuna-371599a2cf7fedc6c8948f97b03641b15d040d7c.zip
device_samsung_tuna-371599a2cf7fedc6c8948f97b03641b15d040d7c.tar.gz
device_samsung_tuna-371599a2cf7fedc6c8948f97b03641b15d040d7c.tar.bz2
audio: fix latency and buffer size calculation
out_get_buffer_size() was returning the total buffer size in frames instead of the period size in bytes. It should also take the resampling into account so that the audio flinger buffer duration somehow matches the period duration. The calculation in out_get_latency() was assuming the period size in the pcm config structure is in bytes whereas it is in frames. Change-Id: I2025a89e753355bd321865faa726013e0a97912f
Diffstat (limited to 'audio')
-rw-r--r--audio/audio_hw.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/audio/audio_hw.c b/audio/audio_hw.c
index 2d23e9c..771eaad 100644
--- a/audio/audio_hw.c
+++ b/audio/audio_hw.c
@@ -91,6 +91,8 @@
#define RESAMPLER_BUFFER_SIZE 8192
+#define DEFAULT_OUT_SAMPLING_RATE 44100
+
#define AUDIO_DEVICE_OUT_ALL_HEADSET (AUDIO_DEVICE_OUT_EARPIECE |\
AUDIO_DEVICE_OUT_WIRED_HEADSET |\
AUDIO_DEVICE_OUT_WIRED_HEADPHONE)
@@ -427,7 +429,7 @@ static int start_output_stream(struct tuna_stream_out *out)
static uint32_t out_get_sample_rate(const struct audio_stream *stream)
{
- return 44100;
+ return DEFAULT_OUT_SAMPLING_RATE;
}
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
@@ -439,7 +441,13 @@ static size_t out_get_buffer_size(const struct audio_stream *stream)
{
struct tuna_stream_out *out = (struct tuna_stream_out *)stream;
- return pcm_get_buffer_size(out->pcm);
+ /* take resampling into account and return the closest majoring
+ multiple of 16 frames, as audioflinger expects audio buffers to
+ be a multiple of 16 frames */
+ size_t size = (out->config.period_size * DEFAULT_OUT_SAMPLING_RATE) /
+ out->config.rate;
+ size = ((size + 15) / 16) * 16;
+ return size * audio_stream_frame_size((struct audio_stream *)stream);
}
static uint32_t out_get_channels(const struct audio_stream *stream)
@@ -509,15 +517,10 @@ static char * out_get_parameters(const struct audio_stream *stream, const char *
static uint32_t out_get_latency(const struct audio_stream_out *stream)
{
- int bytes_per_sample;
-
- if (pcm_config_mm.format == PCM_FORMAT_S32_LE)
- bytes_per_sample = 4;
- else
- bytes_per_sample = 2;
+ struct tuna_stream_out *out = (struct tuna_stream_out *)stream;
- return (pcm_config_mm.period_size * pcm_config_mm.period_count * 1000) /
- (44100 * pcm_config_mm.channels * bytes_per_sample);
+ return (out->config.period_size * out->config.period_count * 1000) /
+ out->config.rate;
}
static int out_set_volume(struct audio_stream_out *stream, float left,
@@ -779,7 +782,7 @@ static int adev_open_output_stream(struct audio_hw_device *dev,
out->config = pcm_config_mm;
- out->speex = speex_resampler_init(2, 44100, 48000,
+ out->speex = speex_resampler_init(2, DEFAULT_OUT_SAMPLING_RATE, 48000,
SPEEX_RESAMPLER_QUALITY_DEFAULT, &ret);
speex_resampler_reset_mem(out->speex);
out->buffer = malloc(RESAMPLER_BUFFER_SIZE); /* todo: allow for reallocing */