diff --git a/cpp/StftPitchShift/ETC.h b/cpp/StftPitchShift/ETC.h index ae6a0d3..02a65ad 100755 --- a/cpp/StftPitchShift/ETC.h +++ b/cpp/StftPitchShift/ETC.h @@ -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); } diff --git a/python/stftpitchshift/main.py b/python/stftpitchshift/main.py index b56defc..42c6064 100644 --- a/python/stftpitchshift/main.py +++ b/python/stftpitchshift/main.py @@ -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)