Skip to content

Commit

Permalink
Parse window size values like 1k, 2k, 4k, 8k, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
jurihock committed Dec 18, 2023
1 parent 8e55dc6 commit 48042d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
21 changes: 9 additions & 12 deletions cpp/StftPitchShift/ETC.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,20 +86,17 @@ double cent(const std::string& value)

size_t number(const std::string& value)
{
if (value == "1k")
if (value.empty())
{
return 1 * 1024;
return 0;
}
else if (value == "2k")
{
return 2 * 1024;
}
else if (value == "4k")
{
return 4 * 1024;
}
else

if (value.back() == 'k' || value.back() == 'K')
{
return std::stoi(value);
const size_t prefix = value.size() - 1;

return (prefix ? std::stoi(value.substr(0, prefix)) : 0) * 1024;
}

return std::stoi(value);
}
2 changes: 1 addition & 1 deletion python/stftpitchshift/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def main(input, output, pitch, quefrency, timbre, rms, window, overlap, debug):
def semicent(value): return value.startswith('+') or value.startswith('-') or (value.startswith('0') and '.' not in value)
def semitone(value): return pow(2, float(re.match('([+,-]?\\d+){1}([+,-]\\d+){0,1}', value)[1]) / 12)
def cent(value): return pow(2, float(re.match('([+,-]?\\d+){1}([+,-]\\d+){0,1}', value)[2] or 0) / 1200)
def number(value): return 1*1024 if value == '1k' else 2*1024 if value == '2k' else 4*1024 if value == '4k' else int(value)
def number(value): return int(value[:-1]) * 1024 if value.lower().endswith('k') else int(value)

x, samplerate = read(input)

Expand Down

0 comments on commit 48042d7

Please sign in to comment.