Skip to content
This repository was archived by the owner on Feb 13, 2020. It is now read-only.

Commit 4b4c3c0

Browse files
Chih-Kai YuChih-Kai Yu
Chih-Kai Yu
authored and
Chih-Kai Yu
committed
Rename bitPerSample to bytePerSample
1 parent fc504f7 commit 4b4c3c0

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

util.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,27 @@ def enframe(y, frameSize, overlap):
99
step = frameSize - overlap
1010
frameCount = int(np.floor((len(y)-overlap)/step))
1111
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
1414
out[:, i] = y[startIndex:(startIndex+frameSize), 0]
1515
return out
1616

1717
def audioread(fileName):
1818
#fs, au = scipy.io.wavfile.read(fileName)
1919
audioFile = wave.open(fileName, 'rb')
2020
# 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]
2222
strData = audioFile.readframes(nFrames)
2323
audioFile.close()
24-
if bitPerSample > 4:
24+
if bytePerSample > 4:
2525
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:
3333
au = np.matrix((np.array(np.fromstring(strData, dtype=np.uint8), dtype=np.float64)-128)/(2**(bitPerSample*8-1))).reshape(-1, nChannels)
3434
return (fs, au)
3535

0 commit comments

Comments
 (0)