當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。