From cfd060fb145fc1ad9219488808d0e697907c40e1 Mon Sep 17 00:00:00 2001 From: Erik Norvell Date: Tue, 10 Dec 2024 09:03:40 +0100 Subject: [PATCH] Add scripts/create_mode_force.py for mode synch debugging --- scripts/create_mode_force.py | 65 ++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 scripts/create_mode_force.py diff --git a/scripts/create_mode_force.py b/scripts/create_mode_force.py new file mode 100644 index 0000000000..39ec6773ea --- /dev/null +++ b/scripts/create_mode_force.py @@ -0,0 +1,65 @@ +#!/usr/bin/env python3 + +""" + (C) 2022-2024 IVAS codec Public Collaboration with portions copyright Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository. All Rights Reserved. + + This software is protected by copyright law and by international treaties. + The IVAS codec Public Collaboration consisting of Dolby International AB, Ericsson AB, + Fraunhofer-Gesellschaft zur Foerderung der angewandten Forschung e.V., Huawei Technologies Co. LTD., + Koninklijke Philips N.V., Nippon Telegraph and Telephone Corporation, Nokia Technologies Oy, Orange, + Panasonic Holdings Corporation, Qualcomm Technologies, Inc., VoiceAge Corporation, and other + contributors to this repository retain full ownership rights in their respective contributions in + the software. This notice grants no license of any kind, including but not limited to patent + license, nor is any license granted by implication, estoppel or otherwise. + + Contributors are required to enter into the IVAS codec Public Collaboration agreement before making + contributions. + + This software is provided "AS IS", without any express or implied warranties. The software is in the + development stage. It is intended exclusively for experts who have experience with such software and + solely for the purpose of inspection. All implied warranties of non-infringement, merchantability + and fitness for a particular purpose are hereby disclaimed and excluded. + + Any dispute, controversy or claim arising under or in relation to providing this software shall be + submitted to and settled by the final, binding jurisdiction of the courts of Munich, Germany in + accordance with the laws of the Federal Republic of Germany excluding its conflict of law rules and + the United Nations Convention on Contracts on the International Sales of Goods. +""" + +import argparse +import struct + +MODES = { + 0: "1 ACELP\n", + 1: "1 TCX\n", + 3: "1 HQ\n", +} +SR = [16, 32, 48] + + +def create_mode_force(input_file, sampling_rate_khz, output_file): + with open(input_file, "rb") as f_in, open(output_file, "w") as f_out: + file = f_in.read() + I = struct.unpack("h" * ((len(file)) // 2), file) + step = sampling_rate_khz * 20 + for i in I[0::step]: + f_out.write(MODES[i]) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("input_file", help="Input file name", type=str) + parser.add_argument( + "sampling_rate_khz", help="Sampling rate in kHz (16, 32 or 48)", type=int + ) + parser.add_argument("output_file", help="Input file name", type=str) + args = parser.parse_args() + + if not args.sampling_rate_khz in SR: + raise ValueError("Invalid sampling rate. Please use 16, 32 or 48") + + create_mode_force(args.input_file, args.sampling_rate_khz, args.output_file) -- GitLab