本文整理匯總了Python中audioop.max方法的典型用法代碼示例。如果您正苦於以下問題:Python audioop.max方法的具體用法?Python audioop.max怎麽用?Python audioop.max使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類audioop
的用法示例。
在下文中一共展示了audioop.max方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_issue7673
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
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)
示例2: test_string
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
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)
示例3: __db_level
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def __db_level(self, rms_mode: bool = False) -> Tuple[float, float]:
"""
Returns the average audio volume level measured in dB (range -60 db to 0 db)
If the sample is stereo, you get back a tuple: (left_level, right_level)
If the sample is mono, you still get a tuple but both values will be the same.
This method is probably only useful if processed on very short sample fragments in sequence,
so the db levels could be used to show a level meter for the duration of the sample.
"""
maxvalue = 2**(8*self.__samplewidth-1)
if self.nchannels == 1:
if rms_mode:
peak_left = peak_right = (audioop.rms(self.__frames, self.__samplewidth)+1)/maxvalue
else:
peak_left = peak_right = (audioop.max(self.__frames, self.__samplewidth)+1)/maxvalue
else:
left_frames = audioop.tomono(self.__frames, self.__samplewidth, 1, 0)
right_frames = audioop.tomono(self.__frames, self.__samplewidth, 0, 1)
if rms_mode:
peak_left = (audioop.rms(left_frames, self.__samplewidth)+1)/maxvalue
peak_right = (audioop.rms(right_frames, self.__samplewidth)+1)/maxvalue
else:
peak_left = (audioop.max(left_frames, self.__samplewidth)+1)/maxvalue
peak_right = (audioop.max(right_frames, self.__samplewidth)+1)/maxvalue
# cut off at the bottom at -60 instead of all the way down to -infinity
return max(20.0*math.log(peak_left, 10), -60.0), max(20.0*math.log(peak_right, 10), -60.0)
示例4: echo
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def echo(self, length: float, amount: int, delay: float, decay: float) -> 'Sample':
"""
Adds the given amount of echos into the end of the sample,
using a given length of sample data (from the end of the sample).
The decay is the factor with which each echo is decayed in volume (can be >1 to increase in volume instead).
If you use a very short delay the echos blend into the sound and the effect is more like a reverb.
"""
if self.__locked:
raise RuntimeError("cannot modify a locked sample")
if amount > 0:
length = max(0, self.duration - length)
echo = self.copy()
echo.__frames = self.__frames[self.frame_idx(length):]
echo_amp = decay
for _ in range(amount):
if echo_amp < 1.0/(2**(8*self.__samplewidth-1)):
# avoid computing echos that you can't hear
break
length += delay
echo = echo.copy().amplify(echo_amp)
self.mix_at(length, echo)
echo_amp *= decay
return self
示例5: get_microphone_level
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def get_microphone_level():
"""
source: http://stackoverflow.com/questions/26478315/getting-volume-levels-from-pyaudio-for-use-in-arduino
audioop.max alternative to audioop.rms
"""
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
p = pyaudio.PyAudio()
s = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=chunk)
global levels
while True:
data = s.read(chunk)
mx = audioop.rms(data, 2)
if len(levels) >= 100:
levels = []
levels.append(mx)
示例6: test_max
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def test_max(self):
for w in 1, 2, 4:
self.assertEqual(audioop.max(b'', w), 0)
p = packs[w]
self.assertEqual(audioop.max(p(5), w), 5)
self.assertEqual(audioop.max(p(5, -8, -1), w), 8)
self.assertEqual(audioop.max(p(maxvalues[w]), w), maxvalues[w])
self.assertEqual(audioop.max(p(minvalues[w]), w), -minvalues[w])
self.assertEqual(audioop.max(datas[w], w), -minvalues[w])
示例7: test_max
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def test_max(self):
for w in 1, 2, 3, 4:
self.assertEqual(audioop.max(b'', w), 0)
self.assertEqual(audioop.max(bytearray(), w), 0)
self.assertEqual(audioop.max(memoryview(b''), w), 0)
p = packs[w]
self.assertEqual(audioop.max(p(5), w), 5)
self.assertEqual(audioop.max(p(5, -8, -1), w), 8)
self.assertEqual(audioop.max(p(maxvalues[w]), w), maxvalues[w])
self.assertEqual(audioop.max(p(minvalues[w]), w), -minvalues[w])
self.assertEqual(audioop.max(datas[w], w), -minvalues[w])
示例8: maximum
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def maximum(self) -> int:
return audioop.max(self.__frames, self.samplewidth) # type: ignore
示例9: amplify_max
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def amplify_max(self) -> 'Sample':
"""Amplify the sample to maximum volume without clipping or overflow happening."""
if self.__locked:
raise RuntimeError("cannot modify a locked sample")
max_amp = audioop.max(self.__frames, self.samplewidth)
max_target = 2 ** (8 * self.samplewidth - 1) - 2
if max_amp > 0:
factor = max_target/max_amp
self.__frames = audioop.mul(self.__frames, self.samplewidth, factor)
return self
示例10: modulate_amp
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def modulate_amp(self, modulation_source: Union[Oscillator, Sequence[float], 'Sample', Iterator[float]]) -> 'Sample':
"""
Perform amplitude modulation by another waveform or oscillator.
You can use a Sample (or array of sample values) or an oscillator as modulator.
If you use a Sample (or array), it will be cycled if needed and its maximum amplitude
is scaled to be 1.0, effectively using it as if it was an oscillator.
"""
if self.__locked:
raise RuntimeError("cannot modify a locked sample")
frames = self.get_frame_array()
if isinstance(modulation_source, (Sample, list, array.array)):
# modulator is a waveform, turn that into an 'oscillator' ran
if isinstance(modulation_source, Sample):
modulation_source = modulation_source.get_frame_array()
biggest = max(max(modulation_source), abs(min(modulation_source)))
actual_modulator = (v/biggest for v in itertools.cycle(modulation_source)) # type: ignore
elif isinstance(modulation_source, Oscillator):
actual_modulator = itertools.chain.from_iterable(modulation_source.blocks()) # type: ignore
else:
actual_modulator = iter(modulation_source) # type: ignore
for i in range(len(frames)):
frames[i] = int(frames[i] * next(actual_modulator))
self.__frames = frames.tobytes()
if sys.byteorder == "big":
self.__frames = audioop.byteswap(self.__frames, self.__samplewidth)
return self
示例11: testmax
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import max [as 別名]
def testmax(data):
if verbose:
print 'max'
if audioop.max(data[0], 1) != 2 or \
audioop.max(data[1], 2) != 2 or \
audioop.max(data[2], 4) != 2:
return 0
return 1