Commit b5e1d22e authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

update spectral testv for smoketest

parent b4ce428a
Loading
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3
from pathlib import Path
from scipy.io.wavfile import read, write
import numpy as np

MAX_NUM_CH = 20  # number of channel indices in file
MIN_DURATION_MS = 1200  # minimum duration needed for all indices at 16kHz
TESTV_DIR = Path(__file__).parent.joinpath("testv")


def create_vector(fs: int, num_ch: int):
    in_file = TESTV_DIR / f"spectral_{fs}.wav"

    # requires spectral_{16,32,48}.wav
    if not in_file.exists():
        raise FileNotFoundError(f"Source file {in_file} not found!")
    # validate num_ch
    if num_ch > MAX_NUM_CH or num_ch < 1:
        raise ValueError(
            f"Requested channel count of {num_ch} channels is invalid. Must be between 1 and {MAX_NUM_CH}!"
        )

    _, data = read(in_file)

    # split source file into parts
    part_len = data.shape[0] // MAX_NUM_CH
    parts = data.reshape(MAX_NUM_CH, part_len).T

    duration = fs * MIN_DURATION_MS
    out = np.zeros([duration, num_ch], dtype=np.int16)

    # populate output vector, loop over the channel indices
    # until the duration is reached
    for i in range(duration // part_len):
        for ch in range(num_ch):
            if i % num_ch == ch:
                out[i * part_len : (i + 1) * part_len, ch] = parts[:, ch]

    write(TESTV_DIR / f"spectral_test_{num_ch}ch_{fs}kHz.wav", fs * 1000, out)


def main():
    for fs in [16, 32, 48]:
        for ch in range(1, 21):
            create_vector(fs, ch)


if __name__ == "__main__":
    main()
+130 B

File added.

No diff preview for this file type.

+130 B

File added.

No diff preview for this file type.

+130 B

File added.

No diff preview for this file type.

Loading