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


Python audioop.mul方法代码示例

本文整理汇总了Python中audioop.mul方法的典型用法代码示例。如果您正苦于以下问题:Python audioop.mul方法的具体用法?Python audioop.mul怎么用?Python audioop.mul使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在audioop的用法示例。


在下文中一共展示了audioop.mul方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_issue7673

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [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_mul

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def test_mul(self):
        for w in 1, 2, 3, 4:
            self.assertEqual(audioop.mul(b'', w, 2), b'')
            self.assertEqual(audioop.mul(bytearray(), w, 2), b'')
            self.assertEqual(audioop.mul(memoryview(b''), w, 2), b'')
            self.assertEqual(audioop.mul(datas[w], w, 0),
                             b'\0' * len(datas[w]))
            self.assertEqual(audioop.mul(datas[w], w, 1),
                             datas[w])
        self.assertEqual(audioop.mul(datas[1], 1, 2),
                         b'\x00\x24\x7f\x80\x7f\x80\xfe')
        self.assertEqual(audioop.mul(datas[2], 2, 2),
                packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2))
        self.assertEqual(audioop.mul(datas[3], 3, 2),
                packs[3](0, 0x2468ac, 0x7fffff, -0x800000,
                         0x7fffff, -0x800000, -2))
        self.assertEqual(audioop.mul(datas[4], 4, 2),
                packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000,
                         0x7fffffff, -0x80000000, -2)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:21,代码来源:test_audioop.py

