[pulseaudio-commits] r1548 - /branches/lennart/src/pulsecore/resampler.c
svnmailer-noreply at 0pointer.de
svnmailer-noreply at 0pointer.de
Thu Jul 26 12:30:52 PDT 2007
Author: lennart
Date: Thu Jul 26 21:30:51 2007
New Revision: 1548
URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1548&root=3Dpulseaudio&vi=
ew=3Drev
Log:
Fix channel remapping in resample; other modernizations
Modified:
branches/lennart/src/pulsecore/resampler.c
Modified: branches/lennart/src/pulsecore/resampler.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
resampler.c?rev=3D1548&root=3Dpulseaudio&r1=3D1547&r2=3D1548&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/resampler.c (original)
+++ branches/lennart/src/pulsecore/resampler.c Thu Jul 26 21:30:51 2007
@@ -25,7 +25,6 @@
#include <config.h>
#endif
=
-#include <assert.h>
#include <string.h>
=
#include <samplerate.h>
@@ -33,9 +32,9 @@
#include <liboil/liboil.h>
=
#include <pulse/xmalloc.h>
-
#include <pulsecore/sconv.h>
#include <pulsecore/log.h>
+#include <pulsecore/macro.h>
=
#include "resampler.h"
=
@@ -83,12 +82,12 @@
=
pa_resampler *r =3D NULL;
=
- assert(pool);
- assert(a);
- assert(b);
- assert(pa_sample_spec_valid(a));
- assert(pa_sample_spec_valid(b));
- assert(resample_method !=3D PA_RESAMPLER_INVALID);
+ pa_assert(pool);
+ pa_assert(a);
+ pa_assert(b);
+ pa_assert(pa_sample_spec_valid(a));
+ pa_assert(pa_sample_spec_valid(b));
+ pa_assert(resample_method !=3D PA_RESAMPLER_INVALID);
=
r =3D pa_xnew(pa_resampler, 1);
r->impl_data =3D NULL;
@@ -145,7 +144,7 @@
}
=
void pa_resampler_free(pa_resampler *r) {
- assert(r);
+ pa_assert(r);
=
if (r->impl_free)
r->impl_free(r);
@@ -154,8 +153,8 @@
}
=
void pa_resampler_set_input_rate(pa_resampler *r, uint32_t rate) {
- assert(r);
- assert(rate > 0);
+ pa_assert(r);
+ pa_assert(rate > 0);
=
if (r->i_ss.rate =3D=3D rate)
return;
@@ -167,8 +166,8 @@
}
=
void pa_resampler_set_output_rate(pa_resampler *r, uint32_t rate) {
- assert(r);
- assert(rate > 0);
+ pa_assert(r);
+ pa_assert(rate > 0);
=
if (r->o_ss.rate =3D=3D rate)
return;
@@ -180,19 +179,19 @@
}
=
void pa_resampler_run(pa_resampler *r, const pa_memchunk *in, pa_memchunk =
*out) {
- assert(r && in && out && r->impl_run);
+ pa_assert(r && in && out && r->impl_run);
=
r->impl_run(r, in, out);
}
=
size_t pa_resampler_request(pa_resampler *r, size_t out_length) {
- assert(r);
+ pa_assert(r);
=
return (((out_length / r->o_fz)*r->i_ss.rate)/r->o_ss.rate) * r->i_fz;
}
=
pa_resample_method_t pa_resampler_get_method(pa_resampler *r) {
- assert(r);
+ pa_assert(r);
return r->resample_method;
}
=
@@ -216,7 +215,7 @@
pa_resample_method_t pa_parse_resample_method(const char *string) {
pa_resample_method_t m;
=
- assert(string);
+ pa_assert(string);
=
for (m =3D 0; m < PA_RESAMPLER_MAX; m++)
if (!strcmp(string, resample_methods[m]))
@@ -231,8 +230,8 @@
static void libsamplerate_free(pa_resampler *r) {
struct impl_libsamplerate *u;
=
- assert(r);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(r->impl_data);
=
u =3D r->impl_data;
=
@@ -253,12 +252,13 @@
static void calc_map_table(pa_resampler *r) {
struct impl_libsamplerate *u;
unsigned oc;
- assert(r);
- assert(r->impl_data);
-
- u =3D r->impl_data;
-
- if (!(u->map_required =3D (!pa_channel_map_equal(&r->i_cm, &r->o_cm) |=
| r->i_ss.channels !=3D r->o_ss.channels)))
+ =
+ pa_assert(r);
+ pa_assert(r->impl_data);
+
+ u =3D r->impl_data;
+
+ if (!(u->map_required =3D (r->i_ss.channels !=3D r->o_ss.channels || !=
pa_channel_map_equal(&r->i_cm, &r->o_cm))))
return;
=
for (oc =3D 0; oc < r->o_ss.channels; oc++) {
@@ -290,11 +290,11 @@
unsigned n_samples;
void *src, *dst;
=
- assert(r);
- assert(input);
- assert(input->memblock);
-
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(input);
+ pa_assert(input->memblock);
+
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
/* Convert the incoming sample into floats and place them in buf1 */
@@ -328,16 +328,16 @@
=
static pa_memchunk *remap_channels(pa_resampler *r, pa_memchunk *input) {
struct impl_libsamplerate *u;
- unsigned n_samples, n_frames;
+ unsigned in_n_samples, out_n_samples, n_frames;
int i_skip, o_skip;
unsigned oc;
float *src, *dst;
=
- assert(r);
- assert(input);
- assert(input->memblock);
-
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(input);
+ pa_assert(input->memblock);
+
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
/* Remap channels and place the result int buf2 */
@@ -345,22 +345,23 @@
if (!u->map_required || !input->length)
return input;
=
- n_samples =3D input->length / sizeof(float);
- n_frames =3D n_samples / r->o_ss.channels;
-
- if (!u->buf2.memblock || u->buf2_samples < n_samples) {
+ in_n_samples =3D input->length / sizeof(float);
+ n_frames =3D in_n_samples / r->i_ss.channels;
+ out_n_samples =3D n_frames * r->o_ss.channels;
+
+ if (!u->buf2.memblock || u->buf2_samples < out_n_samples) {
if (u->buf2.memblock)
pa_memblock_unref(u->buf2.memblock);
=
- u->buf2_samples =3D n_samples;
- u->buf2.memblock =3D pa_memblock_new(r->mempool, u->buf2.length =
=3D sizeof(float) * n_samples);
+ u->buf2_samples =3D out_n_samples;
+ u->buf2.memblock =3D pa_memblock_new(r->mempool, u->buf2.length =
=3D sizeof(float) * out_n_samples);
u->buf2.index =3D 0;
}
=
src =3D (float*) ((uint8_t*) pa_memblock_acquire(input->memblock) + in=
put->index);
dst =3D (float*) pa_memblock_acquire(u->buf2.memblock);
=
- memset(dst, 0, n_samples * sizeof(float));
+ memset(dst, 0, u->buf2.length);
=
o_skip =3D sizeof(float) * r->o_ss.channels;
i_skip =3D sizeof(float) * r->i_ss.channels;
@@ -381,7 +382,7 @@
pa_memblock_release(input->memblock);
pa_memblock_release(u->buf2.memblock);
=
- u->buf2.length =3D n_frames * sizeof(float) * r->o_ss.channels;
+ u->buf2.length =3D out_n_samples * sizeof(float);
=
return &u->buf2;
}
@@ -393,9 +394,9 @@
unsigned out_n_frames, out_n_samples;
int ret;
=
- assert(r);
- assert(input);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(input);
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
/* Resample the data and place the result in buf3 */
@@ -428,8 +429,8 @@
data.end_of_input =3D 0;
=
ret =3D src_process(u->src_state, &data);
- assert(ret =3D=3D 0);
- assert((unsigned) data.input_frames_used =3D=3D in_n_frames);
+ pa_assert(ret =3D=3D 0);
+ pa_assert((unsigned) data.input_frames_used =3D=3D in_n_frames);
=
pa_memblock_release(input->memblock);
pa_memblock_release(u->buf3.memblock);
@@ -444,9 +445,9 @@
unsigned n_samples, n_frames;
void *src, *dst;
=
- assert(r);
- assert(input);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(input);
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
/* Convert the data into the correct sample type and place the result =
in buf4 */
@@ -481,13 +482,13 @@
struct impl_libsamplerate *u;
pa_memchunk *buf;
=
- assert(r);
- assert(in);
- assert(out);
- assert(in->length);
- assert(in->memblock);
- assert(in->length % r->i_fz =3D=3D 0);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(in);
+ pa_assert(out);
+ pa_assert(in->length);
+ pa_assert(in->memblock);
+ pa_assert(in->length % r->i_fz =3D=3D 0);
+ pa_assert(r->impl_data);
=
u =3D r->impl_data;
=
@@ -511,36 +512,36 @@
static void libsamplerate_update_input_rate(pa_resampler *r, uint32_t rate=
) {
struct impl_libsamplerate *u;
=
- assert(r);
- assert(rate > 0);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(rate > 0);
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
if (!u->src_state) {
int err;
u->src_state =3D src_new(r->resample_method, r->o_ss.channels, &er=
r);
- assert(u->src_state);
+ pa_assert(u->src_state);
} else {
int ret =3D src_set_ratio(u->src_state, (double) r->o_ss.rate / ra=
te);
- assert(ret =3D=3D 0);
+ pa_assert(ret =3D=3D 0);
}
}
=
static void libsamplerate_update_output_rate(pa_resampler *r, uint32_t rat=
e) {
struct impl_libsamplerate *u;
=
- assert(r);
- assert(rate > 0);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(rate > 0);
+ pa_assert(r->impl_data);
u =3D r->impl_data;
=
if (!u->src_state) {
int err;
u->src_state =3D src_new(r->resample_method, r->o_ss.channels, &er=
r);
- assert(u->src_state);
+ pa_assert(u->src_state);
} else {
int ret =3D src_set_ratio(u->src_state, (double) rate / r->i_ss.ra=
te);
- assert(ret =3D=3D 0);
+ pa_assert(ret =3D=3D 0);
}
}
=
@@ -592,15 +593,15 @@
unsigned n_frames;
struct impl_trivial *u;
=
- assert(r);
- assert(in);
- assert(out);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(in);
+ pa_assert(out);
+ pa_assert(r->impl_data);
=
u =3D r->impl_data;
=
fz =3D r->i_fz;
- assert(fz =3D=3D r->o_fz);
+ pa_assert(fz =3D=3D r->o_fz);
=
n_frames =3D in->length/fz;
=
@@ -635,7 +636,7 @@
if (j >=3D n_frames)
break;
=
- assert(o_index*fz < pa_memblock_get_length(out->memblock));
+ pa_assert(o_index*fz < pa_memblock_get_length(out->memblock));
=
memcpy((uint8_t*) dst + fz*o_index,
(uint8_t*) src + fz*j, fz);
@@ -653,13 +654,13 @@
/* Normalize counters */
while (u->i_counter >=3D r->i_ss.rate) {
u->i_counter -=3D r->i_ss.rate;
- assert(u->o_counter >=3D r->o_ss.rate);
+ pa_assert(u->o_counter >=3D r->o_ss.rate);
u->o_counter -=3D r->o_ss.rate;
}
}
=
static void trivial_free(pa_resampler *r) {
- assert(r);
+ pa_assert(r);
=
pa_xfree(r->impl_data);
}
@@ -667,9 +668,9 @@
static void trivial_update_rate(pa_resampler *r, uint32_t rate) {
struct impl_trivial *u;
=
- assert(r);
- assert(rate > 0);
- assert(r->impl_data);
+ pa_assert(r);
+ pa_assert(rate > 0);
+ pa_assert(r->impl_data);
=
u =3D r->impl_data;
u->i_counter =3D 0;
@@ -679,9 +680,9 @@
static int trivial_init(pa_resampler*r) {
struct impl_trivial *u;
=
- assert(r);
- assert(r->i_ss.format =3D=3D r->o_ss.format);
- assert(r->i_ss.channels =3D=3D r->o_ss.channels);
+ pa_assert(r);
+ pa_assert(r->i_ss.format =3D=3D r->o_ss.format);
+ pa_assert(r->i_ss.channels =3D=3D r->o_ss.channels);
=
r->impl_data =3D u =3D pa_xnew(struct impl_trivial, 1);
u->o_counter =3D u->i_counter =3D 0;
More information about the pulseaudio-commits
mailing list