Mercurial > octave
comparison scripts/audio/lin2mu.m @ 30974:e4f9db6543bd
test: new BISTs for lin2mu.m (patch #10192).
* scripts/audio/lin2mu.m: new BISTs.
Co-authored-by: Kai T. Ohlhus <k.ohlhus@gmail.com>
author | Shreya Gupta <shreyaguptammm@gmail.com> |
---|---|
date | Sun, 01 May 2022 12:53:26 +0900 |
parents | 796f54d4ddbf |
children | 13a7af4ca0da |
comparison
equal
deleted
inserted
replaced
30973:767c9131cf64 | 30974:e4f9db6543bd |
---|---|
72 | 72 |
73 ## Take absolute value of x, but force it to be smaller than 32636; | 73 ## Take absolute value of x, but force it to be smaller than 32636; |
74 ## add bias. | 74 ## add bias. |
75 x = min (abs (x), 32635) + 132; | 75 x = min (abs (x), 32635) + 132; |
76 | 76 |
77 ## Find exponent and fraction of bineary representation. | 77 ## Find exponent and fraction of binary representation. |
78 [f, e] = log2 (x); | 78 [f, e] = log2 (x); |
79 | 79 |
80 y = 64 * sig - 16 * e - fix (32 * f) + 335; | 80 y = 64 * sig - 16 * e - fix (32 * f) + 335; |
81 | 81 |
82 endfunction | 82 endfunction |
83 | |
84 ## Test functionality | |
85 %!test | |
86 %! x = -1:1; | |
87 %! y = x'; | |
88 %! assert (lin2mu (x), (lin2mu (y))') | |
89 %! assert (lin2mu (x), [0, 255, 128]) | |
90 | |
91 %!assert (lin2mu ([0, 1, NaN, inf, -inf], 8), [255, 231, NaN, 128, 0]) | |
92 %!assert (lin2mu ([]), []) | |
93 %!assert (lin2mu (0), 255) | |
94 %!assert (lin2mu (0, 0), 255) | |
95 %!assert (lin2mu (0, 8), 255) | |
96 %!assert (lin2mu (0, 16), 255) | |
97 %!assert (lin2mu (2, 8), 219) | |
98 %!assert (lin2mu (3, []), 255) | |
99 %!assert (lin2mu (3, 16), 255) | |
100 %!assert (lin2mu (repmat (-0.23, 1, 1000), 0), repmat (34, 1, 1000)) | |
101 %!assert (lin2mu (ones (2, 2), 0), repmat (128, 2)) | |
102 | |
103 ## Test input validation | |
104 %!error <Invalid call> lin2mu () | |
105 %!warning <no precision specified, so using 8> assert (lin2mu (2), 219) | |
106 %!error <N must be either 0, 8 or 16> lin2mu (1, 2) | |
107 %!error <N must be either 0, 8 or 16> lin2mu (1, [1,2]) | |
108 %!error <N must be either 0, 8 or 16> lin2mu (1, ones (1, 2)) | |
109 %!error <abs: not defined for cell> lin2mu ({2:5}) |