Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 1 | # Test audioop. |
| 2 | import audioop |
Benjamin Peterson | ee8712c | 2008-05-20 21:35:26 +0000 | [diff] [blame] | 3 | from test.support import verbose |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 4 | |
| 5 | def gendata1(): |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 6 | return b'\0\1\2' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 7 | |
| 8 | def gendata2(): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 9 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 10 | print('getsample') |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 11 | if audioop.getsample(b'\0\1', 2, 0) == 1: |
| 12 | return b'\0\0\0\1\0\2' |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 13 | else: |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 14 | return b'\0\0\1\0\2\0' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 15 | |
| 16 | def gendata4(): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 17 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 18 | print('getsample') |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 19 | if audioop.getsample(b'\0\0\0\1', 4, 0) == 1: |
| 20 | return b'\0\0\0\0\0\0\0\1\0\0\0\2' |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 21 | else: |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 22 | return b'\0\0\0\0\1\0\0\0\2\0\0\0' |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 23 | |
| 24 | def testmax(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 25 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 26 | print('max') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 27 | if audioop.max(data[0], 1) != 2 or \ |
| 28 | audioop.max(data[1], 2) != 2 or \ |
| 29 | audioop.max(data[2], 4) != 2: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 30 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 31 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 32 | |
Guido van Rossum | 4fdb744 | 1996-12-20 03:13:06 +0000 | [diff] [blame] | 33 | def testminmax(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 34 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 35 | print('minmax') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 36 | if audioop.minmax(data[0], 1) != (0, 2) or \ |
| 37 | audioop.minmax(data[1], 2) != (0, 2) or \ |
| 38 | audioop.minmax(data[2], 4) != (0, 2): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 39 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 40 | return 1 |
Guido van Rossum | 4fdb744 | 1996-12-20 03:13:06 +0000 | [diff] [blame] | 41 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 42 | def testmaxpp(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 43 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 44 | print('maxpp') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 45 | if audioop.maxpp(data[0], 1) != 0 or \ |
| 46 | audioop.maxpp(data[1], 2) != 0 or \ |
| 47 | audioop.maxpp(data[2], 4) != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 48 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 49 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 50 | |
| 51 | def testavg(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 52 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 53 | print('avg') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 54 | if audioop.avg(data[0], 1) != 1 or \ |
| 55 | audioop.avg(data[1], 2) != 1 or \ |
| 56 | audioop.avg(data[2], 4) != 1: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 57 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 58 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 59 | |
| 60 | def testavgpp(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 61 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 62 | print('avgpp') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 63 | if audioop.avgpp(data[0], 1) != 0 or \ |
| 64 | audioop.avgpp(data[1], 2) != 0 or \ |
| 65 | audioop.avgpp(data[2], 4) != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 66 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 67 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 68 | |
| 69 | def testrms(data): |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 70 | if audioop.rms(data[0], 1) != 1 or \ |
| 71 | audioop.rms(data[1], 2) != 1 or \ |
| 72 | audioop.rms(data[2], 4) != 1: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 73 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 74 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 75 | |
| 76 | def testcross(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 77 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 78 | print('cross') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 79 | if audioop.cross(data[0], 1) != 0 or \ |
| 80 | audioop.cross(data[1], 2) != 0 or \ |
| 81 | audioop.cross(data[2], 4) != 0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 82 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 83 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 84 | |
| 85 | def testadd(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 86 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 87 | print('add') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 88 | data2 = [] |
| 89 | for d in data: |
Guido van Rossum | 254348e | 2007-11-21 19:29:53 +0000 | [diff] [blame] | 90 | str = bytearray(len(d)) |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 91 | for i,b in enumerate(d): |
| 92 | str[i] = 2*b |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 93 | data2.append(str) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 94 | if audioop.add(data[0], data[0], 1) != data2[0] or \ |
| 95 | audioop.add(data[1], data[1], 2) != data2[1] or \ |
| 96 | audioop.add(data[2], data[2], 4) != data2[2]: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 97 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 98 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 99 | |
| 100 | def testbias(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 101 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 102 | print('bias') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 103 | # Note: this test assumes that avg() works |
| 104 | d1 = audioop.bias(data[0], 1, 100) |
| 105 | d2 = audioop.bias(data[1], 2, 100) |
| 106 | d4 = audioop.bias(data[2], 4, 100) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 107 | if audioop.avg(d1, 1) != 101 or \ |
| 108 | audioop.avg(d2, 2) != 101 or \ |
| 109 | audioop.avg(d4, 4) != 101: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 110 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 111 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 112 | |
| 113 | def testlin2lin(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 114 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 115 | print('lin2lin') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 116 | # too simple: we test only the size |
| 117 | for d1 in data: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 118 | for d2 in data: |
Guido van Rossum | 54e54c6 | 2001-09-04 19:14:14 +0000 | [diff] [blame] | 119 | got = len(d1)//3 |
| 120 | wtd = len(d2)//3 |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 121 | if len(audioop.lin2lin(d1, got, wtd)) != len(d2): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 122 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 123 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 124 | |
| 125 | def testadpcm2lin(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 126 | # Very cursory test |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 127 | if audioop.adpcm2lin(b'\0\0', 1, None) != (b'\0\0\0\0', (0,0)): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 128 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 129 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 130 | |
| 131 | def testlin2adpcm(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 132 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 133 | print('lin2adpcm') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 134 | # Very cursory test |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 135 | if audioop.lin2adpcm(b'\0\0\0\0', 1, None) != (b'\0\0', (0,0)): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 136 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 137 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 138 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 139 | def testlin2alaw(data): |
| 140 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 141 | print('lin2alaw') |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 142 | if audioop.lin2alaw(data[0], 1) != b'\xd5\xc5\xf5' or \ |
| 143 | audioop.lin2alaw(data[1], 2) != b'\xd5\xd5\xd5' or \ |
| 144 | audioop.lin2alaw(data[2], 4) != b'\xd5\xd5\xd5': |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 145 | return 0 |
| 146 | return 1 |
| 147 | |
| 148 | def testalaw2lin(data): |
| 149 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 150 | print('alaw2lin') |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 151 | # Cursory |
| 152 | d = audioop.lin2alaw(data[0], 1) |
| 153 | if audioop.alaw2lin(d, 1) != data[0]: |
| 154 | return 0 |
| 155 | return 1 |
| 156 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 157 | def testlin2ulaw(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 158 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 159 | print('lin2ulaw') |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 160 | if audioop.lin2ulaw(data[0], 1) != b'\xff\xe7\xdb' or \ |
| 161 | audioop.lin2ulaw(data[1], 2) != b'\xff\xff\xff' or \ |
| 162 | audioop.lin2ulaw(data[2], 4) != b'\xff\xff\xff': |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 163 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 164 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 165 | |
| 166 | def testulaw2lin(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 167 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 168 | print('ulaw2lin') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 169 | # Cursory |
| 170 | d = audioop.lin2ulaw(data[0], 1) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 171 | if audioop.ulaw2lin(d, 1) != data[0]: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 172 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 173 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 174 | |
| 175 | def testmul(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 176 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 177 | print('mul') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 178 | data2 = [] |
| 179 | for d in data: |
Guido van Rossum | 254348e | 2007-11-21 19:29:53 +0000 | [diff] [blame] | 180 | str = bytearray(len(d)) |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 181 | for i,b in enumerate(d): |
| 182 | str[i] = 2*b |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 183 | data2.append(str) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 184 | if audioop.mul(data[0], 1, 2) != data2[0] or \ |
| 185 | audioop.mul(data[1],2, 2) != data2[1] or \ |
| 186 | audioop.mul(data[2], 4, 2) != data2[2]: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 187 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 188 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 189 | |
Guido van Rossum | c8504e2 | 1997-02-14 15:58:00 +0000 | [diff] [blame] | 190 | def testratecv(data): |
| 191 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 192 | print('ratecv') |
Guido van Rossum | 05ba2ab | 1997-05-21 14:27:20 +0000 | [diff] [blame] | 193 | state = None |
| 194 | d1, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state) |
| 195 | d2, state = audioop.ratecv(data[0], 1, 1, 8000, 16000, state) |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 196 | if d1 + d2 != b'\000\000\001\001\002\001\000\000\001\001\002': |
Guido van Rossum | 05ba2ab | 1997-05-21 14:27:20 +0000 | [diff] [blame] | 197 | return 0 |
Guido van Rossum | c8504e2 | 1997-02-14 15:58:00 +0000 | [diff] [blame] | 198 | return 1 |
| 199 | |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 200 | def testreverse(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 201 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 202 | print('reverse') |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 203 | if audioop.reverse(data[0], 1) != b'\2\1\0': |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 204 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 205 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 206 | |
| 207 | def testtomono(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 208 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 209 | print('tomono') |
Guido van Rossum | 254348e | 2007-11-21 19:29:53 +0000 | [diff] [blame] | 210 | data2 = bytearray() |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 211 | for d in data[0]: |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 212 | data2.append(d) |
| 213 | data2.append(d) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 214 | if audioop.tomono(data2, 1, 0.5, 0.5) != data[0]: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 215 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 216 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 217 | |
| 218 | def testtostereo(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 219 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 220 | print('tostereo') |
Guido van Rossum | 254348e | 2007-11-21 19:29:53 +0000 | [diff] [blame] | 221 | data2 = bytearray() |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 222 | for d in data[0]: |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 223 | data2.append(d) |
| 224 | data2.append(d) |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 225 | if audioop.tostereo(data[0], 1, 1, 1) != data2: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 226 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 227 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 228 | |
| 229 | def testfindfactor(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 230 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 231 | print('findfactor') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 232 | if audioop.findfactor(data[1], data[1]) != 1.0: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 233 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 234 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 235 | |
| 236 | def testfindfit(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 237 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 238 | print('findfit') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 239 | if audioop.findfit(data[1], data[1]) != (0, 1.0): |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 240 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 241 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 242 | |
| 243 | def testfindmax(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 244 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 245 | print('findmax') |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 246 | if audioop.findmax(data[1], 1) != 2: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 247 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 248 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 249 | |
| 250 | def testgetsample(data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 251 | if verbose: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 252 | print('getsample') |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 253 | for i in range(3): |
Fred Drake | 132dce2 | 2000-12-12 23:11:42 +0000 | [diff] [blame] | 254 | if audioop.getsample(data[0], 1, i) != i or \ |
| 255 | audioop.getsample(data[1], 2, i) != i or \ |
| 256 | audioop.getsample(data[2], 4, i) != i: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 257 | return 0 |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 258 | return 1 |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 259 | |
| 260 | def testone(name, data): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 261 | try: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 262 | func = eval('test'+name) |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 263 | except NameError: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 264 | print('No test found for audioop.'+name+'()') |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 265 | return |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 266 | try: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 267 | rv = func(data) |
Martin v. Löwis | 3a2e5ce | 2007-07-20 07:36:26 +0000 | [diff] [blame] | 268 | except Exception as e: |
| 269 | print('Test FAILED for audioop.'+name+'() (with %s)' % repr(e)) |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 270 | return |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 271 | if not rv: |
Guido van Rossum | be19ed7 | 2007-02-09 05:37:30 +0000 | [diff] [blame] | 272 | print('Test FAILED for audioop.'+name+'()') |
Guido van Rossum | fa7fcb9 | 1994-01-12 09:55:11 +0000 | [diff] [blame] | 273 | |
Christian Heimes | 180510d | 2008-03-03 19:15:45 +0000 | [diff] [blame] | 274 | def test_main(): |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 275 | data = [gendata1(), gendata2(), gendata4()] |
| 276 | names = dir(audioop) |
| 277 | # We know there is a routine 'add' |
| 278 | routines = [] |
| 279 | for n in names: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 280 | if type(eval('audioop.'+n)) == type(audioop.add): |
| 281 | routines.append(n) |
Roger E. Masse | 7a61f87 | 1997-01-03 19:20:17 +0000 | [diff] [blame] | 282 | for n in routines: |
Guido van Rossum | 41360a4 | 1998-03-26 19:42:58 +0000 | [diff] [blame] | 283 | testone(n, data) |
Christian Heimes | 180510d | 2008-03-03 19:15:45 +0000 | [diff] [blame] | 284 | |
| 285 | |
| 286 | |
| 287 | if __name__ == '__main__': |
| 288 | test_main() |