Skip to content

Commit 666f12e

Browse files
committed
fix hptsm for multichannel audio
1 parent 680368a commit 666f12e

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

pytsmod/hptsm.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from librosa.effects import hpss
2+
import numpy as np
23
from .pvtsm import phase_vocoder
34
from .olatsm import ola
5+
from .utils import _validate_audio
46

57

68
def hptsm(x, s, hp_kernel_size=31, hp_power=2.0, hp_mask=False, hp_margin=1.0,
@@ -32,9 +34,16 @@ def hptsm(x, s, hp_kernel_size=31, hp_power=2.0, hp_mask=False, hp_margin=1.0,
3234
y : numpy.ndarray [shape=(channel, num_samples) or (num_samples)]
3335
the modified output audio sequence.
3436
"""
35-
36-
x_harm, x_perc = hpss(x, kernel_size=hp_kernel_size, power=hp_power,
37-
mask=hp_mask, margin=hp_margin)
37+
x = _validate_audio(x)
38+
x_harm = np.zeros(x.shape)
39+
x_perc = np.zeros(x.shape)
40+
41+
for c, x_chan in enumerate(x):
42+
x_harm_chan, x_perc_chan = hpss(x_chan, kernel_size=hp_kernel_size,
43+
power=hp_power, mask=hp_mask,
44+
margin=hp_margin)
45+
x_harm[c, :] = x_harm_chan
46+
x_perc[c, :] = x_perc_chan
3847

3948
y_harm = phase_vocoder(x_harm, s, win_type=pv_win_type,
4049
win_size=pv_win_size, syn_hop_size=pv_syn_hop_size,

0 commit comments

Comments
 (0)