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 * cubeb_resampler_create(cubeb_stream * stream, 43 cubeb_stream_params * input_params, 44 cubeb_stream_params * output_params, 45 unsigned int target_rate, 46 cubeb_data_callback callback, 47 void * user_ptr, 48 cubeb_resampler_quality quality); 49 50 /** 51 * Fill the buffer with frames acquired using the data callback. Resampling will 52 * happen if necessary. 53 * @param resampler A cubeb_resampler instance. 54 * @param input_buffer A buffer of input samples 55 * @param input_frame_count The size of the buffer. Returns the number of frames 56 * consumed. 57 * @param output_buffer The buffer to be filled. 58 * @param output_frames_needed Number of frames that should be produced. 59 * @retval Number of frames that are actually produced. 60 * @retval CUBEB_ERROR on error. 61 */ 62 long cubeb_resampler_fill(cubeb_resampler * resampler, 63 void * input_buffer, 64 long * input_frame_count, 65 void * output_buffer, 66 long output_frames_needed); 67 68 /** 69 * Destroy a cubeb_resampler. 70 * @param resampler A cubeb_resampler instance. 71 */ 72 void cubeb_resampler_destroy(cubeb_resampler * resampler); 73 74 /** 75 * Returns the latency, in frames, of the resampler. 76 * @param resampler A cubeb resampler instance. 77 * @retval The latency, in frames, induced by the resampler. 78 */ 79 long cubeb_resampler_latency(cubeb_resampler * resampler); 80 81 #if defined(__cplusplus) 82 } 83 #endif 84 85 #endif /* CUBEB_RESAMPLER_H */ 86