blob: f6649ce4ab7247315e88a09da6719f2ae3641807 [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
27#define CARD_IN 0
28#define PORT_BUILTIN_MIC 3
29
30#define MIXER_XML_PATH "/vendor/etc/mixer_paths.xml"
31/* Minimum granularity - Arbitrary but small value */
32#define CODEC_BASE_FRAME_COUNT 32
33
34#define CHANNEL_STEREO 2
35
36#ifdef AEC_HAL
37#define NUM_AEC_REFERENCE_CHANNELS 1
38#else
39/* App AEC uses 2-channel reference */
40#define NUM_AEC_REFERENCE_CHANNELS 2
41#endif /* #ifdef AEC_HAL */
42
43#define DEBUG_AEC 0
44
45#define PCM_OPEN_RETRIES 100
46#define PCM_OPEN_WAIT_TIME_MS 20
47
48/* Capture codec parameters */
49/* Set up a capture period of 32 ms:
50 * CAPTURE_PERIOD = PERIOD_SIZE / SAMPLE_RATE, so (32e-3) = PERIOD_SIZE / (16e3)
51 * => PERIOD_SIZE = 512 frames, where each "frame" consists of 1 sample of every channel (here, 2ch) */
52#define CAPTURE_PERIOD_MULTIPLIER 16
53#define CAPTURE_PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * CAPTURE_PERIOD_MULTIPLIER)
54#define CAPTURE_PERIOD_COUNT 4
55#define CAPTURE_PERIOD_START_THRESHOLD 0
56#define CAPTURE_CODEC_SAMPLING_RATE 16000
57
58/* Playback codec parameters */
59/* number of base blocks in a short period (low latency) */
60#define PLAYBACK_PERIOD_MULTIPLIER 32 /* 21 ms */
61/* number of frames per short period (low latency) */
62#define PLAYBACK_PERIOD_SIZE (CODEC_BASE_FRAME_COUNT * PLAYBACK_PERIOD_MULTIPLIER)
63/* number of pseudo periods for low latency playback */
64#define PLAYBACK_PERIOD_COUNT 4
65#define PLAYBACK_PERIOD_START_THRESHOLD 2
66#define PLAYBACK_CODEC_SAMPLING_RATE 48000
67#define MIN_WRITE_SLEEP_US 5000
68
69#define SPEAKER_EQ_FILE "/vendor/etc/speaker_eq_sei610.fir"
70#define SPEAKER_MAX_EQ_LENGTH 512
71
72struct alsa_audio_device {
73 struct audio_hw_device hw_device;
74
75 pthread_mutex_t lock; /* see notes in in_read/out_write on mutex acquisition order */
76 struct alsa_stream_in *active_input;
77 struct alsa_stream_out *active_output;
78 struct audio_route *audio_route;
79 struct mixer *mixer;
80 bool mic_mute;
81 struct aec_t *aec;
82};
83
84struct alsa_stream_in {
85 struct audio_stream_in stream;
86
87 pthread_mutex_t lock; /* see note in in_read() on mutex acquisition order */
88 audio_devices_t devices;
89 struct pcm_config config;
90 struct pcm *pcm;
91 bool unavailable;
92 bool standby;
93 struct alsa_audio_device *dev;
94 int read_threshold;
95 unsigned int frames_read;
96 uint64_t timestamp_nsec;
97 audio_source_t source;
98};
99
100struct alsa_stream_out {
101 struct audio_stream_out stream;
102
103 pthread_mutex_t lock; /* see note in out_write() on mutex acquisition order */
104 audio_devices_t devices;
105 struct pcm_config config;
106 struct pcm *pcm;
107 bool unavailable;
108 int standby;
109 struct alsa_audio_device *dev;
110 int write_threshold;
111 unsigned int frames_written;
112 struct timespec timestamp;
113 fir_filter_t* speaker_eq;
114};
115
116/* 'bytes' are the number of bytes written to audio FIFO, for which 'timestamp' is valid.
117 * 'available' is the number of frames available to read (for input) or yet to be played
118 * (for output) frames in the PCM buffer.
119 * timestamp and available are updated by pcm_get_htimestamp(), so they use the same
120 * datatypes as the corresponding arguments to that function. */
121struct aec_info {
122 struct timespec timestamp;
123 uint64_t timestamp_usec;
124 unsigned int available;
125 size_t bytes;
126};
127
128#endif /* #ifndef _YUKAWA_AUDIO_HW_H_ */