summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2012-10-13 12:55:02 +0200
committerPaul Kocialkowski <contact@paulk.fr>2012-10-13 12:55:02 +0200
commiteae512666c652d8c9efbb5986a43f2f3ae82b687 (patch)
tree051e791839aee850260f094e7842527b2b13f5f3
parent9b78c141abe0dcac335e5423f5ebdd05b481d1cc (diff)
downloadhardware_tinyalsa-audio-eae512666c652d8c9efbb5986a43f2f3ae82b687.zip
hardware_tinyalsa-audio-eae512666c652d8c9efbb5986a43f2f3ae82b687.tar.gz
hardware_tinyalsa-audio-eae512666c652d8c9efbb5986a43f2f3ae82b687.tar.bz2
Output: Set sample rate, channels and format from mixer values
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--audio_hw.h12
-rw-r--r--audio_out.c83
2 files changed, 91 insertions, 4 deletions
diff --git a/audio_hw.h b/audio_hw.h
index 7343fb2..cc7f963 100644
--- a/audio_hw.h
+++ b/audio_hw.h
@@ -25,11 +25,23 @@
struct tinyalsa_audio_stream_out {
struct audio_stream_out stream;
struct tinyalsa_audio_device *device;
+
+ struct tinyalsa_mixer_io_props *mixer_props;
+
+ int rate;
+ audio_channels_t channels;
+ audio_format_t format;
};
struct tinyalsa_audio_stream_in {
struct audio_stream_in stream;
struct tinyalsa_audio_device *device;
+
+ struct tinyalsa_mixer_io_props *mixer_props;
+
+ int rate;
+ audio_channels_t channels;
+ audio_format_t format;
};
struct tinyalsa_audio_device {
diff --git a/audio_out.c b/audio_out.c
index 538438b..e55190a 100644
--- a/audio_out.c
+++ b/audio_out.c
@@ -38,35 +38,89 @@
static uint32_t audio_out_get_sample_rate(const struct audio_stream *stream)
{
- return 44100;
+ struct tinyalsa_audio_stream_out *stream_out;
+
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ return stream_out->rate;
}
static int audio_out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
+ struct tinyalsa_audio_stream_out *stream_out;
+
LOGD("%s(%p, %d)", __func__, stream, rate);
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ // FIXME: If rate is different, change resampler
+ stream_out->rate = rate;
+
return 0;
}
static size_t audio_out_get_buffer_size(const struct audio_stream *stream)
{
- return 4096;
+ struct tinyalsa_audio_stream_out *stream_out;
+ size_t size;
+
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ size = (stream_out->mixer_props->period_size * stream_out->rate) /
+ stream_out->rate;
+ size = ((size + 15) / 16) * 16;
+ size = size * audio_stream_frame_size((struct audio_stream *) stream);
+
+ return size;
}
static uint32_t audio_out_get_channels(const struct audio_stream *stream)
{
- return AUDIO_CHANNEL_OUT_STEREO;
+ struct tinyalsa_audio_stream_out *stream_out;
+
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ return stream_out->channels;
}
static int audio_out_get_format(const struct audio_stream *stream)
{
- return AUDIO_FORMAT_PCM_16_BIT;
+ struct tinyalsa_audio_stream_out *stream_out;
+
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ return stream_out->format;
}
static int audio_out_set_format(struct audio_stream *stream, int format)
{
+ struct tinyalsa_audio_stream_out *stream_out;
+
LOGD("%s(%p, %d)", __func__, stream, format);
+ if(stream == NULL)
+ return -1;
+
+ stream_out = (struct tinyalsa_audio_stream_out *) stream;
+
+ // FIXME: If format is different, change resampler
+ stream_out->format = format;
+
return 0;
}
@@ -214,7 +268,28 @@ int audio_hw_open_output_stream(struct audio_hw_device *dev,
stream->write = audio_out_write;
stream->get_render_position = audio_out_get_render_position;
+ if(tinyalsa_audio_device->mixer == NULL)
+ goto error_stream;
+
+ tinyalsa_audio_stream_out->mixer_props =
+ tinyalsa_mixer_get_output_props(tinyalsa_audio_device->mixer);
+
+ if(tinyalsa_audio_stream_out->mixer_props == NULL)
+ goto error_stream;
+
+ tinyalsa_audio_stream_out->rate =
+ tinyalsa_audio_stream_out->mixer_props->rate;
+ tinyalsa_audio_stream_out->channels =
+ tinyalsa_audio_stream_out->mixer_props->channels;
+ tinyalsa_audio_stream_out->format =
+ tinyalsa_audio_stream_out->mixer_props->format;
+
*stream_out = stream;
return 0;
+
+error_stream:
+ *stream_out = NULL;
+
+ return -1;
}