-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.h
128 lines (108 loc) · 4.75 KB
/
config.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* This file is part of audio_async_loopback
* Copyright (c) 2020 Jacob Moroni.
*
* 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, version 3.
*
* 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/>.
*/
#ifndef _CONFIG_H_
#define _CONFIG_H_
#define PROGRAM_NAME_STR "audio_async_loopback"
//#define DEBUG 1
/* Use the old FFMPEG AC3 decoding API (for Ubuntu 16.04). */
/* #define FFMPEG_OLD_AUDIO_API 1 */
/* When Pulseaudio is configured for 4 channels (surround 4.0), the
* sink ends up with Front Left, Front Right, Rear Left, Rear Right.
* However, AC3 considers the rear channels "side". If the AC3 mapping
* is used, no audio will come from the rear channels.
* So, when this is undefined, the AC3 "side" channels get mapped
* to the sink "rear" channels.
* I don't think this should ever be defined, but it's here just
* in case.
*/
#undef USE_AC3_SURROUND_MAPPING
/* Input data is read out in chunks of this size (in bytes). */
#define INPUT_CHUNK_SIZE 512u /* 2.6 millisecond chunks */
/* Number of input chunks that must pass without receiving a single
* IEC 61937 data burst before considering the input to be a PCM
* stream.
*/
#define IEC_61937_DETECTION_WINDOW 64u
/* Buffer level measurement averaging depth.
* This is used to smooth out some of the jitter that
* occurs when the buffer utilization is measured.
* This also has side effects on overall loop stability,
* so proceed with caution.
* Must be a power of 2.
*/
#define PCM_SINK_BUFFER_HIST_SIZE 512u
/* Proportional gain for PCM sink buffer utilization
* control loop. The max sampling rate ratio is:
* (PCM_SINK_BUFFER_TARGET_SAMPLES * PCM_SINK_LOOP_GAIN) + 1.
* This is kept low enough to limit the max ratio to something
* that won't result in audible pitch changes.
*/
#define PCM_SINK_LOOP_GAIN 0.000002
/* Number of samples to aim to keep in the buffer right before
* the next chunk is added (so, the minimim utilization).
* This should be as low as possible while still being able to
* get a reasonable measurement. If it's too low, then jitter
* may cause larger buffer depletions to not be accounted for.
* In other words, if your jitter is +- 64 samples, then this
* should at least be 128.
*/
#define PCM_SINK_BUFFER_TARGET_SAMPLES 128
/* PCM sink ring buffer size. Large enough to handle some
* backups, but not so large that it takes forever to each
* the target utilization level.
*/
#define PCM_SINK_SAMPLE_BUFFER_SIZE 2048u
#define PCM_SINK_SAMPLE_BUFFER_SIZE_MASK (PCM_SINK_SAMPLE_BUFFER_SIZE - 1u)
/* Minimum amount of samples that we will attempt to write
* to the PCM sink output stream. Note that this is SAMPLES
* and not L/R frames or bytes.
* NOTE: This must be a multiple of 2 otherwise the Pulseaudio
* sink can become out of sync w.r.t left/right.
*/
#define PCM_SINK_OUTPUT_CHUNK_SIZE 32u
/* PCM sink Pulseaudio output buffer. This directly impacts
* the overall latency, so keep it small, but not so small
* that there are a lot of underruns.
* Even though the sampling rate is being adjusted dynamically
* to maintain a buffer level, systems with high scheduling
* jitter can still underrun/overflow the buffer.
*/
#define PCM_SINK_PA_BUFFER_SIZE 2048u /* 5.3 milliseconds */
/* See comment above about the PCM sink. Note that this is
* 6 times larger than the PCM value divided by two.
* For the PCM sink we write 16 samples per channel, so 32 total,
* so here we write 96.
*/
#define AC3_SINK_OUTPUT_CHUNK_SIZE 96u
/* Same as PCM sink, but adjusted for 6 channels. */
#define AC3_SINK_PA_BUFFER_SIZE 6144u
/* See comment above regarding PCM. Note that this is
* much smaller because AC3 frames arrive at a much lower
* rate than PCM chunks, so in order to keep the loop
* characteristics similar, this had to be reduced.
*/
#define AC3_SINK_BUFFER_HIST_SIZE 128u
/* This is just like the PCM sink, but scaled to compensate
* for 6 channels worth of samples.
*/
#define AC3_SINK_LOOP_GAIN 0.0000006666666666666
/* See PCM comments above. */
#define AC3_SINK_BUFFER_TARGET_SAMPLES 384
/* See PCM comments above. */
#define AC3_SINK_SAMPLE_BUFFER_SIZE 32768u
#define AC3_SINK_SAMPLE_BUFFER_SIZE_MASK (AC3_SINK_SAMPLE_BUFFER_SIZE - 1u)
#endif /* _CONFIG_H_ */