Lines Matching refs:w
12 packs = {w: (lambda *data, width=w: pack(width, data)) for w in (1, 2, 3, 4)}
13 maxvalues = {w: (1 << (8 * w - 1)) - 1 for w in (1, 2, 3, 4)}
14 minvalues = {w: -1 << (8 * w - 1) for w in (1, 2, 3, 4)}
35 for w in 1, 2, 3, 4:
36 self.assertEqual(audioop.max(b'', w), 0)
37 self.assertEqual(audioop.max(bytearray(), w), 0)
38 self.assertEqual(audioop.max(memoryview(b''), w), 0)
39 p = packs[w]
40 self.assertEqual(audioop.max(p(5), w), 5)
41 self.assertEqual(audioop.max(p(5, -8, -1), w), 8)
42 self.assertEqual(audioop.max(p(maxvalues[w]), w), maxvalues[w])
43 self.assertEqual(audioop.max(p(minvalues[w]), w), -minvalues[w])
44 self.assertEqual(audioop.max(datas[w], w), -minvalues[w])
47 for w in 1, 2, 3, 4:
48 self.assertEqual(audioop.minmax(b'', w),
50 self.assertEqual(audioop.minmax(bytearray(), w),
52 self.assertEqual(audioop.minmax(memoryview(b''), w),
54 p = packs[w]
55 self.assertEqual(audioop.minmax(p(5), w), (5, 5))
56 self.assertEqual(audioop.minmax(p(5, -8, -1), w), (-8, 5))
57 self.assertEqual(audioop.minmax(p(maxvalues[w]), w),
58 (maxvalues[w], maxvalues[w]))
59 self.assertEqual(audioop.minmax(p(minvalues[w]), w),
60 (minvalues[w], minvalues[w]))
61 self.assertEqual(audioop.minmax(datas[w], w),
62 (minvalues[w], maxvalues[w]))
65 for w in 1, 2, 3, 4:
66 self.assertEqual(audioop.maxpp(b'', w), 0)
67 self.assertEqual(audioop.maxpp(bytearray(), w), 0)
68 self.assertEqual(audioop.maxpp(memoryview(b''), w), 0)
69 self.assertEqual(audioop.maxpp(packs[w](*range(100)), w), 0)
70 self.assertEqual(audioop.maxpp(packs[w](9, 10, 5, 5, 0, 1), w), 10)
71 self.assertEqual(audioop.maxpp(datas[w], w),
72 maxvalues[w] - minvalues[w])
75 for w in 1, 2, 3, 4:
76 self.assertEqual(audioop.avg(b'', w), 0)
77 self.assertEqual(audioop.avg(bytearray(), w), 0)
78 self.assertEqual(audioop.avg(memoryview(b''), w), 0)
79 p = packs[w]
80 self.assertEqual(audioop.avg(p(5), w), 5)
81 self .assertEqual(audioop.avg(p(5, 8), w), 6)
82 self.assertEqual(audioop.avg(p(5, -8), w), -2)
83 self.assertEqual(audioop.avg(p(maxvalues[w], maxvalues[w]), w),
84 maxvalues[w])
85 self.assertEqual(audioop.avg(p(minvalues[w], minvalues[w]), w),
86 minvalues[w])
93 for w in 1, 2, 3, 4:
94 self.assertEqual(audioop.avgpp(b'', w), 0)
95 self.assertEqual(audioop.avgpp(bytearray(), w), 0)
96 self.assertEqual(audioop.avgpp(memoryview(b''), w), 0)
97 self.assertEqual(audioop.avgpp(packs[w](*range(100)), w), 0)
98 self.assertEqual(audioop.avgpp(packs[w](9, 10, 5, 5, 0, 1), w), 10)
105 for w in 1, 2, 3, 4:
106 self.assertEqual(audioop.rms(b'', w), 0)
107 self.assertEqual(audioop.rms(bytearray(), w), 0)
108 self.assertEqual(audioop.rms(memoryview(b''), w), 0)
109 p = packs[w]
110 self.assertEqual(audioop.rms(p(*range(100)), w), 57)
111 self.assertAlmostEqual(audioop.rms(p(maxvalues[w]) * 5, w),
112 maxvalues[w], delta=1)
113 self.assertAlmostEqual(audioop.rms(p(minvalues[w]) * 5, w),
114 -minvalues[w], delta=1)
121 for w in 1, 2, 3, 4:
122 self.assertEqual(audioop.cross(b'', w), -1)
123 self.assertEqual(audioop.cross(bytearray(), w), -1)
124 self.assertEqual(audioop.cross(memoryview(b''), w), -1)
125 p = packs[w]
126 self.assertEqual(audioop.cross(p(0, 1, 2), w), 0)
127 self.assertEqual(audioop.cross(p(1, 2, -3, -4), w), 1)
128 self.assertEqual(audioop.cross(p(-1, -2, 3, 4), w), 1)
129 self.assertEqual(audioop.cross(p(0, minvalues[w]), w), 1)
130 self.assertEqual(audioop.cross(p(minvalues[w], maxvalues[w]), w), 1)
133 for w in 1, 2, 3, 4:
134 self.assertEqual(audioop.add(b'', b'', w), b'')
135 self.assertEqual(audioop.add(bytearray(), bytearray(), w), b'')
136 self.assertEqual(audioop.add(memoryview(b''), memoryview(b''), w), b'')
137 self.assertEqual(audioop.add(datas[w], b'\0' * len(datas[w]), w),
138 datas[w])
151 for w in 1, 2, 3, 4:
153 self.assertEqual(audioop.bias(b'', w, bias), b'')
154 self.assertEqual(audioop.bias(bytearray(), w, bias), b'')
155 self.assertEqual(audioop.bias(memoryview(b''), w, bias), b'')
197 for w in 1, 2, 3, 4:
198 self.assertEqual(audioop.lin2lin(datas[w], w, w), datas[w])
199 self.assertEqual(audioop.lin2lin(bytearray(datas[w]), w, w),
200 datas[w])
201 self.assertEqual(audioop.lin2lin(memoryview(datas[w]), w, w),
202 datas[w])
252 for w in 1, 2, 3, 4:
253 self.assertEqual(audioop.adpcm2lin(b'\0' * 5, w, None),
254 (b'\0' * w * 10, (0, 0)))
263 for w in 2, 3, 4:
264 self.assertEqual(audioop.lin2adpcm(datas[w], w, None),
268 for w in 1, 2, 3, 4:
269 self.assertEqual(audioop.lin2adpcm(b'\0' * w * 10, w, None),
294 for w in 2, 3, 4:
295 self.assertEqual(audioop.lin2alaw(datas[w], w),
303 for w in 1, 2, 3, 4:
304 decoded = packs[w](*(x << (w * 8) >> 13 for x in src))
305 self.assertEqual(audioop.alaw2lin(encoded, w), decoded)
306 self.assertEqual(audioop.alaw2lin(bytearray(encoded), w), decoded)
307 self.assertEqual(audioop.alaw2lin(memoryview(encoded), w), decoded)
310 for w in 2, 3, 4:
311 decoded = audioop.alaw2lin(encoded, w)
312 self.assertEqual(audioop.lin2alaw(decoded, w), encoded)
321 for w in 2, 3, 4:
322 self.assertEqual(audioop.lin2ulaw(datas[w], w),
330 for w in 1, 2, 3, 4:
331 decoded = packs[w](*(x << (w * 8) >> 14 for x in src))
332 self.assertEqual(audioop.ulaw2lin(encoded, w), decoded)
333 self.assertEqual(audioop.ulaw2lin(bytearray(encoded), w), decoded)
334 self.assertEqual(audioop.ulaw2lin(memoryview(encoded), w), decoded)
338 for w in 2, 3, 4:
339 decoded = audioop.ulaw2lin(encoded, w)
340 self.assertEqual(audioop.lin2ulaw(decoded, w), encoded)
343 for w in 1, 2, 3, 4:
344 self.assertEqual(audioop.mul(b'', w, 2), b'')
345 self.assertEqual(audioop.mul(bytearray(), w, 2), b'')
346 self.assertEqual(audioop.mul(memoryview(b''), w, 2), b'')
347 self.assertEqual(audioop.mul(datas[w], w, 0),
348 b'\0' * len(datas[w]))
349 self.assertEqual(audioop.mul(datas[w], w, 1),
350 datas[w])
363 for w in 1, 2, 3, 4:
364 self.assertEqual(audioop.ratecv(b'', w, 1, 8000, 8000, None),
366 self.assertEqual(audioop.ratecv(bytearray(), w, 1, 8000, 8000, None),
368 self.assertEqual(audioop.ratecv(memoryview(b''), w, 1, 8000, 8000, None),
370 self.assertEqual(audioop.ratecv(b'', w, 5, 8000, 8000, None),
372 self.assertEqual(audioop.ratecv(b'', w, 1, 8000, 16000, None),
374 self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None)[0],
375 datas[w])
376 self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 1, 0)[0],
377 datas[w])
384 for w in 1, 2, 3, 4:
385 d0, state0 = audioop.ratecv(datas[w], w, 1, 8000, 16000, None)
387 for i in range(0, len(datas[w]), w):
388 d1, state = audioop.ratecv(datas[w][i:i + w], w, 1,
402 for w in 1, 2, 3, 4:
403 self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 3, 1)[0],
404 expected[w])
405 self.assertEqual(audioop.ratecv(datas[w], w, 1, 8000, 8000, None, 30, 10)[0],
406 expected[w])
413 for w in 1, 2, 3, 4:
414 self.assertEqual(audioop.reverse(b'', w), b'')
415 self.assertEqual(audioop.reverse(bytearray(), w), b'')
416 self.assertEqual(audioop.reverse(memoryview(b''), w), b'')
417 self.assertEqual(audioop.reverse(packs[w](0, 1, 2), w),
418 packs[w](2, 1, 0))
421 for w in 1, 2, 3, 4:
422 data1 = datas[w]
424 for k in range(w):
425 data2[k::2*w] = data1[k::w]
426 self.assertEqual(audioop.tomono(data2, w, 1, 0), data1)
427 self.assertEqual(audioop.tomono(data2, w, 0, 1), b'\0' * len(data1))
428 for k in range(w):
429 data2[k+w::2*w] = data1[k::w]
430 self.assertEqual(audioop.tomono(data2, w, 0.5, 0.5), data1)
431 self.assertEqual(audioop.tomono(bytearray(data2), w, 0.5, 0.5),
433 self.assertEqual(audioop.tomono(memoryview(data2), w, 0.5, 0.5),
437 for w in 1, 2, 3, 4:
438 data1 = datas[w]
440 for k in range(w):
441 data2[k::2*w] = data1[k::w]
442 self.assertEqual(audioop.tostereo(data1, w, 1, 0), data2)
443 self.assertEqual(audioop.tostereo(data1, w, 0, 0), b'\0' * len(data2))
444 for k in range(w):
445 data2[k+w::2*w] = data1[k::w]
446 self.assertEqual(audioop.tostereo(data1, w, 1, 1), data2)
447 self.assertEqual(audioop.tostereo(bytearray(data1), w, 1, 1), data2)
448 self.assertEqual(audioop.tostereo(memoryview(data1), w, 1, 1),
477 for w in 1, 2, 3, 4:
478 data = packs[w](0, 1, -1, maxvalues[w], minvalues[w])
479 self.assertEqual(audioop.getsample(data, w, 0), 0)
480 self.assertEqual(audioop.getsample(bytearray(data), w, 0), 0)
481 self.assertEqual(audioop.getsample(memoryview(data), w, 0), 0)
482 self.assertEqual(audioop.getsample(data, w, 1), 1)
483 self.assertEqual(audioop.getsample(data, w, 2), -1)
484 self.assertEqual(audioop.getsample(data, w, 3), maxvalues[w])
485 self.assertEqual(audioop.getsample(data, w, 4), minvalues[w])
495 for w in 1, 2, 3, 4:
496 self.assertEqual(audioop.byteswap(b'', w), b'')
497 self.assertEqual(audioop.byteswap(datas[w], w), swapped_datas[w])
498 self.assertEqual(audioop.byteswap(swapped_datas[w], w), datas[w])
499 self.assertEqual(audioop.byteswap(bytearray(datas[w]), w),
500 swapped_datas[w])
501 self.assertEqual(audioop.byteswap(memoryview(datas[w]), w),
502 swapped_datas[w])