summaryrefslogtreecommitdiffstats
path: root/audio_out.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio_out.c')
-rw-r--r--audio_out.c165
1 files changed, 165 insertions, 0 deletions
diff --git a/audio_out.c b/audio_out.c
new file mode 100644
index 0000000..ae69f52
--- /dev/null
+++ b/audio_out.c
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ *
+ * This is based on Galaxy Nexus audio.primary.tuna implementation:
+ * Copyright 2011, The Android Open-Source Project
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#undef LOG_TAG
+#define LOG_TAG "audio_out"
+
+/*
+ * Functions
+ */
+
+static uint32_t audio_out_get_sample_rate(const struct audio_stream *stream)
+{
+ return 44100;
+}
+
+static int audio_out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
+{
+ return 0;
+}
+
+static size_t audio_out_get_buffer_size(const struct audio_stream *stream)
+{
+ return 4096;
+}
+
+static uint32_t audio_out_get_channels(const struct audio_stream *stream)
+{
+ return AUDIO_CHANNEL_OUT_STEREO;
+}
+
+static int audio_out_get_format(const struct audio_stream *stream)
+{
+ return AUDIO_FORMAT_PCM_16_BIT;
+}
+
+static int audio_out_set_format(struct audio_stream *stream, int format)
+{
+ return 0;
+}
+
+static int audio_out_standby(struct audio_stream *stream)
+{
+ return 0;
+}
+
+static int audio_out_dump(const struct audio_stream *stream, int fd)
+{
+ return 0;
+}
+
+static int audio_out_set_parameters(struct audio_stream *stream, const char *kvpairs)
+{
+ return 0;
+}
+
+static char * audio_out_get_parameters(const struct audio_stream *stream, const char *keys)
+{
+ return strdup("");
+}
+
+static uint32_t audio_out_get_latency(const struct audio_stream_out *stream)
+{
+ return 0;
+}
+
+static int audio_out_set_volume(struct audio_stream_out *stream, float left,
+ float right)
+{
+ return 0;
+}
+
+static ssize_t audio_out_write(struct audio_stream_out *stream, const void* buffer,
+ size_t bytes)
+{
+ /* XXX: fake timing for audio output */
+ usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) /
+ audio_out_get_sample_rate(&stream->common));
+ return bytes;
+}
+
+static int audio_out_get_render_position(const struct audio_stream_out *stream,
+ uint32_t *dsp_frames)
+{
+ return -EINVAL;
+}
+
+static int audio_out_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
+{
+ return 0;
+}
+
+static int audio_out_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect)
+{
+ return 0;
+}
+
+/*
+ * Interface
+ */
+
+void audio_hw_close_output_stream(struct audio_hw_device *dev,
+ struct audio_stream_out *stream)
+{
+ if(stream != NULL)
+ free(stream);
+}
+
+int audio_hw_open_output_stream(struct audio_hw_device *dev,
+ uint32_t devices, int *format, uint32_t *channels, uint32_t *sample_rate,
+ struct audio_stream_out **stream_out)
+{
+ struct tinyalsa_audio_device *tinyalsa_audio_device;
+ struct tinyalsa_audio_stream_out *tinyalsa_audio_stream_out;
+ struct audio_stream_out *stream;
+
+ if(dev == NULL)
+ return -EINVAL;
+
+ tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev;
+ tinyalsa_audio_stream_out = calloc(1, sizeof(struct tinyalsa_audio_stream_out));
+
+ if(tinyalsa_audio_stream_out == NULL)
+ return -ENOMEM;
+
+ tinyalsa_audio_stream_out->dev = tinyalsa_audio_device;
+ stream = &(tinyalsa_audio_stream_out->stream);
+
+ stream->common.get_sample_rate = audio_out_get_sample_rate;
+ stream->common.set_sample_rate = audio_out_set_sample_rate;
+ stream->common.get_buffer_size = audio_out_get_buffer_size;
+ stream->common.get_channels = audio_out_get_channels;
+ stream->common.get_format = audio_out_get_format;
+ stream->common.set_format = audio_out_set_format;
+ stream->common.standby = audio_out_standby;
+ stream->common.dump = audio_out_dump;
+ stream->common.set_parameters = audio_out_set_parameters;
+ stream->common.get_parameters = audio_out_get_parameters;
+ stream->common.add_audio_effect = audio_out_add_audio_effect;
+ stream->common.remove_audio_effect = audio_out_remove_audio_effect;
+ stream->get_latency = audio_out_get_latency;
+ stream->set_volume = audio_out_set_volume;
+ stream->write = audio_out_write;
+ stream->get_render_position = audio_out_get_render_position;
+
+ *stream_out = stream;
+
+ return 0;
+}