Python audioop.max() Examples
The following are 28
code examples of audioop.max().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
audioop
, or try the search function
.
Example #1
Source File: test_audioop.py From ironpython2 with Apache License 2.0 | 6 votes |
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)
Example #2
Source File: test_audioop.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
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)
Example #3
Source File: test_audioop.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: main.py From real-time-plot-microphone-kivy with MIT License | 6 votes |
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)
Example #5
Source File: test_audioop.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #6
Source File: test_audioop.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: test_audioop.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #8
Source File: sample.py From synthesizer with GNU Lesser General Public License v3.0 | 6 votes |
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
Example #9
Source File: sample.py From synthesizer with GNU Lesser General Public License v3.0 | 6 votes |
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)
Example #10
Source File: test_audioop.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #11
Source File: test_audioop.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #12
Source File: test_audioop.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #13
Source File: test_audioop.py From BinderFilter with MIT License | 6 votes |
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)
Example #14
Source File: test_audioop.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #15
Source File: test_audioop.py From oss-ftp with MIT License | 6 votes |
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)
Example #16
Source File: test_audioop.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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])
Example #17
Source File: test_audioop.py From ironpython2 with Apache License 2.0 | 5 votes |
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])
Example #18
Source File: test_audioop.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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])
Example #19
Source File: test_audioop.py From BinderFilter with MIT License | 5 votes |
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])
Example #20
Source File: test_audioop.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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])
Example #21
Source File: test_audioop.py From medicare-demo with Apache License 2.0 | 5 votes |
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
Example #22
Source File: test_audioop.py From oss-ftp with MIT License | 5 votes |
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])
Example #23
Source File: test_audioop.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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])
Example #24
Source File: test_audioop.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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])
Example #25
Source File: sample.py From synthesizer with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #26
Source File: sample.py From synthesizer with GNU Lesser General Public License v3.0 | 5 votes |
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
Example #27
Source File: sample.py From synthesizer with GNU Lesser General Public License v3.0 | 5 votes |
def maximum(self) -> int: return audioop.max(self.__frames, self.samplewidth) # type: ignore
Example #28
Source File: test_audioop.py From ironpython3 with Apache License 2.0 | 5 votes |
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])