本文整理匯總了Python中audioop.add方法的典型用法代碼示例。如果您正苦於以下問題:Python audioop.add方法的具體用法?Python audioop.add怎麽用?Python audioop.add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類audioop
的用法示例。
在下文中一共展示了audioop.add方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_issue7673
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [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_add
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def test_add(self):
for w in 1, 2, 3, 4:
self.assertEqual(audioop.add(b'', b'', w), b'')
self.assertEqual(audioop.add(bytearray(), bytearray(), w), b'')
self.assertEqual(audioop.add(memoryview(b''), memoryview(b''), w), b'')
self.assertEqual(audioop.add(datas[w], b'\0' * len(datas[w]), w),
datas[w])
self.assertEqual(audioop.add(datas[1], datas[1], 1),
b'\x00\x24\x7f\x80\x7f\x80\xfe')
self.assertEqual(audioop.add(datas[2], datas[2], 2),
packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2))
self.assertEqual(audioop.add(datas[3], datas[3], 3),
packs[3](0, 0x2468ac, 0x7fffff, -0x800000,
0x7fffff, -0x800000, -2))
self.assertEqual(audioop.add(datas[4], datas[4], 4),
packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000,
0x7fffffff, -0x80000000, -2))
示例3: test_string
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [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)
示例4: mix
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def mix(self, other: 'Sample', other_seconds: Optional[float] = None, pad_shortest: bool = True) -> 'Sample':
"""
Mix another sample into the current sample.
You can limit the length taken from the other sample.
When pad_shortest is False, no sample length adjustment is done.
"""
if self.__locked:
raise RuntimeError("cannot modify a locked sample")
assert self.samplewidth == other.samplewidth
assert self.samplerate == other.samplerate
assert self.nchannels == other.nchannels
frames1 = self.__frames
if other_seconds:
frames2 = other.__frames[:other.frame_idx(other_seconds)]
else:
frames2 = other.__frames
if pad_shortest:
if len(frames1) < len(frames2):
frames1 += b"\0"*(len(frames2)-len(frames1))
elif len(frames2) < len(frames1):
frames2 += b"\0"*(len(frames1)-len(frames2))
self.__frames = audioop.add(frames1, frames2, self.samplewidth)
return self
示例5: mix_at
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def mix_at(self, seconds: float, other: 'Sample', other_seconds: Optional[float] = None) -> 'Sample':
"""
Mix another sample into the current sample at a specific time point.
You can limit the length taken from the other sample.
"""
if seconds == 0.0:
return self.mix(other, other_seconds)
if self.__locked:
raise RuntimeError("cannot modify a locked sample")
assert self.samplewidth == other.samplewidth
assert self.samplerate == other.samplerate
assert self.nchannels == other.nchannels
start_frame_idx = self.frame_idx(seconds)
if other_seconds:
other_frames = other.__frames[:other.frame_idx(other_seconds)]
else:
other_frames = other.__frames
# Mix the frames. Unfortunately audioop requires splitting and copying the sample data, which is slow.
pre, to_mix, post = self._mix_split_frames(len(other_frames), start_frame_idx)
self.__frames = b"" # allow for garbage collection
mixed = audioop.add(to_mix, other_frames, self.samplewidth)
del to_mix # more garbage collection
self.__frames = self._mix_join_frames(pre, mixed, post)
return self
示例6: test_add
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def test_add(self):
for w in 1, 2, 4:
self.assertEqual(audioop.add(b'', b'', w), b'')
self.assertEqual(audioop.add(datas[w], b'\0' * len(datas[w]), w),
datas[w])
self.assertEqual(audioop.add(datas[1], datas[1], 1),
b'\x00\x24\x7f\x80\x7f\x80\xfe')
self.assertEqual(audioop.add(datas[2], datas[2], 2),
packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2))
self.assertEqual(audioop.add(datas[4], datas[4], 4),
packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000,
0x7fffffff, -0x80000000, -2))
示例7: writeframes
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def writeframes(self, data):
import time
from Carbon.Sound import bufferCmd, callBackCmd, extSH
import struct
import MacOS
if not self._chan:
from Carbon import Snd
self._chan = Snd.SndNewChannel(5, 0, self._callback)
nframes = len(data) / self._nchannels / self._sampwidth
if len(data) != nframes * self._nchannels * self._sampwidth:
raise error, 'data is not a whole number of frames'
while self._gc and \
self.getfilled() + nframes > \
self._qsize / self._nchannels / self._sampwidth:
time.sleep(0.1)
if self._sampwidth == 1:
import audioop
data = audioop.add(data, '\x80'*len(data), 1)
h1 = struct.pack('llHhllbbl',
id(data)+MacOS.string_id_to_buffer,
self._nchannels,
self._outrate, 0,
0,
0,
extSH,
60,
nframes)
h2 = 22*'\0'
h3 = struct.pack('hhlll',
self._sampwidth*8,
0,
0,
0,
0)
header = h1+h2+h3
self._gc.append((header, data))
self._chan.SndDoCommand((bufferCmd, 0, header), 0)
self._chan.SndDoCommand((callBackCmd, 0, 0), 0)
示例8: chunks
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def chunks(self) -> Generator[memoryview, None, None]:
silence = b"\0" * self.chunksize
while not self._closed:
chunks_to_mix = []
active_samples = self.determine_samples_to_mix()
for i, (name, s) in active_samples:
try:
chunk = next(s)
if len(chunk) > self.chunksize:
raise ValueError("chunk from sample is larger than chunksize from mixer (" +
str(len(chunk)) + " vs " + str(self.chunksize) + ")")
if len(chunk) < self.chunksize:
# pad the chunk with some silence
chunk = memoryview(chunk.tobytes() + silence[len(chunk):])
chunks_to_mix.append(chunk)
except StopIteration:
self.remove_sample(i, True)
chunks_to_mix = chunks_to_mix or [silence] # type: ignore
assert all(len(c) == self.chunksize for c in chunks_to_mix)
mixed = chunks_to_mix[0]
if len(chunks_to_mix) > 1:
for to_mix in chunks_to_mix[1:]:
mixed = audioop.add(mixed, to_mix, params.norm_nchannels)
mixed = memoryview(mixed)
self.chunks_mixed += 1
yield mixed
示例9: testadd
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def testadd(data):
if verbose:
print 'add'
data2 = []
for d in data:
str = ''
for s in d:
str = str + chr(ord(s)*2)
data2.append(str)
if audioop.add(data[0], data[0], 1) != data2[0] or \
audioop.add(data[1], data[1], 2) != data2[1] or \
audioop.add(data[2], data[2], 4) != data2[2]:
return 0
return 1
示例10: testall
# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import add [as 別名]
def testall():
data = [gendata1(), gendata2(), gendata4()]
names = dir(audioop)
# We know there is a routine 'add'
routines = []
for n in names:
if type(eval('audioop.'+n)) == type(audioop.add):
routines.append(n)
for n in routines:
testone(n, data)