Skip to content

Commit

Permalink
Forward stft options to shiftpitch
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Mar 25, 2024
1 parent a7a638e commit 5ad9ad0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ addopts = ["--capture=tee-sys"]

[tool.pylint]
max-args = 10
max-attributes = 10
max-locals = 42
max-line-length = 200
exclude-protected = ["_load_audio"] # demucs.api.Separator._load_audio
Expand Down
14 changes: 13 additions & 1 deletion src/remucs/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,20 @@ class RemucsOptions:
bala: List[float] = field(default_factory=lambda: [0, 0, 0, 0])
gain: List[float] = field(default_factory=lambda: [1, 1, 1, 1])

pitch: float = 1
pitch: float = 1
quefrency: float = 1e-3

order: int = 12
overlap: int = 4

@property
def model(self):
return 'htdemucs_ft' if self.fine else 'htdemucs'

@property
def framesize(self):
return 1 << self.order

@property
def hopsize(self):
return self.framesize // self.overlap
18 changes: 10 additions & 8 deletions src/remucs/synthesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,12 @@ def stereo_gain_weights(gain):

return numpy.clip(y[..., None, None], -10, +10)

def shiftpitch(x, *, samplerate, factor, quefrency):
def shiftpitch(x, *, samplerate, factor, quefrency, framesize, hopsize, normalize=True):

x = numpy.atleast_2d(x)
y = numpy.zeros_like(x)
assert len(x.shape) == 2 and x.shape[-1] == 2

framesize = 4 * 1024
overlap = 4
hopsize = framesize // overlap
normalize = True

pitchshifter = stftpitchshift.StftPitchShift(
framesize=framesize,
hopsize=hopsize,
Expand Down Expand Up @@ -91,10 +86,17 @@ def synthesize(file, data, opts):

stems = [STEMS.index(stem) for stem in ['bass', 'other', 'vocals']]
factors = [pitch] * len(stems)
quefrencies = [0, 0, 1e-3]
quefrencies = [0, 0, opts.quefrency]
framesize = opts.framesize
hopsize = opts.hopsize

for i, stem in enumerate(stems):
x[stem] = shiftpitch(x[stem], samplerate=sr, factor=factors[i], quefrency=quefrencies[i])
x[stem] = shiftpitch(x[stem],
samplerate=sr,
factor=factors[i],
quefrency=quefrencies[i],
framesize=framesize,
hopsize=hopsize)

if not opts.quiet:
if mono:
Expand Down

0 comments on commit 5ad9ad0

Please sign in to comment.