Alexandre Lision | 7c6f4a6 | 2013-09-05 13:27:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright (C) 2007-2011 Erik de Castro Lopo <erikd@mega-nerd.com> |
| 3 | ** Copyright (c) 2007 <robs@users.sourceforge.net> |
| 4 | ** |
| 5 | ** This library is free software; you can redistribute it and/or modify it |
| 6 | ** under the terms of the GNU Lesser General Public License as published by |
| 7 | ** the Free Software Foundation; either version 2 of the License, or (at |
| 8 | ** your option) any later version. |
| 9 | ** |
| 10 | ** This library is distributed in the hope that it will be useful, but |
| 11 | ** WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser |
| 13 | ** General Public License for more details. |
| 14 | ** |
| 15 | ** You should have received a copy of the GNU Lesser General Public License |
| 16 | ** along with this library. If not, write to the Free Software Foundation, |
| 17 | ** Fifth Floor, 51 Franklin Street, Boston, MA 02111-1301, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "sfconfig.h" |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #include "test_main.h" |
| 25 | |
| 26 | #include "ima_oki_adpcm.c" |
| 27 | |
| 28 | static const unsigned char test_codes [] = |
| 29 | { 0x08, 0x08, 0x04, 0x7f, 0x72, 0xf7, 0x9f, 0x7c, 0xd7, 0xbc, 0x7a, 0xa7, 0xb8, |
| 30 | 0x4b, 0x0b, 0x38, 0xf6, 0x9d, 0x7a, 0xd7, 0xbc, 0x7a, 0xd7, 0xa8, 0x6c, 0x81, |
| 31 | 0x98, 0xe4, 0x0e, 0x7a, 0xd7, 0x9e, 0x7b, 0xc7, 0xab, 0x7a, 0x85, 0xc0, 0xb3, |
| 32 | 0x8f, 0x58, 0xd7, 0xad, 0x7a, 0xd7, 0xad, 0x7a, 0x87, 0xd0, 0x2b, 0x0e, 0x48, |
| 33 | 0xd7, 0xad, 0x78, 0xf7, 0xbc, 0x7a, 0xb7, 0xa8, 0x4b, 0x88, 0x18, 0xd5, 0x8d, |
| 34 | 0x6a, 0xa4, 0x98, 0x08, 0x00, 0x80, 0x88, |
| 35 | } ; |
| 36 | |
| 37 | static const short test_pcm [] = |
| 38 | { 32, 0, 32, 0, 32, 320, 880, -336, 2304, 4192, -992, 10128, 5360, -16352, |
| 39 | 30208, 2272, -31872, 14688, -7040, -32432, 14128, -1392, -15488, 22960, |
| 40 | 1232, -1584, 21488, -240, 2576, -15360, 960, -1152, -30032, 10320, 1008, |
| 41 | -30032, 16528, 1008, -30032, 16528, -5200, -30592, 15968, 448, -30592, |
| 42 | 15968, 448, -2368, 30960, 3024, -80, 8384, 704, -1616, -29168, -1232, 1872, |
| 43 | -32768, 13792, -1728, -32768, 13792, 4480, -32192, 14368, -7360, -32752, |
| 44 | 13808, -1712, -21456, 16992, 1472, -1344, 26848, -1088, 2016, -17728, 208, |
| 45 | -2112, -32768, 1376, -1728, -32768, 13792, -1728, -32768, 13792, -1728, |
| 46 | -32768, 13792, -1728, -32768, 13792, -1728, -4544, 32767, -1377, 1727, |
| 47 | 15823, -2113, 207, -27345, 591, -2513, -32768, 13792, -1728, -32768, 13792, |
| 48 | 10688, -31632, 14928, -6800, -32192, 14368, -1152, -20896, 17552, 2032, |
| 49 | -784, 22288, 560, -2256, -4816, 2176, 64, -21120, 9920, 6816, -24224, 16128, |
| 50 | 608, -13488, 9584, 272, -2544, 16, -2304, -192, 1728, -16, 1568, 128, -1184, |
| 51 | } ; |
| 52 | |
| 53 | |
| 54 | static void |
| 55 | test_oki_adpcm (void) |
| 56 | { |
| 57 | IMA_OKI_ADPCM adpcm ; |
| 58 | unsigned char code ; |
| 59 | int i, j ; |
| 60 | |
| 61 | print_test_name ("Testing ima/oki encoder") ; |
| 62 | |
| 63 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; |
| 64 | for (i = 0 ; i < ARRAY_LEN (test_codes) ; i++) |
| 65 | for (j = 0, code = test_codes [i] ; j < 2 ; j++, code <<= 4) |
| 66 | if (adpcm_decode (&adpcm, code >> 4) != test_pcm [2 * i + j]) |
| 67 | { printf ("\n\nFail at i = %d, j = %d.\n\n", i, j) ; |
| 68 | exit (1) ; |
| 69 | } ; |
| 70 | |
| 71 | puts ("ok") ; |
| 72 | |
| 73 | print_test_name ("Testing ima/oki decoder") ; |
| 74 | |
| 75 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; |
| 76 | for (i = 0 ; i < ARRAY_LEN (test_pcm) - 1 ; i += 2) |
| 77 | { code = adpcm_encode (&adpcm, test_pcm [i]) ; |
| 78 | code = (code << 4) | adpcm_encode (&adpcm, test_pcm [i + 1]) ; |
| 79 | if (code != test_codes [i / 2]) |
| 80 | { printf ("\n\nFail at i = %d, %d should be %d\n\n", i, code, test_codes [i / 2]) ; |
| 81 | exit (1) ; |
| 82 | } ; |
| 83 | } ; |
| 84 | |
| 85 | puts ("ok") ; |
| 86 | } /* test_oki_adpcm */ |
| 87 | |
| 88 | static void |
| 89 | test_oki_adpcm_block (void) |
| 90 | { |
| 91 | IMA_OKI_ADPCM adpcm ; |
| 92 | int k ; |
| 93 | |
| 94 | if (ARRAY_LEN (adpcm.pcm) < ARRAY_LEN (test_pcm)) |
| 95 | { printf ("\n\nLine %d : ARRAY_LEN (adpcm->pcm) > ARRAY_LEN (test_pcm) (%d > %d).\n\n", __LINE__, ARRAY_LEN (adpcm.pcm), ARRAY_LEN (test_pcm)) ; |
| 96 | exit (1) ; |
| 97 | } ; |
| 98 | |
| 99 | if (ARRAY_LEN (adpcm.codes) < ARRAY_LEN (test_codes)) |
| 100 | { printf ("\n\nLine %d : ARRAY_LEN (adcodes->codes) > ARRAY_LEN (test_codes).n", __LINE__) ; |
| 101 | exit (1) ; |
| 102 | } ; |
| 103 | |
| 104 | print_test_name ("Testing ima/oki block encoder") ; |
| 105 | |
| 106 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; |
| 107 | |
| 108 | memcpy (adpcm.pcm, test_pcm, sizeof (adpcm.pcm [0]) * ARRAY_LEN (test_pcm)) ; |
| 109 | adpcm.pcm_count = ARRAY_LEN (test_pcm) ; |
| 110 | adpcm.code_count = 13 ; |
| 111 | |
| 112 | ima_oki_adpcm_encode_block (&adpcm) ; |
| 113 | |
| 114 | if (adpcm.code_count * 2 != ARRAY_LEN (test_pcm)) |
| 115 | { printf ("\n\nLine %d : %d * 2 != %d\n\n", __LINE__, adpcm.code_count * 2, ARRAY_LEN (test_pcm)) ; |
| 116 | exit (1) ; |
| 117 | } ; |
| 118 | |
| 119 | for (k = 0 ; k < ARRAY_LEN (test_codes) ; k++) |
| 120 | if (adpcm.codes [k] != test_codes [k]) |
| 121 | { printf ("\n\nLine %d : Fail at k = %d, %d should be %d\n\n", __LINE__, k, adpcm.codes [k], test_codes [k]) ; |
| 122 | exit (1) ; |
| 123 | } ; |
| 124 | |
| 125 | puts ("ok") ; |
| 126 | |
| 127 | print_test_name ("Testing ima/oki block decoder") ; |
| 128 | |
| 129 | ima_oki_adpcm_init (&adpcm, IMA_OKI_ADPCM_TYPE_OKI) ; |
| 130 | |
| 131 | memcpy (adpcm.codes, test_codes, sizeof (adpcm.codes [0]) * ARRAY_LEN (test_codes)) ; |
| 132 | adpcm.code_count = ARRAY_LEN (test_codes) ; |
| 133 | adpcm.pcm_count = 13 ; |
| 134 | |
| 135 | ima_oki_adpcm_decode_block (&adpcm) ; |
| 136 | |
| 137 | if (adpcm.pcm_count != 2 * ARRAY_LEN (test_codes)) |
| 138 | { printf ("\n\nLine %d : %d * 2 != %d\n\n", __LINE__, adpcm.pcm_count, 2 * ARRAY_LEN (test_codes)) ; |
| 139 | exit (1) ; |
| 140 | } ; |
| 141 | |
| 142 | for (k = 0 ; k < ARRAY_LEN (test_pcm) ; k++) |
| 143 | if (adpcm.pcm [k] != test_pcm [k]) |
| 144 | { printf ("\n\nLine %d : Fail at i = %d, %d should be %d.\n\n", __LINE__, k, adpcm.pcm [k], test_pcm [k]) ; |
| 145 | exit (1) ; |
| 146 | } ; |
| 147 | |
| 148 | puts ("ok") ; |
| 149 | } /* test_oki_adpcm_block */ |
| 150 | |
| 151 | void |
| 152 | test_ima_oki_adpcm (void) |
| 153 | { |
| 154 | test_oki_adpcm () ; |
| 155 | test_oki_adpcm_block () ; |
| 156 | } /* main */ |
| 157 | |