#define AUDIO_DEVICE_NAME "/dev/eac"
-#define OUT_SAMPLING_RATE 44100
#define OUT_BUFFER_SIZE 4096
#define OUT_LATENCY_MS 20
#define IN_SAMPLING_RATE 8000
struct audio_stream_out stream;
struct generic_audio_device *dev;
audio_devices_t device;
+ uint32_t sample_rate;
};
struct generic_stream_in {
static uint32_t out_get_sample_rate(const struct audio_stream *stream)
{
- return OUT_SAMPLING_RATE;
+ struct generic_stream_out *out = (struct generic_stream_out *)stream;
+ return out->sample_rate;
}
static int out_set_sample_rate(struct audio_stream *stream, uint32_t rate)
{
struct generic_audio_device *adev = (struct generic_audio_device *)dev;
struct generic_stream_out *out;
+ static const uint32_t sample_rates [] = { 44100, 48000 };
+ static const int sample_rates_count = sizeof(sample_rates)/sizeof(sample_rates[0]);
int ret = 0;
pthread_mutex_lock(&adev->lock);
}
if ((config->format != AUDIO_FORMAT_PCM_16_BIT) ||
- (config->channel_mask != AUDIO_CHANNEL_OUT_STEREO) ||
- (config->sample_rate != OUT_SAMPLING_RATE)) {
- ALOGE("Error opening output stream format %d, channel_mask %04x, sample_rate %u",
- config->format, config->channel_mask, config->sample_rate);
+ (config->channel_mask != AUDIO_CHANNEL_OUT_STEREO) ) {
+ ALOGE("Error opening output stream, format %d, channel_mask %04x",
+ config->format, config->channel_mask);
config->format = AUDIO_FORMAT_PCM_16_BIT;
config->channel_mask = AUDIO_CHANNEL_OUT_STEREO;
- config->sample_rate = OUT_SAMPLING_RATE;
ret = -EINVAL;
- goto error;
}
+ for (int idx = 0; idx < sample_rates_count; idx++) {
+ if (config->sample_rate < sample_rates[idx]) {
+ config->sample_rate = sample_rates[idx];
+ ALOGE("Error opening output stream, sample_rate %u", config->sample_rate);
+ ret = -EINVAL;
+ break;
+ } else if (config->sample_rate == sample_rates[idx]) {
+ break;
+ } else if (idx == sample_rates_count-1) {
+ // Cap it to the highest rate we support
+ config->sample_rate = sample_rates[idx];
+ ALOGE("Error opening output stream, sample_rate %u", config->sample_rate);
+ ret = -EINVAL;
+ }
+ }
+
+ if (ret != 0) goto error;
+
out = (struct generic_stream_out *)calloc(1, sizeof(struct generic_stream_out));
out->stream.common.get_sample_rate = out_get_sample_rate;
out->stream.write = out_write;
out->stream.get_render_position = out_get_render_position;
out->stream.get_next_write_timestamp = out_get_next_write_timestamp;
+ out->sample_rate = config->sample_rate;
out->dev = adev;
out->device = devices;
sampling_rates 8000|11025|16000|22050|24000|44100|48000
channel_masks AUDIO_CHANNEL_OUT_MONO|AUDIO_CHANNEL_OUT_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
- devices AUDIO_DEVICE_OUT_SPEAKER
+ devices AUDIO_DEVICE_OUT_SPEAKER|AUDIO_DEVICE_OUT_WIRED_HEADPHONE|AUDIO_DEVICE_OUT_WIRED_HEADSET
flags AUDIO_OUTPUT_FLAG_PRIMARY
}
}
sampling_rates 8000|11025|16000|22050|44100|48000
channel_masks AUDIO_CHANNEL_IN_MONO|AUDIO_CHANNEL_IN_STEREO
formats AUDIO_FORMAT_PCM_16_BIT
- devices AUDIO_DEVICE_IN_BUILTIN_MIC
+ devices AUDIO_DEVICE_IN_BUILTIN_MIC|AUDIO_DEVICE_IN_WIRED_HEADSET
}
}
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+/*
+** Copyright 2017, The Android Open Source Project
+**
+** Licensed under the Apache License, Version 2.0 (the "License");
+** you may not use this file except in compliance with the License.
+** You may obtain a copy of the License at
+**
+** http://www.apache.org/licenses/LICENSE-2.0
+**
+** Unless required by applicable law or agreed to in writing, software
+** distributed under the License is distributed on an "AS IS" BASIS,
+** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+** See the License for the specific language governing permissions and
+** limitations under the License.
+*/
+-->
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <!-- Make this 'true' to allow the Emulator to control
+ the state of the headphone/microphone jack -->
+ <bool name="config_useDevInputEventForAudioJack">true</bool>
+</resources>