Merge pull request #13080 from kencooke/audio-asan-warnings

Fix asan warnings
This commit is contained in:
Ken Cooke 2018-05-03 10:32:59 -07:00 committed by GitHub
commit 028ea11405
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 41 deletions

View file

@ -10,9 +10,9 @@
// Inline functions to implement audio dynamics processing
//
#include <stddef.h>
#include <math.h>
#include <stdint.h>
#include <stddef.h>
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
@ -21,7 +21,15 @@
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
#ifdef _MSC_VER
#if defined(_MSC_VER)
#define FORCEINLINE __forceinline
#elif defined(__GNUC__)
#define FORCEINLINE inline __attribute__((always_inline))
#else
#define FORCEINLINE inline
#endif
#if defined(_MSC_VER)
#include <intrin.h>
#define MUL64(a,b) __emul((a), (b))
#else
@ -42,14 +50,14 @@
#include <xmmintrin.h>
// convert float to int using round-to-nearest
static inline int32_t floatToInt(float x) {
FORCEINLINE static int32_t floatToInt(float x) {
return _mm_cvt_ss2si(_mm_load_ss(&x));
}
#else
// convert float to int using round-to-nearest
static inline int32_t floatToInt(float x) {
FORCEINLINE static int32_t floatToInt(float x) {
x += (x < 0.0f ? -0.5f : 0.5f); // round
return (int32_t)x;
}
@ -60,12 +68,12 @@ static const double FIXQ31 = 2147483648.0; // convert float to Q31
static const double DB_TO_LOG2 = 0.16609640474436813; // convert dB to log2
// convert dB to amplitude
static inline double dBToGain(double dB) {
FORCEINLINE static double dBToGain(double dB) {
return pow(10.0, dB / 20.0);
}
// convert milliseconds to first-order time constant
static inline int32_t msToTc(double ms, double sampleRate) {
FORCEINLINE static int32_t msToTc(double ms, double sampleRate) {
double tc = exp(-1000.0 / (ms * sampleRate));
return (int32_t)(FIXQ31 * tc); // Q31
}
@ -144,16 +152,16 @@ static const int IEEE754_EXPN_BIAS = 127;
// x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff
// x > 2^LOG2_HEADROOM undefined
//
static inline int32_t peaklog2(float* input) {
FORCEINLINE static int32_t peaklog2(float* input) {
// float as integer bits
int32_t u = *(int32_t*)input;
uint32_t u = *(uint32_t*)input;
// absolute value
int32_t peak = u & IEEE754_FABS_MASK;
uint32_t peak = u & IEEE754_FABS_MASK;
// split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate
@ -180,19 +188,19 @@ static inline int32_t peaklog2(float* input) {
// x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff
// x > 2^LOG2_HEADROOM undefined
//
static inline int32_t peaklog2(float* input0, float* input1) {
FORCEINLINE static int32_t peaklog2(float* input0, float* input1) {
// float as integer bits
int32_t u0 = *(int32_t*)input0;
int32_t u1 = *(int32_t*)input1;
uint32_t u0 = *(uint32_t*)input0;
uint32_t u1 = *(uint32_t*)input1;
// max absolute value
u0 &= IEEE754_FABS_MASK;
u1 &= IEEE754_FABS_MASK;
int32_t peak = MAX(u0, u1);
uint32_t peak = MAX(u0, u1);
// split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate
@ -219,23 +227,23 @@ static inline int32_t peaklog2(float* input0, float* input1) {
// x < 2^(31-LOG2_HEADROOM) returns 0x7fffffff
// x > 2^LOG2_HEADROOM undefined
//
static inline int32_t peaklog2(float* input0, float* input1, float* input2, float* input3) {
FORCEINLINE static int32_t peaklog2(float* input0, float* input1, float* input2, float* input3) {
// float as integer bits
int32_t u0 = *(int32_t*)input0;
int32_t u1 = *(int32_t*)input1;
int32_t u2 = *(int32_t*)input2;
int32_t u3 = *(int32_t*)input3;
uint32_t u0 = *(uint32_t*)input0;
uint32_t u1 = *(uint32_t*)input1;
uint32_t u2 = *(uint32_t*)input2;
uint32_t u3 = *(uint32_t*)input3;
// max absolute value
u0 &= IEEE754_FABS_MASK;
u1 &= IEEE754_FABS_MASK;
u2 &= IEEE754_FABS_MASK;
u3 &= IEEE754_FABS_MASK;
int32_t peak = MAX(MAX(u0, u1), MAX(u2, u3));
uint32_t peak = MAX(MAX(u0, u1), MAX(u2, u3));
// split into e and x - 1.0
int32_t e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int e = IEEE754_EXPN_BIAS - (peak >> IEEE754_MANT_BITS) + LOG2_HEADROOM;
int32_t x = (peak << IEEE754_EXPN_BITS) & 0x7fffffff;
// saturate
@ -261,7 +269,7 @@ static inline int32_t peaklog2(float* input0, float* input1, float* input2, floa
// Count Leading Zeros
// Emulates the CLZ (ARM) and LZCNT (x86) instruction
//
static inline int CLZ(uint32_t u) {
FORCEINLINE static int CLZ(uint32_t u) {
if (u == 0) {
return 32;
@ -294,7 +302,7 @@ static inline int CLZ(uint32_t u) {
// Compute -log2(x) for x=[0,1] in Q31, result in Q26
// x <= 0 returns 0x7fffffff
//
static inline int32_t fixlog2(int32_t x) {
FORCEINLINE static int32_t fixlog2(int32_t x) {
if (x <= 0) {
return 0x7fffffff;
@ -303,8 +311,7 @@ static inline int32_t fixlog2(int32_t x) {
// split into e and x - 1.0
uint32_t u = (uint32_t)x;
int e = CLZ(u);
u <<= e; // normalize to [0x80000000, 0xffffffff]
x = u & 0x7fffffff; // x - 1.0
x = (u << e) & 0x7fffffff;
int k = x >> (31 - LOG2_TABBITS);
@ -324,7 +331,7 @@ static inline int32_t fixlog2(int32_t x) {
// Compute exp2(-x) for x=[0,32] in Q26, result in Q31
// x <= 0 returns 0x7fffffff
//
static inline int32_t fixexp2(int32_t x) {
FORCEINLINE static int32_t fixexp2(int32_t x) {
if (x <= 0) {
return 0x7fffffff;
@ -350,12 +357,12 @@ static inline int32_t fixexp2(int32_t x) {
}
// fast TPDF dither in [-1.0f, 1.0f]
static inline float dither() {
FORCEINLINE static float dither() {
static uint32_t rz = 0;
rz = rz * 69069 + 1;
int32_t r0 = rz & 0xffff;
int32_t r1 = rz >> 16;
return (int32_t)(r0 - r1) * (1/65536.0f);
return (r0 - r1) * (1/65536.0f);
}
//

View file

@ -13,18 +13,11 @@
#include "AudioReverb.h"
#ifdef _MSC_VER
#include <intrin.h>
inline static int MULHI(int a, int b) {
long long c = __emul(a, b);
return ((int*)&c)[1];
}
#define MULHI(a,b) ((int32_t)(__emul(a, b) >> 32))
#else
#define MULHI(a,b) (int)(((long long)(a) * (b)) >> 32)
#endif // _MSC_VER
#define MULHI(a,b) ((int32_t)(((int64_t)(a) * (int64_t)(b)) >> 32))
#endif
#ifndef MAX
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
@ -1954,7 +1947,7 @@ static inline float dither() {
rz = rz * 69069 + 1;
int32_t r0 = rz & 0xffff;
int32_t r1 = rz >> 16;
return (int32_t)(r0 - r1) * (1/65536.0f);
return (r0 - r1) * (1/65536.0f);
}
// convert float to int16_t with dither, interleave stereo

View file

@ -1200,7 +1200,7 @@ static inline float dither() {
rz = rz * 69069 + 1;
int32_t r0 = rz & 0xffff;
int32_t r1 = rz >> 16;
return (int32_t)(r0 - r1) * (1/65536.0f);
return (r0 - r1) * (1/65536.0f);
}
// convert float to int16_t with dither, interleave stereo