• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (c) 2012 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 #ifndef CRAS_VOLUME_CURVE_H_
7 #define CRAS_VOLUME_CURVE_H_
8 
9 #define MAX_VOLUME 100
10 #define NUM_VOLUME_STEPS (MAX_VOLUME + 1) /* 0-100 inclusive. */
11 
12 /* Holds the function that converts from a volume index to a dBFS value. */
13 struct cras_volume_curve {
14 	/* Function to convert from index to dBFS value.
15 	 * Args:
16 	 *    curve - A curve from cras_volume_curve_create_* functions.
17 	 *    volume - The volume level from 0 to 100.
18 	 * Returns:
19 	 *    The volume to apply in dB * 100.  This value will normally be
20 	 *    negative and is means dB down from full scale.
21 	 */
22 	long (*get_dBFS)(const struct cras_volume_curve *curve, size_t volume);
23 };
24 
25 /* Creates a system-default volume curve. The default curve maps one volume step
26  * to 1 dB down.
27  * Returns null on error, or the new volume curve on success.
28  */
29 struct cras_volume_curve *cras_volume_curve_create_default();
30 
31 /* Creates a volume curve with a specified max volume and step.
32  * Args:
33  *    max_volume - Maximum volume allowed in dBFS.
34  *    volume_step - Number of dB to change for one volume tick.
35  */
36 struct cras_volume_curve *
37 cras_volume_curve_create_simple_step(long max_volume, long volume_step);
38 
39 /* Creates a volume curve with each step's dB value called out.
40  * Args:
41  *    dB_values - Each element specifies what the volume should be set to (in
42  *      dB) for the volume at that index.
43  * Returns:
44  *    A volume curve pointer that should  be passed to
45  *    cras_volume_curve_destroy() when it is no longer needed. If there is an
46  *    error NULL will be returned.
47  */
48 struct cras_volume_curve *
49 cras_volume_curve_create_explicit(long dB_values[101]);
50 
51 /* Destroys a curve created with cras_volume_curve_create_*.
52  * Args:
53  *    curve - The curve to destroy.
54  */
55 void cras_volume_curve_destroy(struct cras_volume_curve *curve);
56 
57 #endif /* CRAS_VOLUME_CURVE_H_ */
58