]> code.delx.au - pulseaudio/blob - src/pulsecore/resampler.h
remap: Make resampler's remap structure more self-contained
[pulseaudio] / src / pulsecore / resampler.h
1 #ifndef fooresamplerhfoo
2 #define fooresamplerhfoo
3
4 /***
5 This file is part of PulseAudio.
6
7 Copyright 2004-2006 Lennart Poettering
8
9 PulseAudio is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published
11 by the Free Software Foundation; either version 2.1 of the License,
12 or (at your option) any later version.
13
14 PulseAudio is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with PulseAudio; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
22 USA.
23 ***/
24
25 #include <pulse/sample.h>
26 #include <pulse/channelmap.h>
27 #include <pulsecore/memblock.h>
28 #include <pulsecore/memchunk.h>
29
30 typedef struct pa_resampler pa_resampler;
31 typedef struct pa_resampler_impl pa_resampler_impl;
32
33 struct pa_resampler_impl {
34 void (*free)(pa_resampler *r);
35 void (*update_rates)(pa_resampler *r);
36
37 /* Returns the number of leftover frames in the input buffer. */
38 unsigned (*resample)(pa_resampler *r, const pa_memchunk *in, unsigned in_n_frames, pa_memchunk *out, unsigned *out_n_frames);
39
40 void (*reset)(pa_resampler *r);
41 void *data;
42 };
43
44 typedef enum pa_resample_method {
45 PA_RESAMPLER_INVALID = -1,
46 PA_RESAMPLER_SRC_SINC_BEST_QUALITY = 0, /* = SRC_SINC_BEST_QUALITY */
47 PA_RESAMPLER_SRC_SINC_MEDIUM_QUALITY = 1, /* = SRC_SINC_MEDIUM_QUALITY */
48 PA_RESAMPLER_SRC_SINC_FASTEST = 2, /* = SRC_SINC_FASTEST */
49 PA_RESAMPLER_SRC_ZERO_ORDER_HOLD = 3, /* = SRC_ZERO_ORDER_HOLD */
50 PA_RESAMPLER_SRC_LINEAR = 4, /* = SRC_LINEAR */
51 PA_RESAMPLER_TRIVIAL,
52 PA_RESAMPLER_SPEEX_FLOAT_BASE,
53 PA_RESAMPLER_SPEEX_FLOAT_MAX = PA_RESAMPLER_SPEEX_FLOAT_BASE + 10,
54 PA_RESAMPLER_SPEEX_FIXED_BASE,
55 PA_RESAMPLER_SPEEX_FIXED_MAX = PA_RESAMPLER_SPEEX_FIXED_BASE + 10,
56 PA_RESAMPLER_FFMPEG,
57 PA_RESAMPLER_AUTO, /* automatic select based on sample format */
58 PA_RESAMPLER_COPY,
59 PA_RESAMPLER_PEAKS,
60 PA_RESAMPLER_MAX
61 } pa_resample_method_t;
62
63 typedef enum pa_resample_flags {
64 PA_RESAMPLER_VARIABLE_RATE = 0x0001U,
65 PA_RESAMPLER_NO_REMAP = 0x0002U, /* implies NO_REMIX */
66 PA_RESAMPLER_NO_REMIX = 0x0004U,
67 PA_RESAMPLER_NO_LFE = 0x0008U
68 } pa_resample_flags_t;
69
70 pa_resampler* pa_resampler_new(
71 pa_mempool *pool,
72 const pa_sample_spec *a,
73 const pa_channel_map *am,
74 const pa_sample_spec *b,
75 const pa_channel_map *bm,
76 pa_resample_method_t resample_method,
77 pa_resample_flags_t flags);
78
79 void pa_resampler_free(pa_resampler *r);
80
81 /* Returns the size of an input memory block which is required to return the specified amount of output data */
82 size_t pa_resampler_request(pa_resampler *r, size_t out_length);
83
84 /* Inverse of pa_resampler_request() */
85 size_t pa_resampler_result(pa_resampler *r, size_t in_length);
86
87 /* Returns the maximum size of input blocks we can process without needing bounce buffers larger than the mempool tile size. */
88 size_t pa_resampler_max_block_size(pa_resampler *r);
89
90 /* Pass the specified memory chunk to the resampler and return the newly resampled data */
91 void pa_resampler_run(pa_resampler *r, const pa_memchunk *in, pa_memchunk *out);
92
93 /* Change the input rate of the resampler object */
94 void pa_resampler_set_input_rate(pa_resampler *r, uint32_t rate);
95
96 /* Change the output rate of the resampler object */
97 void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate);
98
99 /* Reinitialize state of the resampler, possibly due to seeking or other discontinuities */
100 void pa_resampler_reset(pa_resampler *r);
101
102 /* Return the resampling method of the resampler object */
103 pa_resample_method_t pa_resampler_get_method(pa_resampler *r);
104
105 /* Try to parse the resampler method */
106 pa_resample_method_t pa_parse_resample_method(const char *string);
107
108 /* return a human readable string for the specified resampling method. Inverse of pa_parse_resample_method() */
109 const char *pa_resample_method_to_string(pa_resample_method_t m);
110
111 /* Return 1 when the specified resampling method is supported */
112 int pa_resample_method_supported(pa_resample_method_t m);
113
114 const pa_channel_map* pa_resampler_input_channel_map(pa_resampler *r);
115 const pa_sample_spec* pa_resampler_input_sample_spec(pa_resampler *r);
116 const pa_channel_map* pa_resampler_output_channel_map(pa_resampler *r);
117 const pa_sample_spec* pa_resampler_output_sample_spec(pa_resampler *r);
118
119 #endif