pulseaudio/pulseaudio-0.9.7-type-punning.diff

65 lines
1.6 KiB
Diff

--- src/tests/resampler-test.c-dist 2007-10-31 11:59:07.000000000 +0100
+++ src/tests/resampler-test.c 2007-10-31 12:02:38.000000000 +0100
@@ -37,9 +37,13 @@
#include <liboil/liboil.h>
static float swap_float(float a) {
- uint32_t *b = (uint32_t*) &a;
- *b = PA_UINT32_SWAP(*b);
- return a;
+ union {
+ uint32_t i;
+ float f;
+ } b;
+ b.f = a;
+ b.i = PA_UINT32_SWAP(b.i);
+ return b.f;
}
static void dump_block(const pa_sample_spec *ss, const pa_memchunk *chunk) {
--- src/pulsecore/sconv-s16le.c-dist 2007-10-31 11:58:56.000000000 +0100
+++ src/pulsecore/sconv-s16le.c 2007-10-31 12:02:59.000000000 +0100
@@ -95,16 +95,21 @@ void pa_sconv_s16le_from_float32ne(unsig
#endif
}
+union float32 {
+ uint32_t i;
+ float f;
+};
+
void pa_sconv_s16le_to_float32re(unsigned n, const int16_t *a, float *b) {
pa_assert(a);
pa_assert(b);
for (; n > 0; n--) {
int16_t s = *(a++);
- float k = ((float) INT16_FROM(s))/0x7FFF;
- uint32_t *j = (uint32_t*) &k;
- *j = PA_UINT32_SWAP(*j);
- *(b++) = k;
+ union float32 k;
+ k.f = ((float) INT16_FROM(s))/0x7FFF;
+ k.i = PA_UINT32_SWAP(k.i);
+ *(b++) = k.f;
}
}
@@ -114,11 +119,11 @@ void pa_sconv_s16le_from_float32re(unsig
for (; n > 0; n--) {
int16_t s;
- float v = *(a++);
- uint32_t *j = (uint32_t*) &v;
- *j = PA_UINT32_SWAP(*j);
- v = CLAMP(v, -1, 1);
- s = (int16_t) (v * 0x7FFF);
+ union float32 v;
+ v.f = *(a++);
+ v.i = PA_UINT32_SWAP(v.i);
+ v.f = CLAMP(v.f, -1, 1);
+ s = (int16_t) (v.f * 0x7FFF);
*(b++) = INT16_TO(s);
}
}