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