blob: ce7e3c79b6fbc72bf944f20130ce4172d4373d1c [file] [log] [blame]
Amit Pundirfec74f62020-09-28 12:43:59 +05301/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _YUKAWA_AUDIO_HW_H_
18#define _YUKAWA_AUDIO_HW_H_
19
20#include <hardware/audio.h>
21#include <tinyalsa/asoundlib.h>
22
23#include "fir_filter.h"
24
25#define CARD_OUT 0
26#define PORT_INTERNAL_SPEAKER 0
Caleb Connolly6e92e452021-08-10 09:54:18 +010027#define PORT_HEADSET 1
Amit Pundirfec74f62020-09-28 12:43:59 +053028#define CARD_IN 0
29#define PORT_BUILTIN_MIC 3
30
31#define MIXER_XML_PATH "/vendor/etc/mixer_paths.xml"
32/* Minimum granularity - Arbitrary but small value */
33#define CODEC_BASE_FRAME_COUNT 32
34
35#define CHANNEL_STEREO 2
36
37#ifdef AEC_HAL
38#define NUM_AEC_REFERENCE_CHANNELS 1
39#else
40/* App AEC uses 2-channel reference */
41#define NUM_AEC_REFERENCE_CHANNELS 2
42#endif /* #ifdef AEC_HAL */
43
44#define DEBUG_AEC 0
45
46#define PCM_OPEN_RETRIES 100
47#define PCM_OPEN_WAIT_TIME_MS 20
48
49/* Capture codec parameters */
50/* Set up a capture period of 32 ms:
51 * CAPTURE_PERIOD = PERIOD_SIZE / SAMPLE_RATE, so (32e-3) = PERIOD_SIZE / (16e3)
52 * => PERIOD_SIZE = 512 frames, where each "frame" consists of 1 sample of every channel (here, 2ch) */
53#define CAPTURE_PERIOD_MULTIPLIER 16
54#define CAPTURE_PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * CAPTURE_PERIOD_MULTIPLIER)
55#define CAPTURE_PERIOD_COUNT 4
56#define CAPTURE_PERIOD_START_THRESHOLD 0
57#define CAPTURE_CODEC_SAMPLING_RATE 16000
58
59/* Playback codec parameters */
60/* number of base blocks in a short period (low latency) */
61#define PLAYBACK_PERIOD_MULTIPLIER 32 /* 21 ms */
62/* number of frames per short period (low latency) */
63#define PLAYBACK_PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * PLAYBACK_PERIOD_MULTIPLIER)
64/* number of pseudo periods for low latency playback */
65#define PLAYBACK_PERIOD_COUNT 4
66#define PLAYBACK_PERIOD_START_THRESHOLD 2
67#define PLAYBACK_CODEC_SAMPLING_RATE 48000
68#define MIN_WRITE_SLEEP_US 5000
69
70#define SPEAKER_EQ_FILE "/vendor/etc/speaker_eq_sei610.fir"
71#define SPEAKER_MAX_EQ_LENGTH 512
72
73struct alsa_audio_device {
74 struct audio_hw_device hw_device;
75
76 pthread_mutex_t lock; /* see notes in in_read/out_write on mutex acquisition order */
77 struct alsa_stream_in *active_input;
78 struct alsa_stream_out *active_output;
79 struct audio_route *audio_route;
80 struct mixer *mixer;
81 bool mic_mute;
82 struct aec_t *aec;
Caleb Connolly1f0c1382021-08-10 11:41:23 +010083 int active_port;
Amit Pundirfec74f62020-09-28 12:43:59 +053084};
85
86struct alsa_stream_in {
87 struct audio_stream_in stream;
88
89 pthread_mutex_t lock; /* see note in in_read() on mutex acquisition order */
90 audio_devices_t devices;
91 struct pcm_config config;
92 struct pcm *pcm;
93 bool unavailable;
94 bool standby;
95 struct alsa_audio_device *dev;
96 int read_threshold;
97 unsigned int frames_read;
98 uint64_t timestamp_nsec;
99 audio_source_t source;
100};
101
102struct alsa_stream_out {
103 struct audio_stream_out stream;
104
105 pthread_mutex_t lock; /* see note in out_write() on mutex acquisition order */
106 audio_devices_t devices;
107 struct pcm_config config;
108 struct pcm *pcm;
109 bool unavailable;
110 int standby;
111 struct alsa_audio_device *dev;
112 int write_threshold;
113 unsigned int frames_written;
114 struct timespec timestamp;
115 fir_filter_t* speaker_eq;
116};
117
118/* 'bytes' are the number of bytes written to audio FIFO, for which 'timestamp' is valid.
119 * 'available' is the number of frames available to read (for input) or yet to be played
120 * (for output) frames in the PCM buffer.
121 * timestamp and available are updated by pcm_get_htimestamp(), so they use the same
122 * datatypes as the corresponding arguments to that function. */
123struct aec_info {
124 struct timespec timestamp;
125 uint64_t timestamp_usec;
126 unsigned int available;
127 size_t bytes;
128};
129
130#endif /* #ifndef _YUKAWA_AUDIO_HW_H_ */