當前位置: 首頁>>代碼示例>>Python>>正文


Python audioop.tostereo方法代碼示例

本文整理匯總了Python中audioop.tostereo方法的典型用法代碼示例。如果您正苦於以下問題:Python audioop.tostereo方法的具體用法?Python audioop.tostereo怎麽用?Python audioop.tostereo使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在audioop的用法示例。


在下文中一共展示了audioop.tostereo方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_issue7673

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [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 tostereo [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: normalize

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [as 別名]
def normalize(self) -> 'Sample':
        """
        Normalize the sample, meaning: convert it to the default samplerate, sample width and number of channels.
        When mixing samples, they should all have the same properties, and this method is ideal to make sure of that.
        """
        if self.__locked:
            raise RuntimeError("cannot modify a locked sample")
        self.resample(params.norm_samplerate)
        if self.samplewidth != params.norm_samplewidth:
            # Convert to desired sample size.
            self.__frames = audioop.lin2lin(self.__frames, self.samplewidth, params.norm_samplewidth)
            self.__samplewidth = params.norm_samplewidth
        if params.norm_nchannels not in (1, 2):
            raise ValueError("norm_nchannels has invalid value, can only be 1 or 2")
        if self.nchannels == 1 and params.norm_nchannels == 2:
            # convert to stereo
            self.__frames = audioop.tostereo(self.__frames, self.samplewidth, 1, 1)
            self.__nchannels = 2
        elif self.nchannels == 2 and params.norm_nchannels == 1:
            # convert to mono
            self.__frames = audioop.tomono(self.__frames, self.__samplewidth, 1, 1)
            self.__nchannels = 1
        return self 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:25,代碼來源:sample.py

示例4: stereo

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [as 別名]
def stereo(self, left_factor: float = 1.0, right_factor: float = 1.0) -> 'Sample':
        """
        Turn a mono sample into a stereo one with given factors/amplitudes for left and right channels.
        Note that it is a fast but simplistic conversion; the waveform in both channels is identical
        so you may suffer from phase cancellation when playing the resulting stereo sample.
        If the sample is already stereo, the left/right channel separation is changed instead.
        """
        if self.__locked:
            raise RuntimeError("cannot modify a locked sample")
        if self.__nchannels == 2:
            # first split the left and right channels and then remix them
            right = self.copy().right()
            self.left().amplify(left_factor)
            return self.stereo_mix(right, 'R', right_factor)
        if self.__nchannels == 1:
            self.__frames = audioop.tostereo(self.__frames, self.__samplewidth, left_factor, right_factor)
            self.__nchannels = 2
            return self
        raise ValueError("sample must be mono or stereo") 
開發者ID:irmen,項目名稱:synthesizer,代碼行數:21,代碼來源:sample.py

示例5: test_tostereo

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [as 別名]
def test_tostereo(self):
        for w in 1, 2, 4:
            data1 = datas[w]
            data2 = bytearray(2 * len(data1))
            for k in range(w):
                data2[k::2*w] = data1[k::w]
            self.assertEqual(audioop.tostereo(data1, w, 1, 0), data2)
            self.assertEqual(audioop.tostereo(data1, w, 0, 0), b'\0' * len(data2))
            for k in range(w):
                data2[k+w::2*w] = data1[k::w]
            self.assertEqual(audioop.tostereo(data1, w, 1, 1), data2) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:13,代碼來源:test_audioop.py

示例6: test_tostereo

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [as 別名]
def test_tostereo(self):
        for w in 1, 2, 3, 4:
            data1 = datas[w]
            data2 = bytearray(2 * len(data1))
            for k in range(w):
                data2[k::2*w] = data1[k::w]
            self.assertEqual(audioop.tostereo(data1, w, 1, 0), data2)
            self.assertEqual(audioop.tostereo(data1, w, 0, 0), b'\0' * len(data2))
            for k in range(w):
                data2[k+w::2*w] = data1[k::w]
            self.assertEqual(audioop.tostereo(data1, w, 1, 1), data2)
            self.assertEqual(audioop.tostereo(bytearray(data1), w, 1, 1), data2)
            self.assertEqual(audioop.tostereo(memoryview(data1), w, 1, 1),
                             data2) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:16,代碼來源:test_audioop.py

示例7: testtostereo

# 需要導入模塊: import audioop [as 別名]
# 或者: from audioop import tostereo [as 別名]
def testtostereo(data):
    if verbose:
        print 'tostereo'
    data2 = ''
    for d in data[0]:
        data2 = data2 + d + d
    if audioop.tostereo(data[0], 1, 1, 1) != data2:
        return 0
    return 1 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:11,代碼來源:test_audioop.py


注:本文中的audioop.tostereo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。