Commit a592fe18 authored by multrus's avatar multrus
Browse files

Merge branch '114-add-helper-script-to-verify-object-audio-files' into 'main'

Resolve "Add helper-script to verify object audio files"

See merge request !213
parents d98a9aad a9c14cbe
Loading
Loading
Loading
Loading

other/check_ISM.sh

0 → 100755
+92 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash

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


# Usage: check_ISM.sh audio.wav ism_metadata.0.csv [... ism_metadata.4.csv]
# Compares the number of audio frames against the number of frames in the object metadata
# Requires: InfoAudio


if (( $# < 2 || $# > 5 )); then
    echo ""
    echo "Usage: $0 audio.wav ism_metadata.0.csv [... ism_metadata.4.csv]" >&2
    echo "file_name;success;audio_20ms_aligned;no_audio_frames;no_object_frames" >&2
    exit 1
fi

InfoAudio=InfoAudio

audio_file=$1
metadata_files=("${@:2}")
line_counts=()

# getting all info from InfoAudio - storing in res
res=`$InfoAudio "$audio_file"`
# paring res
sampleFreq=`echo "$res" | grep -m1 "Sampling frequency" | sed -e 's/\([a-zA-Z\. ]*: \)\([0-9]*\)\(.*\)/\2/g'`
frameSize=$(( sampleFreq / 50 ))
numberSamples=`echo "$res" | grep -m1 "No. frames" | sed -e 's/\([a-zA-Z\. ]*: \)\([0-9]*\)\(.*\)/\2/g'`
numberSampleFrames=$(( numberSamples / frameSize ))

aligned20ms=false
remainder=$(expr $numberSamples % 960)
if [ $remainder -eq 0 ]; then
    aligned20ms=true
fi

# iterate over metadata-files
for file in "${metadata_files[@]}"; do
    if [[ -r $file ]]; then
	# count number of lines
	lines=$(wc -l < "$file")
	line_counts+=("$lines")
    else
	echo "Warning: File '$file' not found or not readable" >&2
	line_counts+=(0)
    fi
done

success=true
if [[ "$aligned20ms" == "false" ]]; then
    success=false
fi

no_object_frames=""
for i in "${!line_counts[@]}"; do
    count="${line_counts[i]//[[:space:]]/}" # also remove any whitespace 
    no_object_frames+=";$count"
    
    if (( count != numberSampleFrames )); then
	success=false
    fi
done

# echo "file_name;success;audio_20ms_aligned;no_audio_frames;no_object_frames"
echo "${audio_file};${success};${aligned20ms};${numberSampleFrames}${no_object_frames}"