Home | History | Annotate | Download | only in server
      1 /* Copyright 2016 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_RAMP_H_
      7 #define CRAS_RAMP_H_
      8 
      9 #include "cras_iodev.h"
     10 
     11 struct cras_ramp;
     12 
     13 /*
     14  * Infomation telling user how to do ramping.
     15  * action CRAS_RAMP_ACTION_NONE: No scale should be applied.
     16  * action CRAS_RAMP_ACTION_PARTIAL: scale sample by sample starting from scaler
     17  *                                  and increase increment for each sample.
     18  * action CRAS_RAMP_ACTION_INVALID: There is an error in cras_ramp.
     19  */
     20 enum CRAS_RAMP_ACTION_TYPE {
     21 	CRAS_RAMP_ACTION_NONE,
     22 	CRAS_RAMP_ACTION_PARTIAL,
     23 	CRAS_RAMP_ACTION_INVALID,
     24 };
     25 
     26 /*
     27  * Struct to hold current ramping action for user.
     28  * Members:
     29  *   type: See CRAS_RAMP_ACTION_TYPE.
     30  *   scaler: The initial scaler to be applied.
     31  *   increment: The scaler increment that should be added to scaler for every
     32  *              frame.
     33  */
     34 struct cras_ramp_action {
     35 	enum CRAS_RAMP_ACTION_TYPE type;
     36 	float scaler;
     37 	float increment;
     38 };
     39 
     40 typedef void (*cras_ramp_cb)(void *arg);
     41 
     42 /* Creates a ramp. */
     43 struct cras_ramp* cras_ramp_create();
     44 
     45 /* Destroys a ramp. */
     46 void cras_ramp_destroy(struct cras_ramp* ramp);
     47 
     48 /* Starts ramping up from 0 to 1 or from 1 to 0 for duration_frames frames.
     49  * Args:
     50  *   ramp[in]: The ramp struct to start.
     51  *   is_up[in]: 1 to ramp up and 0 to ramp down.
     52  *   duration_frames[in]: Ramp duration in frames.
     53  *   cb[in]: The callback function to call after ramping is done. User can set
     54  *           cb to turn off speaker/headphone switch after ramping down
     55  *           is done.
     56  *   cb_data[in]: The data passed to callback function.
     57  * Returns:
     58  *   0 on success; negative error code on failure.
     59  */
     60 int cras_ramp_start(struct cras_ramp *ramp, int is_up, int duration_frames,
     61 		    cras_ramp_cb cb, void *cb_data);
     62 
     63 /* Resets ramp and cancels current ramping. */
     64 int cras_ramp_reset(struct cras_ramp *ramp);
     65 
     66 /* Gets current ramp action. */
     67 struct cras_ramp_action cras_ramp_get_current_action(
     68 		const struct cras_ramp *ramp);
     69 
     70 /* Updates number of samples that went through ramping. */
     71 int cras_ramp_update_ramped_frames(
     72 		struct cras_ramp *ramp, int num_frames);
     73 
     74 #endif /* CRAS_RAMP_H_ */
     75