当前位置: 首页>>代码示例>>Python>>正文


Python audioop.add方法代码示例

本文整理汇总了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) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_audioop.py

示例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)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:19,代码来源:test_audioop.py

示例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) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:test_audioop.py

示例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 
开发者ID:irmen,项目名称:synthesizer,代码行数:25,代码来源:sample.py

示例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 
开发者ID:irmen,项目名称:synthesizer,代码行数:26,代码来源:sample.py

示例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)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:14,代码来源:test_audioop.py

示例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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:40,代码来源:Audio_mac.py

示例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 
开发者ID:irmen,项目名称:synthesizer,代码行数:28,代码来源:streaming.py

示例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 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:16,代码来源:test_audioop.py

示例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) 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:12,代码来源:test_audioop.py


注:本文中的audioop.add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。