示例3: test_string

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [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: read

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def read(self):
        ret = self.original.read()
        return audioop.mul(ret, 2, min(self._volume, 2.0)) 
开发者ID:Rapptz,项目名称:discord.py,代码行数:5,代码来源:player.py

示例5: test_mul

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def test_mul(self):
        for w in 1, 2, 4:
            self.assertEqual(audioop.mul(b'', w, 2), b'')
            self.assertEqual(audioop.mul(datas[w], w, 0),
                             b'\0' * len(datas[w]))
            self.assertEqual(audioop.mul(datas[w], w, 1),
                             datas[w])
        self.assertEqual(audioop.mul(datas[1], 1, 2),
                         b'\x00\x24\x7f\x80\x7f\x80\xfe')
        self.assertEqual(audioop.mul(datas[2], 2, 2),
                packs[2](0, 0x2468, 0x7fff, -0x8000, 0x7fff, -0x8000, -2))
        self.assertEqual(audioop.mul(datas[4], 4, 2),
                packs[4](0, 0x2468acf0, 0x7fffffff, -0x80000000,
                         0x7fffffff, -0x80000000, -2)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:16,代码来源:test_audioop.py

示例6: run

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def run(self):
        self.loops = 0
        self._start = time.time()
        while not self._end.is_set():
            # are we paused?
            if not self._resumed.is_set():
                # wait until we aren't
                self._resumed.wait()

            if not self._connected.is_set():
                self.stop()
                break

            self.loops += 1
            data = self.data.pop(0)

            if self._volume != 1.0:
                data = audioop.mul(data, 2, min(self._volume, 2.0))

            """if len(data) != self.frame_size:
                self.stop()
                break"""

            self.player(data)
            next_time = self._start + self.delay * self.loops
            delay = max(0, self.delay + (next_time - time.time()))
            time.sleep(delay) 
开发者ID:tekulvw,项目名称:Squid-Plugins,代码行数:29,代码来源:encoder.py

示例7: get_32bit_frames

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def get_32bit_frames(self, scale_amplitude: bool = True) -> bytes:
        """Returns the raw sample frames scaled to 32 bits. See make_32bit method for more info."""
        if self.samplewidth == 4:
            return self.__frames
        frames = audioop.lin2lin(self.__frames, self.samplewidth, 4)   # type: bytes
        if not scale_amplitude:
            # we need to scale back the sample amplitude to fit back into 24/16/8 bit range
            factor = 1.0/2**(8*abs(self.samplewidth-4))
            frames = audioop.mul(frames, 4, factor)
        return frames 
开发者ID:irmen,项目名称:synthesizer,代码行数:12,代码来源:sample.py

示例8: amplify_max

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [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 
开发者ID:irmen,项目名称:synthesizer,代码行数:12,代码来源:sample.py

示例9: amplify

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def amplify(self, factor: float) -> 'Sample':
        """Amplifies (multiplies) the sample by the given factor. May cause clipping/overflow if factor is too large."""
        if self.__locked:
            raise RuntimeError("cannot modify a locked sample")
        self.__frames = audioop.mul(self.__frames, self.samplewidth, factor)
        return self 
开发者ID:irmen,项目名称:synthesizer,代码行数:8,代码来源:sample.py

示例10: _frame_vol

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def _frame_vol(self, frame, mult, *, maxv=2, use_audioop=True):
        if use_audioop:
            return audioop.mul(frame, 2, min(mult, maxv))
        else:
            # ffmpeg returns s16le pcm frames.
            frame_array = array('h', frame)

            for i in range(len(frame_array)):
                frame_array[i] = int(frame_array[i] * min(mult, min(1, maxv)))

            return frame_array.tobytes() 
开发者ID:helionmusic,项目名称:rhinobot_heroku,代码行数:13,代码来源:player.py

示例11: testmul

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def testmul(data):
    if verbose:
        print 'mul'
    data2 = []
    for d in data:
        str = ''
        for s in d:
            str = str + chr(ord(s)*2)
        data2.append(str)
    if audioop.mul(data[0], 1, 2) != data2[0] or \
              audioop.mul(data[1],2, 2) != data2[1] or \
              audioop.mul(data[2], 4, 2) != data2[2]:
        return 0
    return 1 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:16,代码来源:test_audioop.py

示例12: play_audio

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import mul [as 别名]
def play_audio():
    global_settings.audio_dni = (True, settings.sound_board_metadata[C_PLUGIN_INFO][P_PLUGIN_NAME])
    global_settings.mumble_inst.sound_output.clear_buffer()

    uri = f"file:///{dir_utils.get_perm_med_dir()}/sound_board/{settings.current_track}.wav"
    command = settings.sound_board_metadata[C_PLUGIN_SETTINGS][P_VLC_DIR]

    if global_settings.audio_inst is not None:
        global_settings.audio_inst.terminate()
        global_settings.audio_inst.kill()
        global_settings.audio_inst = None

    settings.is_playing = True
    if global_settings.audio_inst is None:
        use_stereo = global_settings.cfg.getboolean(C_MAIN_SETTINGS, P_AUD_STEREO)
        if use_stereo:
            global_settings.audio_inst = sp.Popen(
                [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}',
                                  '--one-instance', f'{"--no-repeat" if settings.loop_clip is False else "--repeat"}',
                                  f'--start-time={settings.skip_to if settings.loop_clip is False else 0}',
                                  '--sout',
                                  '#transcode{acodec=s16le, channels=2, samplerate=48000, '
                                  'ab=128, threads=8}:std{access=file, mux=wav, dst=-}',
                                  'vlc://quit'],
                stdout=sp.PIPE, bufsize=1024)
            settings.skip_to = 0
        else:
            global_settings.audio_inst = sp.Popen(
            [command, uri] + ['-I', 'dummy', f'{"--quiet" if settings.sound_board_metadata.getboolean(C_PLUGIN_SETTINGS, P_VLC_QUIET, fallback=True) else ""}',
                              '--one-instance', f'{"--no-repeat" if settings.loop_clip is False else "--repeat"}',
                              f'--start-time={settings.skip_to if settings.loop_clip is False else 0}',
                              '--sout',
                              '#transcode{acodec=s16le, channels=2, samplerate=24000, '
                              'ab=128, threads=8}:std{access=file, mux=wav, dst=-}',
                              'vlc://quit'],
            stdout=sp.PIPE, bufsize=1024)
            settings.skip_to = 0

    runtime_utils.unmute()
    while not settings.exit_flag and global_settings.audio_inst and settings.is_playing:
        while global_settings.mumble_inst.sound_output.get_buffer_size() > 0.5 and not settings.exit_flag:
            time.sleep(0.01)
        if global_settings.audio_inst:
            raw_music = global_settings.audio_inst.stdout.read(1024)
            if raw_music and global_settings.audio_inst:
                global_settings.mumble_inst.sound_output.add_sound(audioop.mul(raw_music, 2, settings.volume))
            else:
                stop_audio()
                settings.is_playing = False
                return
        else:
            return
    return 
开发者ID:DuckBoss,项目名称:JJMumbleBot,代码行数:55,代码来源:sound_board_utility.py


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