|
1 # HG changeset patch |
|
2 # Parent 091c02c13c8ba50903248432d0c7561104dace21 |
|
3 # User Karl Tomlinson <karlt+@karlt.net> |
|
4 b=913854 add speex_resampler_set_skip_frac_num r=jmspeex |
|
5 |
|
6 This allows a client to align output samples consistently for independent |
|
7 resampling of contiguous input buffers. |
|
8 |
|
9 diff --git a/layout/media/symbols.def.in b/layout/media/symbols.def.in |
|
10 --- a/layout/media/symbols.def.in |
|
11 +++ b/layout/media/symbols.def.in |
|
12 @@ -122,16 +122,17 @@ speex_resampler_set_quality |
|
13 speex_resampler_get_quality |
|
14 speex_resampler_set_input_stride |
|
15 speex_resampler_get_input_stride |
|
16 speex_resampler_set_output_stride |
|
17 speex_resampler_get_output_stride |
|
18 speex_resampler_get_input_latency |
|
19 speex_resampler_get_output_latency |
|
20 speex_resampler_skip_zeros |
|
21 +speex_resampler_set_skip_frac_num |
|
22 speex_resampler_reset_mem |
|
23 speex_resampler_strerror |
|
24 cubeb_destroy |
|
25 cubeb_init |
|
26 cubeb_get_max_channel_count |
|
27 cubeb_get_min_latency |
|
28 cubeb_get_preferred_sample_rate |
|
29 cubeb_stream_destroy |
|
30 diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c |
|
31 --- a/media/libspeex_resampler/src/resample.c |
|
32 +++ b/media/libspeex_resampler/src/resample.c |
|
33 @@ -1138,16 +1138,28 @@ SPX_RESAMPLE_EXPORT int speex_resampler_ |
|
34 SPX_RESAMPLE_EXPORT int speex_resampler_skip_zeros(SpeexResamplerState *st) |
|
35 { |
|
36 spx_uint32_t i; |
|
37 for (i=0;i<st->nb_channels;i++) |
|
38 st->last_sample[i] = st->filt_len/2; |
|
39 return RESAMPLER_ERR_SUCCESS; |
|
40 } |
|
41 |
|
42 +SPX_RESAMPLE_EXPORT int speex_resampler_set_skip_frac_num(SpeexResamplerState *st, spx_uint32_t skip_frac_num) |
|
43 +{ |
|
44 + spx_uint32_t i; |
|
45 + spx_uint32_t last_sample = skip_frac_num / st->den_rate; |
|
46 + spx_uint32_t samp_frac_num = skip_frac_num % st->den_rate; |
|
47 + for (i=0;i<st->nb_channels;i++) { |
|
48 + st->last_sample[i] = last_sample; |
|
49 + st->samp_frac_num[i] = samp_frac_num; |
|
50 + } |
|
51 + return RESAMPLER_ERR_SUCCESS; |
|
52 +} |
|
53 + |
|
54 SPX_RESAMPLE_EXPORT int speex_resampler_reset_mem(SpeexResamplerState *st) |
|
55 { |
|
56 spx_uint32_t i; |
|
57 for (i=0;i<st->nb_channels;i++) |
|
58 { |
|
59 st->last_sample[i] = 0; |
|
60 st->magic_samples[i] = 0; |
|
61 st->samp_frac_num[i] = 0; |
|
62 diff --git a/media/libspeex_resampler/src/speex_resampler.h b/media/libspeex_resampler/src/speex_resampler.h |
|
63 --- a/media/libspeex_resampler/src/speex_resampler.h |
|
64 +++ b/media/libspeex_resampler/src/speex_resampler.h |
|
65 @@ -69,16 +69,17 @@ |
|
66 #define speex_resampler_get_quality CAT_PREFIX(RANDOM_PREFIX,_resampler_get_quality) |
|
67 #define speex_resampler_set_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_input_stride) |
|
68 #define speex_resampler_get_input_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_stride) |
|
69 #define speex_resampler_set_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_set_output_stride) |
|
70 #define speex_resampler_get_output_stride CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_stride) |
|
71 #define speex_resampler_get_input_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_input_latency) |
|
72 #define speex_resampler_get_output_latency CAT_PREFIX(RANDOM_PREFIX,_resampler_get_output_latency) |
|
73 #define speex_resampler_skip_zeros CAT_PREFIX(RANDOM_PREFIX,_resampler_skip_zeros) |
|
74 +#define speex_resampler_set_skip_frac_num CAT_PREFIX(RANDOM_PREFIX,_resampler_set_skip_frac_num) |
|
75 #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem) |
|
76 #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror) |
|
77 |
|
78 #define spx_int16_t short |
|
79 #define spx_int32_t int |
|
80 #define spx_uint16_t unsigned short |
|
81 #define spx_uint32_t unsigned int |
|
82 |
|
83 @@ -321,16 +322,32 @@ int speex_resampler_get_output_latency(S |
|
84 * resampler. It is recommended to use that when resampling an audio file, as |
|
85 * it will generate a file with the same length. For real-time processing, |
|
86 * it is probably easier not to use this call (so that the output duration |
|
87 * is the same for the first frame). |
|
88 * @param st Resampler state |
|
89 */ |
|
90 int speex_resampler_skip_zeros(SpeexResamplerState *st); |
|
91 |
|
92 +/** Set the numerator in a fraction determining the advance through input |
|
93 + * samples before writing any output samples. The denominator of the fraction |
|
94 + * is the value returned from speex_resampler_get_ratio() in ratio_den. This |
|
95 + * is only useful before starting to use a newly created or reset resampler. |
|
96 + * If the first input sample is interpreted as the signal at time |
|
97 + * input_latency*in_rate, then the first output sample represents the signal |
|
98 + * at the time frac_num/ratio_num*out_rate. |
|
99 + * This is intended for careful alignment of output sample points wrt input |
|
100 + * sample points. Large values are not an efficient offset into the in buffer. |
|
101 + * @param st Resampler state |
|
102 + * @param skip_frac_num Numerator of the offset fraction, |
|
103 + * between 0 and ratio_den-1. |
|
104 + */ |
|
105 +int speex_resampler_set_skip_frac_num(SpeexResamplerState *st, |
|
106 + spx_uint32_t skip_frac_num); |
|
107 + |
|
108 /** Reset a resampler so a new (unrelated) stream can be processed. |
|
109 * @param st Resampler state |
|
110 */ |
|
111 int speex_resampler_reset_mem(SpeexResamplerState *st); |
|
112 |
|
113 /** Returns the English meaning for an error code |
|
114 * @param err Error code |
|
115 * @return English string |