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


Python audioop.max方法代码示例

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

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

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

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

示例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) 
开发者ID:atuldo,项目名称:real-time-plot-microphone-kivy,代码行数:25,代码来源:main.py

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

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

示例8: maximum

# 需要导入模块: import audioop [as 别名]
# 或者: from audioop import max [as 别名]
def maximum(self) -> int:
        return audioop.max(self.__frames, self.samplewidth)     # type: ignore 
开发者ID:irmen,项目名称:synthesizer,代码行数:4,代码来源:sample.py

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

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

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


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