Skip to content

Commit

Permalink
Squeeze empty axes #36
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Jul 16, 2023
1 parent 2abadf7 commit 0ab11c2
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions python/stftpitchshift/stftpitchshift.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(self, framesize, hopsize, samplerate):
def shiftpitch(self, input, factors = 1, quefrency = 0, distortion = 1, normalization = False):
'''
Processes a one-dimensional array of type `numpy.floating` or `numpy.integer`.
Returns the resulting array with the same dtype and shape.
Returns the resulting array with the same dtype and shape, but at least 1D.
:param input: The input signal.
:param factors: The fractional pitch shifting factors.
Expand All @@ -39,16 +39,14 @@ def shiftpitch(self, input, factors = 1, quefrency = 0, distortion = 1, normaliz

input = np.atleast_1d(input)

# remember input type and shape
# to apply to output
dtype = input.dtype
ndim = input.ndim
shape = input.shape
size = input.size

if ndim == 1:
pass
elif np.prod(shape) == size:
input = input.flatten()
else:
input = np.squeeze(input)

if input.ndim != 1:
raise ValueError(f'Invalid input shape {shape}, ' +
f'expected a one-dimensional array!')

Expand Down

0 comments on commit 0ab11c2

Please sign in to comment.