-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathpitcher.py
More file actions
25 lines (14 loc) · 766 Bytes
/
pitcher.py
File metadata and controls
25 lines (14 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from stftpitchshift.resampler import linear as resample
import numpy as np
def shiftpitch(frames, factors, samplerate):
for i in range(len(frames)):
magnitudes = np.real(frames[i])
frequencies = np.imag(frames[i])
magnitudes = np.vstack([resample(magnitudes, factor) for factor in factors])
frequencies = np.vstack([resample(frequencies, factor) * factor for factor in factors])
magnitudes[(frequencies <= 0) | (frequencies >= samplerate / 2)] = 0
mask = np.argmax(magnitudes, axis=0)
magnitudes = np.take_along_axis(magnitudes, mask[None,:], axis=0)
frequencies = np.take_along_axis(frequencies, mask[None,:], axis=0)
frames[i] = magnitudes + 1j * frequencies
return frames