@@ -9,27 +9,27 @@ def enframe(y, frameSize, overlap):
9
9
step = frameSize - overlap
10
10
frameCount = int (np .floor ((len (y )- overlap )/ step ))
11
11
out = np .matrix (np .zeros ((frameSize , frameCount ), dtype = np .float64 ))
12
- for i in range (frameCount ):
13
- startIndex = i * step + 1
12
+ for i in range (0 , frameCount ):
13
+ startIndex = i * step
14
14
out [:, i ] = y [startIndex :(startIndex + frameSize ), 0 ]
15
15
return out
16
16
17
17
def audioread (fileName ):
18
18
#fs, au = scipy.io.wavfile.read(fileName)
19
19
audioFile = wave .open (fileName , 'rb' )
20
20
# get file information and read sample data as string bytes
21
- nChannels , bitPerSample , fs , nFrames = audioFile .getparams ()[:4 ]
21
+ nChannels , bytePerSample , fs , nFrames = audioFile .getparams ()[:4 ]
22
22
strData = audioFile .readframes (nFrames )
23
23
audioFile .close ()
24
- if bitPerSample > 4 :
24
+ if bytePerSample > 4 :
25
25
raise ValueError ('Bit per sample can not be greater than 4.' )
26
- elif bitPerSample == 4 :
27
- au = np .matrix (np .fromstring (strData , dtype = np .int32 )/ (2 ** (bitPerSample * 8 - 1 )), dtype = np .float64 ).reshape (- 1 , nChannels )
28
- elif bitPerSample == 3 :
29
- au = np .matrix (np .array ([int .from_bytes (strData [i :i + bitPerSample ], byteorder = 'little' , signed = True ) for i in range (0 , len (strData ), bitPerSample )], dtype = np .float64 )/ (2 ** (bitPerSample * 8 - 1 ))).reshape (- 1 , nChannels )
30
- elif bitPerSample == 2 :
31
- au = np .matrix (np .fromstring (strData , dtype = np .int16 )/ (2 ** (bitPerSample * 8 - 1 )), dtype = np .float64 ).reshape (- 1 , nChannels )
32
- elif bitPerSample == 1 :
26
+ elif bytePerSample == 4 :
27
+ au = np .matrix (np .fromstring (strData , dtype = np .int32 )/ (2 ** (bytePerSample * 8 - 1 )), dtype = np .float64 ).reshape (- 1 , nChannels )
28
+ elif bytePerSample == 3 :
29
+ au = np .matrix (np .array ([int .from_bytes (strData [i :i + bytePerSample ], byteorder = 'little' , signed = True ) for i in range (0 , len (strData ), bitPerSample )], dtype = np .float64 )/ (2 ** (bitPerSample * 8 - 1 ))).reshape (- 1 , nChannels )
30
+ elif bytePerSample == 2 :
31
+ au = np .matrix (np .fromstring (strData , dtype = np .int16 )/ (2 ** (bytePerSample * 8 - 1 )), dtype = np .float64 ).reshape (- 1 , nChannels )
32
+ elif bytePerSample == 1 :
33
33
au = np .matrix ((np .array (np .fromstring (strData , dtype = np .uint8 ), dtype = np .float64 )- 128 )/ (2 ** (bitPerSample * 8 - 1 ))).reshape (- 1 , nChannels )
34
34
return (fs , au )
35
35
0 commit comments