Home | History | Annotate | Download | only in server
      1 /* Copyright (c) 2014 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 LINEAR_RESAMPLER_H_
      7 #define LINEAR_RESAMPLER_H_
      8 
      9 
     10 struct linear_resampler;
     11 
     12 /* Creates a linear resampler.
     13  * Args:
     14  *    num_channels - The number of channels in each frames.
     15  *    format_bytes - The length of one frame in bytes.
     16  *    src_rate - The source rate to resample from.
     17  *    dst_rate - The destination rate to resample to.
     18  */
     19 struct linear_resampler *linear_resampler_create(unsigned int num_channels,
     20 						 unsigned int format_bytes,
     21 						 float src_rate,
     22 						 float dst_rate);
     23 
     24 /* Sets the rates for the linear resampler.
     25  * Args:
     26  *    from - The rate to resample from.
     27  *    to - The rate to resample to.
     28  */
     29 void linear_resampler_set_rates(struct linear_resampler *lr,
     30 				float from,
     31 				float to);
     32 
     33 /* Converts the frames count from output rate to input rate. */
     34 unsigned int linear_resampler_out_frames_to_in(struct linear_resampler *lr,
     35                                                unsigned int frames);
     36 
     37 /* Converts the frames count from input rate to output rate. */
     38 unsigned int linear_resampler_in_frames_to_out(struct linear_resampler *lr,
     39 					       unsigned int frames);
     40 
     41 /* Returns true if SRC is needed, otherwise return false. */
     42 int linear_resampler_needed(struct linear_resampler *lr);
     43 
     44 /* Run linear resample for audio samples.
     45  * Args:
     46  *    lr - The linear resampler.
     47  *    src - The input buffer.
     48  *    src_frames - The number of frames of input buffer.
     49  *    dst - The output buffer.
     50  *    dst_frames - The number of frames of output buffer.
     51  */
     52 unsigned int linear_resampler_resample(struct linear_resampler *lr,
     53 			     uint8_t *src,
     54 			     unsigned int *src_frames,
     55 			     uint8_t *dst,
     56 			     unsigned dst_frames);
     57 
     58 /* Destroy a linear resampler. */
     59 void linear_resampler_destroy(struct linear_resampler *lr);
     60 
     61 #endif /* LINEAR_RESAMPLER_H_ */
     62