Commit 76022069 authored by Jan Kiene's avatar Jan Kiene
Browse files

revert reverts from bad merge

parent 9a1a4b1c
Loading
Loading
Loading
Loading
Loading
+15 −18
Original line number Diff line number Diff line
@@ -72,24 +72,21 @@ def collect_files(file_ids):
    return files


def create_short_testvectors():
    for fs in ["48", "32", "16"]:
        in_file = f"{TEST_VECTOR_DIR}/stvFOA{fs}c.wav"
        cut_gain = "1.0"
        cut_file = f"{TEST_VECTOR_DIR}/stvFOA{fs}c_cut.wav"
        cut_samples(
            in_file, cut_file, NUM_CHANNELS, fs + "000", CUT_FROM, CUT_LEN, cut_gain
        )
        cut_gain = "16.0"
        cut_file = f"{TEST_VECTOR_DIR}/stvFOA{fs}c_cut_{cut_gain}.wav"
        cut_samples(
            in_file, cut_file, NUM_CHANNELS, fs + "000", CUT_FROM, CUT_LEN, cut_gain
        )
        cut_gain = ".004"
        cut_file = f"{TEST_VECTOR_DIR}/stvFOA{fs}c_cut_{cut_gain}.wav"
        cut_samples(
            in_file, cut_file, NUM_CHANNELS, fs + "000", CUT_FROM, CUT_LEN, cut_gain
        )
def create_short_testvectors(which="foa", cut_len=5.0):
    file_ids = []
    if which == "all":
        file_ids = FILE_IDS
    elif which == "foa":
        file_ids = FILE_IDS[:1]

    for f in collect_files(file_ids):
        for g in GAINS:
            suffix = "_cut"
            if g != "1.0":
                suffix += f"_{g}"

            out_file = f.parent.joinpath(f.stem + suffix + f.suffix)
            cut_samples(f, out_file, NUM_CHANNELS, CUT_FROM, f"{cut_len}", g)


if __name__ == "__main__":
+14 −1
Original line number Diff line number Diff line
@@ -61,7 +61,14 @@ def usage():


def cut_samples(
    in_file, out_file, num_channels, sample_rate, start, duration, gain="1.0"
    in_file,
    out_file,
    num_channels,
    sample_rate,
    start,
    duration,
    gain="1.0",
    sample_rate=None,
):
    """
    Function to cut samples from an audio file (wav or pcm)
@@ -74,6 +81,12 @@ def cut_samples(
            + platform.python_version()
        )

    if sample_rate is None and not str(in_file).endswith(".wav"):
        raise ValueError(f"For non-wav files, samplerate must be explicitly given")
    elif sample_rate is None:
        # set to default of pyaudio3dtools.audiofile.readfile -> for wav files it will be ignored anyway
        sample_rate = 48000

    # all input parameters are strings - convert some
    fs = int(sample_rate)
    start_sec = float(start)