1 /* 2 * Copyright © 2014 Mozilla Foundation 3 * 4 * This program is made available under an ISC-style license. See the 5 * accompanying file LICENSE for details. 6 */ 7 #ifndef CUBEB_RESAMPLER_H 8 #define CUBEB_RESAMPLER_H 9 10 #include "cubeb/cubeb.h" 11 12 #if defined(__cplusplus) 13 extern "C" { 14 #endif 15 16 typedef struct cubeb_resampler cubeb_resampler; 17 18 typedef enum { 19 CUBEB_RESAMPLER_QUALITY_VOIP, 20 CUBEB_RESAMPLER_QUALITY_DEFAULT, 21 CUBEB_RESAMPLER_QUALITY_DESKTOP 22 } cubeb_resampler_quality; 23 24 /** 25 * Create a resampler to adapt the requested sample rate into something that 26 * is accepted by the audio backend. 27 * @param stream A cubeb_stream instance supplied to the data callback. 28 * @param input_params Used to calculate bytes per frame and buffer size for 29 * resampling of the input side of the stream. NULL if input should not be 30 * resampled. 31 * @param output_params Used to calculate bytes per frame and buffer size for 32 * resampling of the output side of the stream. NULL if output should not be 33 * resampled. 34 * @param target_rate The sampling rate after resampling for the input side of 35 * the stream, and/or the sampling rate prior to resampling of the output side 36 * of the stream. 37 * @param callback A callback to request data for resampling. 38 * @param user_ptr User data supplied to the data callback. 39 * @param quality Quality of the resampler. 40 * @retval A non-null pointer if success. 41 */ 42 cubeb_resampler * 43 cubeb_resampler_create(cubeb_stream * stream, 44 cubeb_stream_params * input_params, 45 cubeb_stream_params * output_params, 46 unsigned int target_rate, cubeb_data_callback callback, 47 void * user_ptr, cubeb_resampler_quality quality); 48 49 /** 50 * Fill the buffer with frames acquired using the data callback. Resampling will 51 * happen if necessary. 52 * @param resampler A cubeb_resampler instance. 53 * @param input_buffer A buffer of input samples 54 * @param input_frame_count The size of the buffer. Returns the number of frames 55 * consumed. 56 * @param output_buffer The buffer to be filled. 57 * @param output_frames_needed Number of frames that should be produced. 58 * @retval Number of frames that are actually produced. 59 * @retval CUBEB_ERROR on error. 60 */ 61 long 62 cubeb_resampler_fill(cubeb_resampler * resampler, void * input_buffer, 63 long * input_frame_count, void * output_buffer, 64 long output_frames_needed); 65 66 /** 67 * Destroy a cubeb_resampler. 68 * @param resampler A cubeb_resampler instance. 69 */ 70 void 71 cubeb_resampler_destroy(cubeb_resampler * resampler); 72 73 /** 74 * Returns the latency, in frames, of the resampler. 75 * @param resampler A cubeb resampler instance. 76 * @retval The latency, in frames, induced by the resampler. 77 */ 78 long 79 cubeb_resampler_latency(cubeb_resampler * resampler); 80 81 #if defined(__cplusplus) 82 } 83 #endif 84 85 #endif /* CUBEB_RESAMPLER_H */ 86