mirror of
https://github.com/google/liblc3.git
synced 2026-06-02 18:07:02 +00:00
Add intrinsics saturation feature
This commit is contained in:
@@ -29,11 +29,16 @@
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __ARM_ARCH
|
||||
#include <arm_acle.h>
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* Macros
|
||||
* MIN/MAX Minimum and maximum between 2 values
|
||||
* CLIP Clip a value between low and high limits
|
||||
* SATXX Saturation on 'xx' bits
|
||||
* ABS Return the absolute value
|
||||
*/
|
||||
|
||||
@@ -41,9 +46,18 @@
|
||||
#define LC3_MAX(a, b) ( (a) > (b) ? (a) : (b) )
|
||||
#define LC3_CLIP(v, min, max) LC3_MIN(LC3_MAX(v, min), max)
|
||||
|
||||
#ifdef __ARM_FEATURE_SAT
|
||||
#define LC3_SAT16(v) __ssat(v, 16)
|
||||
#define LC3_SAT24(v) __ssat(v, 24)
|
||||
#else
|
||||
#define LC3_SAT16(v) LC3_CLIP(v, -(1 << 15), (1 << 15) - 1)
|
||||
#define LC3_SAT24(v) LC3_CLIP(v, -(1 << 23), (1 << 23) - 1)
|
||||
#endif
|
||||
|
||||
#define LC3_ABS(n) ( (n) < 0 ? -(n) : (n) )
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Convert `dt` in us and `sr` in KHz
|
||||
*/
|
||||
|
||||
@@ -366,8 +366,8 @@ static void store_s16(
|
||||
int ns = LC3_NS(dt, sr);
|
||||
|
||||
for ( ; ns > 0; ns--, xs++, pcm += stride) {
|
||||
int s = *xs >= 0 ? (int)(*xs + 0.5f) : (int)(*xs - 0.5f);
|
||||
*pcm = LC3_CLIP(s, INT16_MIN, INT16_MAX);
|
||||
int32_t s = *xs >= 0 ? (int)(*xs + 0.5f) : (int)(*xs - 0.5f);
|
||||
*pcm = LC3_SAT16(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -380,8 +380,6 @@ static void store_s24(
|
||||
struct lc3_decoder *decoder, void *_pcm, int stride)
|
||||
{
|
||||
int32_t *pcm = _pcm;
|
||||
const int32_t int24_max = (1 << 23) - 1;
|
||||
const int32_t int24_min = -(1 << 23);
|
||||
|
||||
enum lc3_dt dt = decoder->dt;
|
||||
enum lc3_srate sr = decoder->sr_pcm;
|
||||
@@ -392,7 +390,7 @@ static void store_s24(
|
||||
for ( ; ns > 0; ns--, xs++, pcm += stride) {
|
||||
int32_t s = *xs >= 0 ? (int32_t)(ldexpf(*xs, 8) + 0.5f)
|
||||
: (int32_t)(ldexpf(*xs, 8) - 0.5f);
|
||||
*pcm = LC3_CLIP(s, int24_min, int24_max);
|
||||
*pcm = LC3_SAT24(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user