• 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 *cras_volume_curve_create_simple_step(
37 		long max_volume,
38 		long volume_step);
39 
40 /* Creates a volume curve with each step's dB value called out.
41  * Args:
42  *    dB_values - Each element specifies what the volume should be set to (in
43  *      dB) for the volume at that index.
44  * Returns:
45  *    A volume curve pointer that should  be passed to
46  *    cras_volume_curve_destroy() when it is no longer needed. If there is an
47  *    error NULL will be returned.
48  */
49 struct cras_volume_curve *cras_volume_curve_create_explicit(
50 		long dB_values[101]);
51 
52 /* Destroys a curve created with cras_volume_curve_create_*.
53  * Args:
54  *    curve - The curve to destroy.
55  */
56 void cras_volume_curve_destroy(struct cras_volume_curve *curve);
57 
58 #endif /* CRAS_VOLUME_CURVE_H_ */
59