Commit 7de4ac6b authored by multrus's avatar multrus
Browse files

Merge branch 'script_20ms_alignment' into 'main'

add scripts to pad files to 20ms blocks

See merge request !106
parents 474c0b65 d1a1924c
Loading
Loading
Loading
Loading

other/pad_file_20ms.sh

0 → 100755
+76 −0
Original line number Diff line number Diff line
#!/bin/bash


#   (C) 2022-2023 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.


if [ $# -lt 2 ]
then
  echo "Usage: $0 in.wav out.wav"
  echo "Aligns in.wav to 20ms blocks by appending zero samples; output is stored in out.wav"
  echo "Requires: InfoAudio, CopyAudio"
  exit 1
fi

file_in=$1
file_out=$2

InfoAudio=InfoAudio
CopyAudio=CopyAudio

# getting all info from InfoAudio - storing in res
res=`$InfoAudio $file_in`

# paring res
sampleFreq=`echo "$res" | grep -m1 "Sampling frequency" | sed -e 's/\([a-zA-Z\. ]*: \)\([0-9]*\)\(.*\)/\2/g'`

numberSamples=`echo "$res" | grep -m1 "No. frames" | sed -e 's/\([a-zA-Z\. ]*: \)\([0-9]*\)\(.*\)/\2/g'`

remainder=$(expr $numberSamples % 960)
samplesToPad=0

if [ $remainder -eq 0 ]; then
    # no padding required, just copy files
    cp $file_in $file_out
else
    samplesToPad=$(expr 960 - $remainder)
    limit=$(expr $samplesToPad - 1)
    
    # copy required number of sampled to pad into temp file, scale with 0 gain --> results in silence
    tmp=`mktemp`
    $CopyAudio -l 0:$limit -g 0 $file_in $tmp

    # concatenate original file with silence block
    $CopyAudio --concatenate $file_in $tmp $file_out

    # delete tmp file
    rm -f $tmp
fi