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