1 /*
2 * Copyright (C) 2018-2020 Alexandros Theodotou <alex at zrythm dot org>
3 *
4 * This file is part of Zrythm
5 *
6 * Zrythm is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * Zrythm is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Affero General Public License for more details.
15 *
16 * You should have received a copy of the GNU Affero General Public License
17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef __AUDIO_PAN_H__
21 #define __AUDIO_PAN_H__
22
23 /** The amplitude of -3dBfs (0.707945784f). */
24 #define PAN_MINUS_3DB_AMP (- 0.292054216f)
25
26 /** The amplitude of -6dBfs (0.501187234f). */
27 #define PAN_MINUS_6DB_AMP (- 0.498812766f)
28
29 /**
30 * \file
31 *
32 * Panning mono sources.
33 */
34
35 /**
36 * These are only useful when changing mono to
37 * stereo.
38 *
39 * No compensation is needed for stereo to stereo.
40 * See https://www.hackaudio.com/digital-signal-processing/stereo-audio/square-law-panning/
41 */
42 typedef enum PanLaw
43 {
44 PAN_LAW_0DB,
45 PAN_LAW_MINUS_3DB,
46 PAN_LAW_MINUS_6DB
47 } PanLaw;
48
49 static const char * pan_law_str[] =
50 {
51 /* TRANSLATORS: decibels */
52 __("0dB"),
53 __("-3dB"),
54 __("-6dB"),
55 };
56
57 static inline const char *
pan_law_to_string(PanLaw pan_law)58 pan_law_to_string (
59 PanLaw pan_law)
60 {
61 return pan_law_str[pan_law];
62 }
63
64 /**
65 * See https://www.harmonycentral.com/articles/the-truth-about-panning-laws
66 */
67 typedef enum PanAlgorithm
68 {
69 PAN_ALGORITHM_LINEAR,
70 PAN_ALGORITHM_SQUARE_ROOT,
71 PAN_ALGORITHM_SINE_LAW
72 } PanAlgorithm;
73
74 static const char * pan_algorithm_str[] =
75 {
76 __("Linear"),
77 __("Square Root"),
78 __("Sine"),
79 };
80
81 static inline const char *
pan_algorithm_to_string(PanAlgorithm pan_algo)82 pan_algorithm_to_string (
83 PanAlgorithm pan_algo)
84 {
85 return pan_algorithm_str[pan_algo];
86 }
87
88 void
89 pan_get_calc_lr (
90 PanLaw law,
91 PanAlgorithm algo,
92 float pan,
93 float * calc_l,
94 float * calc_r);
95
96 #endif
97