• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2  * Use of this source code is governed by a BSD-style license that can be
3  * found in the LICENSE file.
4  */
5 
6 #include <stddef.h>
7 #include <stdlib.h>
8 
9 #include "cras_volume_curve.h"
10 #include "softvol_curve.h"
11 
12 /* This is a ramp that increases 0.5dB per step, for a total range of 50dB. */
13 const float softvol_scalers[101] = {
14 	0.003162, /* volume 0 */
15 	0.003350,
16 	0.003548,
17 	0.003758,
18 	0.003981,
19 	0.004217,
20 	0.004467,
21 	0.004732,
22 	0.005012,
23 	0.005309,
24 	0.005623,
25 	0.005957,
26 	0.006310,
27 	0.006683,
28 	0.007079,
29 	0.007499,
30 	0.007943,
31 	0.008414,
32 	0.008913,
33 	0.009441,
34 	0.010000,
35 	0.010593,
36 	0.011220,
37 	0.011885,
38 	0.012589,
39 	0.013335,
40 	0.014125,
41 	0.014962,
42 	0.015849,
43 	0.016788,
44 	0.017783,
45 	0.018836,
46 	0.019953,
47 	0.021135,
48 	0.022387,
49 	0.023714,
50 	0.025119,
51 	0.026607,
52 	0.028184,
53 	0.029854,
54 	0.031623,
55 	0.033497,
56 	0.035481,
57 	0.037584,
58 	0.039811,
59 	0.042170,
60 	0.044668,
61 	0.047315,
62 	0.050119,
63 	0.053088,
64 	0.056234,
65 	0.059566,
66 	0.063096,
67 	0.066834,
68 	0.070795,
69 	0.074989,
70 	0.079433,
71 	0.084140,
72 	0.089125,
73 	0.094406,
74 	0.100000,
75 	0.105925,
76 	0.112202,
77 	0.118850,
78 	0.125893,
79 	0.133352,
80 	0.141254,
81 	0.149624,
82 	0.158489,
83 	0.167880,
84 	0.177828,
85 	0.188365,
86 	0.199526,
87 	0.211349,
88 	0.223872,
89 	0.237137,
90 	0.251189,
91 	0.266073,
92 	0.281838,
93 	0.298538,
94 	0.316228,
95 	0.334965,
96 	0.354813,
97 	0.375837,
98 	0.398107,
99 	0.421697,
100 	0.446684,
101 	0.473151,
102 	0.501187,
103 	0.530884,
104 	0.562341,
105 	0.595662,
106 	0.630957,
107 	0.668344,
108 	0.707946,
109 	0.749894,
110 	0.794328,
111 	0.841395,
112 	0.891251,
113 	0.944061,
114 	1.000000, /* volume 100 */
115 };
116 
softvol_build_from_curve(const struct cras_volume_curve * curve)117 float *softvol_build_from_curve(const struct cras_volume_curve *curve)
118 {
119 	float *scalers;
120 	unsigned int volume;
121 
122 	if (!curve)
123 		return NULL;
124 
125 	scalers = (float *)malloc(NUM_VOLUME_STEPS * sizeof(float));
126 	if (!scalers)
127 		return NULL;
128 
129 	/* When software volume is used, it is assumed all volume curve values
130 	 * are relative to 0 dBFS when converting to scale. If a positive dBFS
131 	 * value is specified in curve config, it will be treated as invalid
132 	 * and clip to 1.0 in scale.
133 	 */
134 	for (volume = 0; volume <= MAX_VOLUME; volume++) {
135 		scalers[volume] = convert_softvol_scaler_from_dB(
136 				curve->get_dBFS(curve, volume));
137 		if (scalers[volume] > 1.0)
138 			scalers[volume] = 1.0;
139 	}
140 
141 	return scalers;
142 }
143