我们从Python开源项目中,提取了以下19个代码示例,用于说明如何使用audioop.minmax()。
def test_issue7673(self): state = None for data, size in INVALID_DATA: size2 = size self.assertRaises(audioop.error, audioop.getsample, data, size, 0) self.assertRaises(audioop.error, audioop.max, data, size) self.assertRaises(audioop.error, audioop.minmax, data, size) self.assertRaises(audioop.error, audioop.avg, data, size) self.assertRaises(audioop.error, audioop.rms, data, size) self.assertRaises(audioop.error, audioop.avgpp, data, size) self.assertRaises(audioop.error, audioop.maxpp, data, size) self.assertRaises(audioop.error, audioop.cross, data, size) self.assertRaises(audioop.error, audioop.mul, data, size, 1.0) self.assertRaises(audioop.error, audioop.tomono, data, size, 0.5, 0.5) self.assertRaises(audioop.error, audioop.tostereo, data, size, 0.5, 0.5) self.assertRaises(audioop.error, audioop.add, data, data, size) self.assertRaises(audioop.error, audioop.bias, data, size, 0) self.assertRaises(audioop.error, audioop.reverse, data, size) self.assertRaises(audioop.error, audioop.lin2lin, data, size, size2) self.assertRaises(audioop.error, audioop.ratecv, data, size, 1, 1, 1, state) self.assertRaises(audioop.error, audioop.lin2ulaw, data, size) self.assertRaises(audioop.error, audioop.lin2alaw, data, size) self.assertRaises(audioop.error, audioop.lin2adpcm, data, size, state)
def test_minmax(self): for w in 1, 2, 3, 4: self.assertEqual(audioop.minmax(b'', w), (0x7fffffff, -0x80000000)) self.assertEqual(audioop.minmax(bytearray(), w), (0x7fffffff, -0x80000000)) self.assertEqual(audioop.minmax(memoryview(b''), w), (0x7fffffff, -0x80000000)) p = packs[w] self.assertEqual(audioop.minmax(p(5), w), (5, 5)) self.assertEqual(audioop.minmax(p(5, -8, -1), w), (-8, 5)) self.assertEqual(audioop.minmax(p(maxvalues[w]), w), (maxvalues[w], maxvalues[w])) self.assertEqual(audioop.minmax(p(minvalues[w]), w), (minvalues[w], minvalues[w])) self.assertEqual(audioop.minmax(datas[w], w), (minvalues[w], maxvalues[w]))
def test_string(self): data = 'abcd' size = 2 self.assertRaises(TypeError, audioop.getsample, data, size, 0) self.assertRaises(TypeError, audioop.max, data, size) self.assertRaises(TypeError, audioop.minmax, data, size) self.assertRaises(TypeError, audioop.avg, data, size) self.assertRaises(TypeError, audioop.rms, data, size) self.assertRaises(TypeError, audioop.avgpp, data, size) self.assertRaises(TypeError, audioop.maxpp, data, size) self.assertRaises(TypeError, audioop.cross, data, size) self.assertRaises(TypeError, audioop.mul, data, size, 1.0) self.assertRaises(TypeError, audioop.tomono, data, size, 0.5, 0.5) self.assertRaises(TypeError, audioop.tostereo, data, size, 0.5, 0.5) self.assertRaises(TypeError, audioop.add, data, data, size) self.assertRaises(TypeError, audioop.bias, data, size, 0) self.assertRaises(TypeError, audioop.reverse, data, size) self.assertRaises(TypeError, audioop.lin2lin, data, size, size) self.assertRaises(TypeError, audioop.ratecv, data, size, 1, 1, 1, None) self.assertRaises(TypeError, audioop.lin2ulaw, data, size) self.assertRaises(TypeError, audioop.lin2alaw, data, size) self.assertRaises(TypeError, audioop.lin2adpcm, data, size, None)
def _write_frames_to_file(self, frames, framerate, volume): with tempfile.NamedTemporaryFile(mode='w+b') as f: wav_fp = wave.open(f, 'wb') wav_fp.setnchannels(self._input_channels) wav_fp.setsampwidth(int(self._input_bits / 8)) wav_fp.setframerate(framerate) if self._input_rate == framerate: fragment = ''.join(frames) else: fragment = audioop.ratecv(''.join(frames), int(self._input_bits / 8), self._input_channels, self._input_rate, framerate, None)[0] if volume is not None: maxvolume = audioop.minmax(fragment, self._input_bits / 8)[1] fragment = audioop.mul( fragment, int(self._input_bits / 8), volume * (2. ** 15) / maxvolume) wav_fp.writeframes(fragment) wav_fp.close() f.seek(0) yield f
def test_minmax(self): self.assertEqual(audioop.minmax(data[0], 1), (0, 2)) self.assertEqual(audioop.minmax(data[1], 2), (0, 2)) self.assertEqual(audioop.minmax(data[2], 4), (0, 2))
def test_minmax(self): for w in 1, 2, 4: self.assertEqual(audioop.minmax(b'', w), (0x7fffffff, -0x80000000)) p = packs[w] self.assertEqual(audioop.minmax(p(5), w), (5, 5)) self.assertEqual(audioop.minmax(p(5, -8, -1), w), (-8, 5)) self.assertEqual(audioop.minmax(p(maxvalues[w]), w), (maxvalues[w], maxvalues[w])) self.assertEqual(audioop.minmax(p(minvalues[w]), w), (minvalues[w], minvalues[w])) self.assertEqual(audioop.minmax(datas[w], w), (minvalues[w], maxvalues[w]))