Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/media/channels.pyx
4069 views
1
def _separate_channels(_data, _width, _nchannels):
2
"""
3
Separates the channels. This is an internal helper method for
4
precomputing some data while initializing the wav object.
5
"""
6
cdef int nchannels = _nchannels
7
cdef int width = _width
8
cdef char* data = _data
9
cdef int n
10
cdef short int x
11
12
cdef int l = len(_data) / (width)
13
14
channel_data = [[] for i in xrange(nchannels)]
15
if width == 1:
16
# handle the one byte case
17
18
for n from 0 <= n < l:
19
channel_data[n % nchannels].append(ord(data[n])-127)
20
21
elif width == 2:
22
a = 32768
23
for n from 0 <= n < l:
24
# compute the value as an integer
25
x = <int> (data[2*n]) + 256 * <int>(data[2*n + 1])
26
#x -= 65536*(x > a)
27
channel_data[n % nchannels].append(x)
28
else:
29
raise NotImplementedError, "greater than 16-bit wavs not supported"
30
31
return channel_data
32
33