1
0

b/c...py: skip_first: support fractional seconds

This commit is contained in:
Intel A80486DX2-66 2024-09-23 02:25:24 +03:00
parent 376c7be221
commit 259107b2b6
Signed by: 80486DX2-66
GPG Key ID: 83631EF27054609B

View File

@ -54,6 +54,18 @@ DEFAULT_PARAMETERS = {
stdout_atty = hasattr(stdout, "isatty") and stdout.isatty()
def is_decimal_number(s: str) -> bool:
if s.count('.') > 1: # More than one decimal point
return False
if s.startswith(('+', '-')):
s = s[1:] # Remove the sign for further checks
if s.replace('.', '', 1).isdigit():
return True
return False
def fetch(name: str):
if from_env := environ.get(name):
return from_env
@ -328,17 +340,22 @@ if __name__ == "__main__":
# - Parse the '--skip-first' argument
if not args.skip_first is None:
encountered_point = False
encountered_s = False
for character in args.skip_first:
if character.isdigit() or character == "s" and not encountered_s:
if character == "s":
if character.isdigit() or character == "." and \
not encountered_point or character == "s" and not encountered_s:
if character == ".":
encountered_point = True
elif character == "s":
encountered_s = True
else:
print(f"Invalid --skip-first format: `{args.skip_first}`")
exit(1)
raise SystemExit( "Invalid --skip-first format: "
f"`{args.skip_first}`")
skip_first = \
[int(x) if x.isdigit() else 0 for x in args.skip_first.split("s")]
[Decimal(x) if is_decimal_number(x) else 0 for x in \
args.skip_first.split("s")]
skip_first_samples = 0
if len(skip_first) == 1:
@ -348,6 +365,9 @@ if __name__ == "__main__":
else:
skip_first_samples = 0
# round the number of skipped first samples
skip_first_samples = ceil(skip_first_samples)
length_formula = lambda channels, samples, n: channels * (samples + n)
gen_length = length_formula(args.channels, samples, 0)
loop_end = length_formula(args.channels, samples, skip_first_samples)