PulseAudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
- by the Free Software Foundation; either version 2 of the License,
+ by the Free Software Foundation; either version 2.1 of the License,
or (at your option) any later version.
PulseAudio is distributed in the hope that it will be useful, but
#include <speex/speex_resampler.h>
-#include <liboil/liboilfuncs.h>
-#include <liboil/liboil.h>
-
#include <pulse/xmalloc.h>
#include <pulsecore/sconv.h>
#include <pulsecore/log.h>
[PA_RESAMPLER_PEAKS] = peaks_init,
};
-static inline size_t sample_size(pa_sample_format_t f) {
- pa_sample_spec ss = {
- .format = f,
- .rate = 0,
- .channels = 1
- };
-
- return pa_sample_size(&ss);
-}
-
pa_resampler* pa_resampler_new(
pa_mempool *pool,
const pa_sample_spec *a,
pa_log_info("Using %s as working format.", pa_sample_format_to_string(r->work_format));
- r->w_sz = sample_size(r->work_format);
+ r->w_sz = pa_sample_size_of_format(r->work_format);
if (r->i_ss.format == r->work_format)
r->to_work_format_func = NULL;
size_t pa_resampler_request(pa_resampler *r, size_t out_length) {
pa_assert(r);
- return (((out_length / r->o_fz)*r->i_ss.rate)/r->o_ss.rate) * r->i_fz;
+ /* Let's round up here */
+
+ return (((((out_length + r->o_fz-1) / r->o_fz) * r->i_ss.rate) + r->o_ss.rate-1) / r->o_ss.rate) * r->i_fz;
}
size_t pa_resampler_result(pa_resampler *r, size_t in_length) {
pa_assert(r);
- return (((in_length / r->i_fz)*r->o_ss.rate)/r->i_ss.rate) * r->o_fz;
+ /* Let's round up here */
+
+ return (((((in_length + r->i_fz-1) / r->i_fz) * r->o_ss.rate) + r->i_ss.rate-1) / r->i_ss.rate) * r->o_fz;
}
size_t pa_resampler_max_block_size(pa_resampler *r) {
return &r->buf1;
}
-static void vectoradd_s16_with_fraction(
- int16_t *d, int dstr,
- const int16_t *s1, int sstr1,
- const int16_t *s2, int sstr2,
- int n,
- float s3, float s4) {
+static void vectoradd_f32(
+ float *d, int dstr,
+ const float *s, int sstr,
+ int n, float s4) {
- int32_t i3, i4;
+ for (; n > 0; n--) {
+ *d = (float) (*d + (s4 * *s));
- i3 = (int32_t) (s3 * 0x10000);
- i4 = (int32_t) (s4 * 0x10000);
+ s = (const float*) ((const uint8_t*) s + sstr);
+ d = (float*) ((uint8_t*) d + dstr);
+ }
+}
+
+static void vectoradd_s16(
+ int16_t *d, int dstr,
+ const int16_t *s, int sstr,
+ int n) {
for (; n > 0; n--) {
- int32_t a, b;
+ *d = (int16_t) (*d + *s);
- a = *s1;
- b = *s2;
+ s = (const int16_t*) ((const uint8_t*) s + sstr);
+ d = (int16_t*) ((uint8_t*) d + dstr);
+ }
+}
- a = (a * i3) / 0x10000;
- b = (b * i4) / 0x10000;
+static void vectoradd_s16_with_fraction(
+ int16_t *d, int dstr,
+ const int16_t *s, int sstr,
+ int n, float s4) {
- *d = (int16_t) (a + b);
+ int32_t i4;
- s1 = (const int16_t*) ((const uint8_t*) s1 + sstr1);
- s2 = (const int16_t*) ((const uint8_t*) s2 + sstr2);
- d = (int16_t*) ((uint8_t*) d + dstr);
+ i4 = (int32_t) (s4 * 0x10000);
+ for (; n > 0; n--) {
+ *d = (int16_t) (*d + (((int32_t)*s * i4) >> 16));
+
+ s = (const int16_t*) ((const uint8_t*) s + sstr);
+ d = (int16_t*) ((uint8_t*) d + dstr);
}
}
if (r->map_table[oc][ic] <= 0.0)
continue;
- oil_vectoradd_f32(
- (float*) dst + oc, o_skip,
+ vectoradd_f32(
(float*) dst + oc, o_skip,
(float*) src + ic, i_skip,
(int) n_frames,
- &one, &r->map_table[oc][ic]);
+ r->map_table[oc][ic]);
}
}
continue;
if (r->map_table[oc][ic] >= 1.0) {
- static const int16_t one = 1;
- oil_vectoradd_s16(
- (int16_t*) dst + oc, o_skip,
+ vectoradd_s16(
(int16_t*) dst + oc, o_skip,
(int16_t*) src + ic, i_skip,
- (int) n_frames,
- &one, &one);
+ (int) n_frames);
} else
vectoradd_s16_with_fraction(
- (int16_t*) dst + oc, o_skip,
(int16_t*) dst + oc, o_skip,
(int16_t*) src + ic, i_skip,
(int) n_frames,
- 1.0f, r->map_table[oc][ic]);
+ r->map_table[oc][ic]);
}
}
pa_assert(o_index * fz < pa_memblock_get_length(output->memblock));
- oil_memcpy((uint8_t*) dst + fz * o_index,
+ memcpy((uint8_t*) dst + fz * o_index,
(uint8_t*) src + fz * j, (int) fz);
}