1 /* SPDX-License-Identifier: BSD-3-Clause 2 * 3 * Copyright(c) 2021 Intel Corporation. All rights reserved. 4 */ 5 6 #ifndef __SOF_AUDIO_FORMAT_GENERIC_H__ 7 #define __SOF_AUDIO_FORMAT_GENERIC_H__ 8 9 #include <stdint.h> 10 11 /* Saturation inline functions */ 12 sat_int32(int64_t x)13static inline int32_t sat_int32(int64_t x) 14 { 15 if (x > INT32_MAX) 16 return INT32_MAX; 17 else if (x < INT32_MIN) 18 return INT32_MIN; 19 else 20 return (int32_t)x; 21 } 22 sat_int24(int32_t x)23static inline int32_t sat_int24(int32_t x) 24 { 25 if (x > INT24_MAXVALUE) 26 return INT24_MAXVALUE; 27 else if (x < INT24_MINVALUE) 28 return INT24_MINVALUE; 29 else 30 return x; 31 } 32 sat_int16(int32_t x)33static inline int16_t sat_int16(int32_t x) 34 { 35 if (x > INT16_MAX) 36 return INT16_MAX; 37 else if (x < INT16_MIN) 38 return INT16_MIN; 39 else 40 return (int16_t)x; 41 } 42 43 #endif /* __SOF_AUDIO_FORMAT_GENERIC_H__ */ 44