Debian Codegraph @

third_party/rust/cubeb-sys/libcubeb/src/cubeb_resampler.h

raw
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 typedef enum {
25 CUBEB_RESAMPLER_RECLOCK_NONE,
26 CUBEB_RESAMPLER_RECLOCK_INPUT
27 } cubeb_resampler_reclock;
28
29 /**
30 * Create a resampler to adapt the requested sample rate into something that
31 * is accepted by the audio backend.
32 * @param stream A cubeb_stream instance supplied to the data callback.
33 * @param input_params Used to calculate bytes per frame and buffer size for
34 * resampling of the input side of the stream. NULL if input should not be
35 * resampled.
36 * @param output_params Used to calculate bytes per frame and buffer size for
37 * resampling of the output side of the stream. NULL if output should not be
38 * resampled.
39 * @param target_rate The sampling rate after resampling for the input side of
40 * the stream, and/or the sampling rate prior to resampling of the output side
41 * of the stream.
42 * @param callback A callback to request data for resampling.
43 * @param user_ptr User data supplied to the data callback.
44 * @param quality Quality of the resampler.
45 * @retval A non-null pointer if success.
46 */
47 cubeb_resampler *
48 cubeb_resampler_create(cubeb_stream * stream,
49 cubeb_stream_params * input_params,
50 cubeb_stream_params * output_params,
51 unsigned int target_rate, cubeb_data_callback callback,
52 void * user_ptr, cubeb_resampler_quality quality,
53 cubeb_resampler_reclock reclock);
54
55 /**
56 * Fill the buffer with frames acquired using the data callback. Resampling will
57 * happen if necessary.
58 * @param resampler A cubeb_resampler instance.
59 * @param input_buffer A buffer of input samples
60 * @param input_frame_count The size of the buffer. Returns the number of frames
61 * consumed.
62 * @param output_buffer The buffer to be filled.
63 * @param output_frames_needed Number of frames that should be produced.
64 * @retval Number of frames that are actually produced.
65 * @retval CUBEB_ERROR on error.
66 */
67 long
68 cubeb_resampler_fill(cubeb_resampler * resampler, void * input_buffer,
69 long * input_frame_count, void * output_buffer,
70 long output_frames_needed);
71
72 /**
73 * Destroy a cubeb_resampler.
74 * @param resampler A cubeb_resampler instance.
75 */
76 void
77 cubeb_resampler_destroy(cubeb_resampler * resampler);
78
79 /**
80 * Returns the latency, in frames, of the resampler.
81 * @param resampler A cubeb resampler instance.
82 * @retval The latency, in frames, induced by the resampler.
83 */
84 long
85 cubeb_resampler_latency(cubeb_resampler * resampler);
86
87 #if defined(__cplusplus)
88 }
89 #endif
90
91 #endif /* CUBEB_RESAMPLER_H */