Clamp float values when converting to int32
This commit is contained in:
parent
49fd1f93e5
commit
7840b686f2
|
@ -190,6 +190,13 @@ __attribute__((weak)) void audio_int8_to_float32(int8_t* restrict data, size_t d
|
|||
|
||||
__attribute__((weak)) void audio_float32_to_int32(float* restrict data, size_t data_len, int32_t* restrict buffer, int bitDepth){
|
||||
for (int i = 0; i < data_len; ++i){
|
||||
buffer[i] = (int32_t)(data[i] * BITS_TO_DIV(bitDepth));
|
||||
float f = data[i];
|
||||
if (f < -1.0) {
|
||||
f = -1.0;
|
||||
}
|
||||
if (f > 1.0) {
|
||||
f = 1.0;
|
||||
}
|
||||
buffer[i] = (int32_t)(f * BITS_TO_DIV(bitDepth));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue