Move code from pointless .h file to .c file. Remove warning suppression pragmas. Fix causes of warnings. See also bug #326.
Unified · Split
| @@ -50,7 +50,7 @@ example3_SOURCES = example3.c · 49 unmodified lines | ||
| 50 | 50 | example4_SOURCES = example4.c |
| 51 | 51 | example5_SOURCES = example5.c |
| 52 | 52 | example6_SOURCES = example6.c |
| 53 | −sox_sample_test_SOURCES = sox_sample_test.c sox_sample_test.h | |
| 53 | +sox_sample_test_SOURCES = sox_sample_test.c | |
| 54 | 54 | |
| 55 | 55 | |
| 56 | 56 | |
| @@ -15,4 +15,176 @@ · 14 unmodified lines | ||
| 15 | 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | −#include "sox_sample_test.h" | |
| 18 | +#ifdef NDEBUG /* Enable assert always. */ | |
| 19 | +#undef NDEBUG /* Must undef above assert.h or other that might include it. */ | |
| 20 | +#endif | |
| 21 | +#include <assert.h> | |
| 22 | +#include <math.h> | |
| 23 | +#include "sox.h" | |
| 24 | + | |
| 25 | +#define TEST_UINT(bits) \ | |
| 26 | + uint##bits = 0; \ | |
| 27 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 28 | + assert(sample == SOX_SAMPLE_MIN); \ | |
| 29 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 30 | + assert(uint##bits == 0 && clips == 0); \ | |
| 31 | + \ | |
| 32 | + uint##bits = 1; \ | |
| 33 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 34 | + assert(sample > SOX_SAMPLE_MIN && sample < 0); \ | |
| 35 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 36 | + assert(uint##bits == 1 && clips == 0); \ | |
| 37 | + \ | |
| 38 | + uint##bits = SOX_INT_MAX(bits); \ | |
| 39 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 40 | + assert(sample * SOX_INT_MAX(bits) == SOX_UNSIGNED_TO_SAMPLE(bits,1)); \ | |
| 41 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 42 | + assert(uint##bits == SOX_INT_MAX(bits) && clips == 0); \ | |
| 43 | + \ | |
| 44 | + sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \ | |
| 45 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 46 | + assert(uint##bits == 1 && clips == 0); \ | |
| 47 | + \ | |
| 48 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \ | |
| 49 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 50 | + assert(uint##bits == 0 && clips == 0); \ | |
| 51 | + \ | |
| 52 | + uint##bits = (0^SOX_INT_MIN(bits)); \ | |
| 53 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 54 | + assert(sample == 0); \ | |
| 55 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 56 | + assert(uint##bits == (0^SOX_INT_MIN(bits)) && clips == 0); \ | |
| 57 | + \ | |
| 58 | + uint##bits = ((0^SOX_INT_MIN(bits))+1); \ | |
| 59 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 60 | + assert(sample > 0 && sample < SOX_SAMPLE_MAX); \ | |
| 61 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 62 | + assert(uint##bits == ((0^SOX_INT_MIN(bits))+1) && clips == 0); \ | |
| 63 | + \ | |
| 64 | + uint##bits = SOX_UINT_MAX(bits); \ | |
| 65 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 66 | + assert(sample == SOX_INT_MAX(bits) * SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))); \ | |
| 67 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 68 | + assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \ | |
| 69 | + \ | |
| 70 | + sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \ | |
| 71 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 72 | + assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \ | |
| 73 | + \ | |
| 74 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \ | |
| 75 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 76 | + assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \ | |
| 77 | + \ | |
| 78 | + sample = SOX_SAMPLE_MAX; \ | |
| 79 | + uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 80 | + assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \ | |
| 81 | + | |
| 82 | +#define TEST_SINT(bits) \ | |
| 83 | + int##bits = SOX_INT_MIN(bits); \ | |
| 84 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 85 | + assert(sample == SOX_SAMPLE_MIN); \ | |
| 86 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 87 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 88 | + \ | |
| 89 | + int##bits = SOX_INT_MIN(bits)+1; \ | |
| 90 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 91 | + assert(sample > SOX_SAMPLE_MIN && sample < 0); \ | |
| 92 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 93 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 94 | + \ | |
| 95 | + int##bits = SOX_UINT_MAX(bits) /* i.e. -1 */; \ | |
| 96 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 97 | + assert(sample * SOX_INT_MAX(bits) == SOX_SIGNED_TO_SAMPLE(bits,SOX_INT_MIN(bits)+1)); \ | |
| 98 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 99 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 100 | + \ | |
| 101 | + int##bits = SOX_INT_MIN(bits)+1; \ | |
| 102 | + sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \ | |
| 103 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 104 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 105 | + \ | |
| 106 | + int##bits = SOX_INT_MIN(bits); \ | |
| 107 | + sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \ | |
| 108 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 109 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 110 | + \ | |
| 111 | + int##bits = 0; \ | |
| 112 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 113 | + assert(sample == 0); \ | |
| 114 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 115 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 116 | + \ | |
| 117 | + int##bits = 1; \ | |
| 118 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 119 | + assert(sample > 0 && sample < SOX_SAMPLE_MAX); \ | |
| 120 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 121 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 122 | + \ | |
| 123 | + int##bits = SOX_INT_MAX(bits); \ | |
| 124 | + sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 125 | + assert(sample == SOX_INT_MAX(bits) * SOX_SIGNED_TO_SAMPLE(bits,1)); \ | |
| 126 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 127 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 128 | + \ | |
| 129 | + sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \ | |
| 130 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 131 | + assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 132 | + \ | |
| 133 | + sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \ | |
| 134 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 135 | + assert(int##bits##_2 == int##bits && --clips == 0); \ | |
| 136 | + \ | |
| 137 | + sample = SOX_SAMPLE_MAX; \ | |
| 138 | + int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 139 | + assert(int##bits##_2 == int##bits && --clips == 0); | |
| 140 | + | |
| 141 | +int main(void) | |
| 142 | +{ | |
| 143 | + sox_int8_t int8; | |
| 144 | + sox_int16_t int16; | |
| 145 | + sox_int24_t int24; | |
| 146 | + | |
| 147 | + sox_uint8_t uint8; | |
| 148 | + sox_uint16_t uint16; | |
| 149 | + sox_uint24_t uint24; | |
| 150 | + | |
| 151 | + sox_int8_t int8_2; | |
| 152 | + sox_int16_t int16_2; | |
| 153 | + sox_int24_t int24_2; | |
| 154 | + | |
| 155 | + sox_sample_t sample; | |
| 156 | + size_t clips = 0; | |
| 157 | + | |
| 158 | + double d; | |
| 159 | + SOX_SAMPLE_LOCALS; | |
| 160 | + | |
| 161 | + TEST_UINT(8) | |
| 162 | + TEST_UINT(16) | |
| 163 | + TEST_UINT(24) | |
| 164 | + | |
| 165 | + TEST_SINT(8) | |
| 166 | + TEST_SINT(16) | |
| 167 | + TEST_SINT(24) | |
| 168 | + | |
| 169 | + d = -1.000000001; | |
| 170 | + sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 171 | + assert(sample == SOX_SAMPLE_MIN && --clips == 0); | |
| 172 | + | |
| 173 | + d = -1; | |
| 174 | + sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 175 | + assert(sample == SOX_SAMPLE_MIN && clips == 0); | |
| 176 | + d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips); | |
| 177 | + assert(d == -1 && clips == 0); | |
| 178 | + | |
| 179 | + d = 1; | |
| 180 | + sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 181 | + assert(sample == SOX_SAMPLE_MAX && clips == 0); | |
| 182 | + d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips); | |
| 183 | + assert(fabs(d - 1) < 1e-9 && clips == 0); | |
| 184 | + | |
| 185 | + d = 1.0000000001; | |
| 186 | + sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 187 | + assert(sample == SOX_SAMPLE_MAX && --clips == 0); | |
| 188 | + | |
| 189 | + return 0; | |
| 190 | +} | |
| @@ -1,203 +0,0 @@ | ||
| 1 | −/* libSoX test code copyright (c) 2006 robs@users.sourceforge.net | |
| 2 | − * | |
| 3 | − * This program is free software; you can redistribute it and/or modify it | |
| 4 | − * under the terms of the GNU General Public License as published by the | |
| 5 | − * Free Software Foundation; either version 2 of the License, or (at your | |
| 6 | − * option) any later version. | |
| 7 | − * | |
| 8 | − * This program is distributed in the hope that it will be useful, but | |
| 9 | − * WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 10 | − * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General | |
| 11 | − * Public License for more details. | |
| 12 | − * | |
| 13 | − * You should have received a copy of the GNU General Public License along | |
| 14 | − * with this program; if not, write to the Free Software Foundation, Inc., | |
| 15 | − * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
| 16 | − */ | |
| 17 | − | |
| 18 | −#ifdef NDEBUG /* Enable assert always. */ | |
| 19 | −#undef NDEBUG /* Must undef above assert.h or other that might include it. */ | |
| 20 | −#endif | |
| 21 | −#include <assert.h> | |
| 22 | −#include "sox.h" | |
| 23 | − | |
| 24 | −#define TEST_UINT(bits) \ | |
| 25 | − uint##bits = 0; \ | |
| 26 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 27 | − assert(sample == SOX_SAMPLE_MIN); \ | |
| 28 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 29 | − assert(uint##bits == 0 && clips == 0); \ | |
| 30 | − \ | |
| 31 | − uint##bits = 1; \ | |
| 32 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 33 | − assert(sample > SOX_SAMPLE_MIN && sample < 0); \ | |
| 34 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 35 | − assert(uint##bits == 1 && clips == 0); \ | |
| 36 | − \ | |
| 37 | − uint##bits = SOX_INT_MAX(bits); \ | |
| 38 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 39 | − assert(sample * SOX_INT_MAX(bits) == SOX_UNSIGNED_TO_SAMPLE(bits,1)); \ | |
| 40 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 41 | − assert(uint##bits == SOX_INT_MAX(bits) && clips == 0); \ | |
| 42 | − \ | |
| 43 | − sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \ | |
| 44 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 45 | − assert(uint##bits == 1 && clips == 0); \ | |
| 46 | − \ | |
| 47 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \ | |
| 48 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 49 | − assert(uint##bits == 0 && clips == 0); \ | |
| 50 | − \ | |
| 51 | − uint##bits = (0^SOX_INT_MIN(bits)); \ | |
| 52 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 53 | − assert(sample == 0); \ | |
| 54 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 55 | − assert(uint##bits == (0^SOX_INT_MIN(bits)) && clips == 0); \ | |
| 56 | − \ | |
| 57 | − uint##bits = ((0^SOX_INT_MIN(bits))+1); \ | |
| 58 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 59 | − assert(sample > 0 && sample < SOX_SAMPLE_MAX); \ | |
| 60 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 61 | − assert(uint##bits == ((0^SOX_INT_MIN(bits))+1) && clips == 0); \ | |
| 62 | − \ | |
| 63 | − uint##bits = SOX_UINT_MAX(bits); \ | |
| 64 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,uint##bits); \ | |
| 65 | − assert(sample == SOX_INT_MAX(bits) * SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))); \ | |
| 66 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 67 | − assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \ | |
| 68 | − \ | |
| 69 | − sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \ | |
| 70 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 71 | − assert(uint##bits == SOX_UINT_MAX(bits) && clips == 0); \ | |
| 72 | − \ | |
| 73 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \ | |
| 74 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 75 | − assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \ | |
| 76 | − \ | |
| 77 | − sample = SOX_SAMPLE_MAX; \ | |
| 78 | − uint##bits = SOX_SAMPLE_TO_UNSIGNED(bits,sample, clips); \ | |
| 79 | − assert(uint##bits == SOX_UINT_MAX(bits) && --clips == 0); \ | |
| 80 | − | |
| 81 | −#define TEST_SINT(bits) \ | |
| 82 | − int##bits = SOX_INT_MIN(bits); \ | |
| 83 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 84 | − assert(sample == SOX_SAMPLE_MIN); \ | |
| 85 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 86 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 87 | − \ | |
| 88 | − int##bits = SOX_INT_MIN(bits)+1; \ | |
| 89 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 90 | − assert(sample > SOX_SAMPLE_MIN && sample < 0); \ | |
| 91 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 92 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 93 | − \ | |
| 94 | − int##bits = SOX_UINT_MAX(bits) /* i.e. -1 */; \ | |
| 95 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 96 | − assert(sample * SOX_INT_MAX(bits) == SOX_SIGNED_TO_SAMPLE(bits,SOX_INT_MIN(bits)+1)); \ | |
| 97 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 98 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 99 | − \ | |
| 100 | − int##bits = SOX_INT_MIN(bits)+1; \ | |
| 101 | − sample =SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2; \ | |
| 102 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 103 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 104 | − \ | |
| 105 | − int##bits = SOX_INT_MIN(bits); \ | |
| 106 | − sample = SOX_UNSIGNED_TO_SAMPLE(bits,1)+SOX_UNSIGNED_TO_SAMPLE(bits,SOX_INT_MAX(bits))/2-1; \ | |
| 107 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 108 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 109 | − \ | |
| 110 | − int##bits = 0; \ | |
| 111 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 112 | − assert(sample == 0); \ | |
| 113 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 114 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 115 | − \ | |
| 116 | − int##bits = 1; \ | |
| 117 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 118 | − assert(sample > 0 && sample < SOX_SAMPLE_MAX); \ | |
| 119 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 120 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 121 | − \ | |
| 122 | − int##bits = SOX_INT_MAX(bits); \ | |
| 123 | − sample = SOX_SIGNED_TO_SAMPLE(bits,int##bits); \ | |
| 124 | − assert(sample == SOX_INT_MAX(bits) * SOX_SIGNED_TO_SAMPLE(bits,1)); \ | |
| 125 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 126 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 127 | − \ | |
| 128 | − sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2-1; \ | |
| 129 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 130 | − assert(int##bits##_2 == int##bits && clips == 0); \ | |
| 131 | − \ | |
| 132 | − sample =SOX_UNSIGNED_TO_SAMPLE(bits,SOX_UINT_MAX(bits))+SOX_UNSIGNED_TO_SAMPLE(bits,((0^SOX_INT_MIN(bits))+1))/2; \ | |
| 133 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 134 | − assert(int##bits##_2 == int##bits && --clips == 0); \ | |
| 135 | − \ | |
| 136 | − sample = SOX_SAMPLE_MAX; \ | |
| 137 | − int##bits##_2 = SOX_SAMPLE_TO_SIGNED(bits,sample, clips); \ | |
| 138 | − assert(int##bits##_2 == int##bits && --clips == 0); | |
| 139 | − | |
| 140 | −#if defined __GNUC__ | |
| 141 | − #pragma GCC system_header | |
| 142 | −#elif defined __SUNPRO_CC | |
| 143 | − #pragma disable_warn | |
| 144 | −#elif defined _MSC_VER | |
| 145 | − #pragma warning(push, 1) | |
| 146 | −#endif | |
| 147 | − | |
| 148 | −int main() | |
| 149 | −{ | |
| 150 | − sox_int8_t int8; | |
| 151 | − sox_int16_t int16; | |
| 152 | − sox_int24_t int24; | |
| 153 | − | |
| 154 | − sox_uint8_t uint8; | |
| 155 | − sox_uint16_t uint16; | |
| 156 | − sox_uint24_t uint24; | |
| 157 | − | |
| 158 | − sox_int8_t int8_2; | |
| 159 | − sox_int16_t int16_2; | |
| 160 | − sox_int24_t int24_2; | |
| 161 | − | |
| 162 | − sox_sample_t sample; | |
| 163 | − size_t clips = 0; | |
| 164 | − | |
| 165 | − double d; | |
| 166 | − SOX_SAMPLE_LOCALS; | |
| 167 | − | |
| 168 | − TEST_UINT(8) | |
| 169 | − TEST_UINT(16) | |
| 170 | − TEST_UINT(24) | |
| 171 | − | |
| 172 | − TEST_SINT(8) | |
| 173 | − TEST_SINT(16) | |
| 174 | − TEST_SINT(24) | |
| 175 | − | |
| 176 | − d = -1.000000001; | |
| 177 | − sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 178 | − assert(sample == SOX_SAMPLE_MIN && --clips == 0); | |
| 179 | − | |
| 180 | − d = -1; | |
| 181 | − sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 182 | − assert(sample == SOX_SAMPLE_MIN && clips == 0); | |
| 183 | − d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips); | |
| 184 | − assert(d == -1 && clips == 0); | |
| 185 | − | |
| 186 | − d = 1; | |
| 187 | − sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 188 | − assert(sample == SOX_SAMPLE_MAX && clips == 0); | |
| 189 | − d = SOX_SAMPLE_TO_FLOAT_64BIT(sample,clips); | |
| 190 | − assert(fabs(d - 1) < 1e-9 && clips == 0); | |
| 191 | − | |
| 192 | − d = 1.0000000001; | |
| 193 | − sample = SOX_FLOAT_64BIT_TO_SAMPLE(d, clips); | |
| 194 | − assert(sample == SOX_SAMPLE_MAX && --clips == 0); | |
| 195 | − | |
| 196 | − return 0; | |
| 197 | −} | |
| 198 | − | |
| 199 | −#if defined __SUNPRO_CC | |
| 200 | − #pragma enable_warn | |
| 201 | −#elif defined _MSC_VER | |
| 202 | − #pragma warning(pop) | |
| 203 | −#endif | |