diff options
Diffstat (limited to 'audio_in.c')
-rw-r--r-- | audio_in.c | 158 |
1 files changed, 158 insertions, 0 deletions
diff --git a/audio_in.c b/audio_in.c new file mode 100644 index 0000000..dffed01 --- /dev/null +++ b/audio_in.c @@ -0,0 +1,158 @@ +/* + * 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_in" + +/* + * Functions + */ + +static uint32_t audio_in_get_sample_rate(const struct audio_stream *stream) +{ + return 8000; +} + +static int audio_in_set_sample_rate(struct audio_stream *stream, uint32_t rate) +{ + return 0; +} + +static size_t audio_in_get_buffer_size(const struct audio_stream *stream) +{ + return 320; +} + +static uint32_t audio_in_get_channels(const struct audio_stream *stream) +{ + return AUDIO_CHANNEL_IN_MONO; +} + +static int audio_in_get_format(const struct audio_stream *stream) +{ + return AUDIO_FORMAT_PCM_16_BIT; +} + +static int audio_in_set_format(struct audio_stream *stream, int format) +{ + return 0; +} + +static int audio_in_standby(struct audio_stream *stream) +{ + return 0; +} + +static int audio_in_dump(const struct audio_stream *stream, int fd) +{ + return 0; +} + +static int audio_in_set_parameters(struct audio_stream *stream, const char *kvpairs) +{ + return 0; +} + +static char * audio_in_get_parameters(const struct audio_stream *stream, + const char *keys) +{ + return strdup(""); +} + +static int audio_in_set_gain(struct audio_stream_in *stream, float gain) +{ + return 0; +} + +static ssize_t audio_in_read(struct audio_stream_in *stream, void* buffer, + size_t bytes) +{ + /* XXX: fake timing for audio input */ + usleep(bytes * 1000000 / audio_stream_frame_size(&stream->common) / + audio_in_get_sample_rate(&stream->common)); + return bytes; +} + +static uint32_t audio_in_get_input_frames_lost(struct audio_stream_in *stream) +{ + return 0; +} + +static int audio_in_add_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +static int audio_in_remove_audio_effect(const struct audio_stream *stream, effect_handle_t effect) +{ + return 0; +} + +/* + * Interface + */ + +static void audio_hw_close_input_stream(struct audio_hw_device *dev, + struct audio_stream_in *stream) +{ + if(stream != NULL) + free(stream); +} + +static int audio_hw_open_input_stream(struct audio_hw_device *dev, + uint32_t devices, int *format, uint32_t *channels, uint32_t *sample_rate, + audio_in_acoustics_t acoustics, struct audio_stream_in **stream_in) +{ + struct tinyalsa_audio_device *tinyalsa_audio_device; + struct tinyalsa_audio_stream_in *tinyalsa_audio_stream_in; + struct audio_stream_in *stream; + + if(dev == NULL) + return -EINVAL; + + tinyalsa_audio_device = (struct tinyalsa_audio_device *) dev; + tinyalsa_audio_stream_in = calloc(1, sizeof(struct tinyalsa_audio_stream_in)); + + if(tinyalsa_audio_stream_in == NULL) + return -ENOMEM; + + tinyalsa_audio_stream_in->dev = tinyalsa_audio_device; + stream = &(tinyalsa_audio_stream_in->stream); + + stream->common.get_sample_rate = audio_in_get_sample_rate; + stream->common.set_sample_rate = audio_in_set_sample_rate; + stream->common.get_buffer_size = audio_in_get_buffer_size; + stream->common.get_channels = audio_in_get_channels; + stream->common.get_format = audio_in_get_format; + stream->common.set_format = audio_in_set_format; + stream->common.standby = audio_in_standby; + stream->common.dump = audio_in_dump; + stream->common.set_parameters = audio_in_set_parameters; + stream->common.get_parameters = audio_in_get_parameters; + stream->common.add_audio_effect = audio_in_add_audio_effect; + stream->common.remove_audio_effect = audio_in_remove_audio_effect; + stream->set_gain = audio_in_set_gain; + stream->read = audio_in_read; + stream->get_input_frames_lost = audio_in_get_input_frames_lost; + + *stream_in = stream; + + return 0; +} |