mirror of
https://gitee.com/openharmony/third_party_libsnd
synced 2024-11-26 19:40:24 +00:00
tests/ : Fix undefined behaviour warnings.
This commit is contained in:
parent
149f42892b
commit
eea13650b9
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright (C) 2002-2011 Erik de Castro Lopo <erikd@mega-nerd.com>
|
** Copyright (C) 2002-2014 Erik de Castro Lopo <erikd@mega-nerd.com>
|
||||||
**
|
**
|
||||||
** This program is free software; you can redistribute it and/or modify
|
** This program is free software; you can redistribute it and/or modify
|
||||||
** it under the terms of the GNU General Public License as published by
|
** it under the terms of the GNU General Public License as published by
|
||||||
@ -62,7 +62,7 @@ dwvw_test (const char *filename, int format, int bit_width)
|
|||||||
srand (123456) ;
|
srand (123456) ;
|
||||||
|
|
||||||
/* Only want to grab the top bit_width bits. */
|
/* Only want to grab the top bit_width bits. */
|
||||||
bit_mask = (-1 << (32 - bit_width)) ;
|
bit_mask = arith_shift_left (-1, 32 - bit_width) ;
|
||||||
|
|
||||||
print_test_name ("dwvw_test", filename) ;
|
print_test_name ("dwvw_test", filename) ;
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ dwvw_test (const char *filename, int format, int bit_width)
|
|||||||
} ;
|
} ;
|
||||||
|
|
||||||
for ( ; k < BUFFER_SIZE ; k++)
|
for ( ; k < BUFFER_SIZE ; k++)
|
||||||
write_buf [k] = bit_mask & ((rand () << 11) ^ (rand () >> 11)) ;
|
write_buf [k] = bit_mask & (arith_shift_left (rand (), 11) ^ (rand () >> 11)) ;
|
||||||
|
|
||||||
sf_write_int (file, write_buf, BUFFER_SIZE) ;
|
sf_write_int (file, write_buf, BUFFER_SIZE) ;
|
||||||
sf_close (file) ;
|
sf_close (file) ;
|
||||||
|
@ -85,8 +85,8 @@ main (int argc, char *argv [])
|
|||||||
float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
float_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
||||||
float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
float_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
||||||
|
|
||||||
float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
|
float_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
|
||||||
float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
|
float_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
|
||||||
float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
float_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
||||||
|
|
||||||
/* PAF files do not use the same encoding method for 24 bit PCM data as other file
|
/* PAF files do not use the same encoding method for 24 bit PCM data as other file
|
||||||
@ -144,8 +144,8 @@ main (int argc, char *argv [])
|
|||||||
double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
double_scaled_test ("ms_adpcm.wav" , allow_exit, SF_FALSE, SF_FORMAT_WAV | SF_FORMAT_MS_ADPCM, -40.0) ;
|
||||||
double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
double_scaled_test ("gsm610.raw" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_GSM610, -33.0) ;
|
||||||
|
|
||||||
double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -34.0) ;
|
double_scaled_test ("g721_32.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G721_32, -32.3) ;
|
||||||
double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -34.0) ;
|
double_scaled_test ("g723_24.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_24, -32.3) ;
|
||||||
double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
double_scaled_test ("g723_40.au", allow_exit, SF_FALSE, SF_FORMAT_AU | SF_FORMAT_G723_40, -40.0) ;
|
||||||
|
|
||||||
/* 24 bit PCM PAF files tested here. */
|
/* 24 bit PCM PAF files tested here. */
|
||||||
@ -159,7 +159,7 @@ main (int argc, char *argv [])
|
|||||||
double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
|
double_scaled_test ("adpcm.vox" , allow_exit, SF_FALSE, SF_FORMAT_RAW | SF_FORMAT_VOX_ADPCM, -40.0) ;
|
||||||
|
|
||||||
double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
|
double_scaled_test ("dpcm_16.xi", allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_16, -90.0) ;
|
||||||
double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -42.0) ;
|
double_scaled_test ("dpcm_8.xi" , allow_exit, SF_FALSE, SF_FORMAT_XI | SF_FORMAT_DPCM_8 , -41.0) ;
|
||||||
|
|
||||||
double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
|
double_scaled_test ("pcm_s8.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_S8, -90.0) ;
|
||||||
double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
|
double_scaled_test ("pcm_16.sds", allow_exit, SF_FALSE, SF_FORMAT_SDS | SF_FORMAT_PCM_16, -140.0) ;
|
||||||
@ -203,7 +203,7 @@ float_scaled_test (const char *filename, int allow_exit, int replace_float, int
|
|||||||
|
|
||||||
print_test_name ("float_scaled_test", filename) ;
|
print_test_name ("float_scaled_test", filename) ;
|
||||||
|
|
||||||
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 1.0) ;
|
gen_windowed_sine_float (float_data, DFT_DATA_LENGTH, 0.9999) ;
|
||||||
|
|
||||||
sfinfo.samplerate = SAMPLE_RATE ;
|
sfinfo.samplerate = SAMPLE_RATE ;
|
||||||
sfinfo.frames = DFT_DATA_LENGTH ;
|
sfinfo.frames = DFT_DATA_LENGTH ;
|
||||||
@ -255,7 +255,7 @@ double_scaled_test (const char *filename, int allow_exit, int replace_float, int
|
|||||||
|
|
||||||
print_test_name ("double_scaled_test", filename) ;
|
print_test_name ("double_scaled_test", filename) ;
|
||||||
|
|
||||||
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.95) ;
|
gen_windowed_sine_double (double_data, DFT_DATA_LENGTH, 0.9999) ;
|
||||||
|
|
||||||
sfinfo.samplerate = SAMPLE_RATE ;
|
sfinfo.samplerate = SAMPLE_RATE ;
|
||||||
sfinfo.frames = DFT_DATA_LENGTH ;
|
sfinfo.frames = DFT_DATA_LENGTH ;
|
||||||
@ -311,7 +311,7 @@ static void
|
|||||||
|
|
||||||
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
|
print_test_name ("[+ (get "float_name") +]_[+ (get "int_name") +]_[+ (get "end_name") +]_test", filename) ;
|
||||||
|
|
||||||
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.98) ;
|
gen_windowed_sine_[+ (get "float_name") +] ([+ (get "float_name") +]_data, ARRAY_LEN ([+ (get "float_name") +]_data), 0.9999) ;
|
||||||
|
|
||||||
sfinfo.samplerate = SAMPLE_RATE ;
|
sfinfo.samplerate = SAMPLE_RATE ;
|
||||||
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
|
sfinfo.frames = ARRAY_LEN ([+ (get "int_name") +]_data) ;
|
||||||
|
@ -3,8 +3,8 @@ autogen definitions pcm_test.tpl;
|
|||||||
data_type = {
|
data_type = {
|
||||||
name = "bits_8" ;
|
name = "bits_8" ;
|
||||||
item_count = 127 ;
|
item_count = 127 ;
|
||||||
short_func = "((k * ((k % 2) ? 1 : -1)) << 8)" ;
|
short_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 8)" ;
|
||||||
int_func = "((k * ((k % 2) ? 1 : -1)) << 24)" ;
|
int_func = "arith_shift_left (k * ((k % 2) ? 1 : -1), 24)" ;
|
||||||
float_func = "(k * ((k % 2) ? 1 : -1))" ;
|
float_func = "(k * ((k % 2) ? 1 : -1))" ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
@ -12,7 +12,7 @@ data_type = {
|
|||||||
name = "bits_16" ;
|
name = "bits_16" ;
|
||||||
item_count = 1024 ;
|
item_count = 1024 ;
|
||||||
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||||
int_func = "((k * ((k % 2) ? 3 : -3)) << 16)" ;
|
int_func = "arith_shift_left (k * ((k % 2) ? 3 : -3), 16)" ;
|
||||||
float_func = "(k * ((k % 2) ? 3 : -3))" ;
|
float_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ data_type = {
|
|||||||
name = "bits_24" ;
|
name = "bits_24" ;
|
||||||
item_count = 1024 ;
|
item_count = 1024 ;
|
||||||
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
short_func = "(k * ((k % 2) ? 3 : -3))" ;
|
||||||
int_func = "((k * ((k % 2) ? 3333 : -3333)) << 8)" ;
|
int_func = "arith_shift_left (k * ((k % 2) ? 3333 : -3333), 8)" ;
|
||||||
float_func = "(k * ((k % 2) ? 3333 : -3333))" ;
|
float_func = "(k * ((k % 2) ? 3333 : -3333))" ;
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
|
@ -79,6 +79,11 @@ exit_if_true (int test, const char *format, ...)
|
|||||||
} ;
|
} ;
|
||||||
} /* exit_if_true */
|
} /* exit_if_true */
|
||||||
|
|
||||||
|
static inline int32_t
|
||||||
|
arith_shift_left (int32_t x, int shift)
|
||||||
|
{ return (int32_t) (((uint32_t) x) << shift) ;
|
||||||
|
} /* arith_shift_left */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Functions for saving two vectors of data in an ascii text file which
|
** Functions for saving two vectors of data in an ascii text file which
|
||||||
** can then be loaded into GNU octave for comparison.
|
** can then be loaded into GNU octave for comparison.
|
||||||
|
Loading…
Reference in New Issue
Block a user