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

refactor cut_pcm

parent affc3b90
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -436,7 +436,7 @@ def pre_proc_input(testv_file, fs):
        num_channel = "16"
    cut_file = testv_file.replace(".wav", num_channel + "chn_" + cut_gain + ".wav")
    cut_samples(
        testv_file, cut_file, num_channel, fs + "000", cut_from, cut_len, cut_gain
        testv_file, cut_file, num_channel, cut_from, cut_len, cut_gain
    )
    return cut_file

+1 −1
Original line number Diff line number Diff line
@@ -551,10 +551,10 @@ def sba_enc(
                input_path,
                cut_file,
                num_channels,
                sampling_rate + "000",
                cut_from,
                cut_len,
                cut_gain,
                sample_rate=sampling_rate + "000",
            )
        input_path = cut_file

+7 −8
Original line number Diff line number Diff line
@@ -58,14 +58,13 @@ def collect_files():

def create_short_testvectors():
    for f in collect_files():
        for fs in ['48', '32', '16']:
        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, fs + "000", CUT_FROM, CUT_LEN, g)
            cut_samples(f, out_file, NUM_CHANNELS, CUT_FROM, CUT_LEN, g)


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


def cut_samples(in_file, out_file, num_channels, sample_rate, start, duration, gain="1.0"):
def cut_samples(in_file, out_file, num_channels, start, duration, gain="1.0", sample_rate=None):
    """
    Function to cut samples from an audio file (wav or pcm)
    """
@@ -70,6 +70,12 @@ def cut_samples(in_file, out_file, num_channels, sample_rate, start, duration, g
    if sys.version_info[0] < 3 or sys.version_info[1] < 7:
        sys.exit("This script is written for Python >= 3.7. Found: " + 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)
+1 −1
Original line number Diff line number Diff line
@@ -433,7 +433,7 @@ def pre_proc_input(testv_file, fs):
        num_channel = "16"
    cut_file = testv_file.replace(".wav", num_channel + "chn_" + cut_gain + ".wav")
    cut_samples(
        testv_file, cut_file, num_channel, fs + "000", cut_from, cut_len, cut_gain
        testv_file, cut_file, num_channel, cut_from, cut_len, cut_gain
    )
    return cut_file