Commit 904eac0b authored by Tapani Pihlajakuja's avatar Tapani Pihlajakuja
Browse files

Add Matlab script for converting LTV files in the long test vector branch to...

Add Matlab script for converting LTV files in the long test vector branch to other sample rates from 48 kHz.
parent ad78a3cd
Loading
Loading
Loading
Loading
+77 −0
Original line number Diff line number Diff line
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%   (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.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This script creates 16 kHz and 32 kHz versions of all wav-files in the
% same folder. This assumes that the input file will contain ltv48 as the
% starting pattern. It will replace them with ltv16 or ltv32 in the result.
%
% Note, MASA metadata and ISM metadata will not be converted as the same
% metadata can be used with lower sample rates.

d = dir('ltv48*.wav');

for n = 1:length(d)
    filename = d(n).name;
    disp(['Processing input file: ', filename]);
    
    [x, fs] = audioread(filename);
    
    if fs ~= 48000
        error('Input file is not with 48 kHz sample rate. Aborting.');
    end
    
    % Process 32 kHz
    x32 = resample(x, 32000, 48000);

    % Check if clipping would occur and normalize when necessary
    maxAbsVal = max(abs(x32),[],'all');
    if (maxAbsVal >= 1.0)
        warning('Clipping would occur, normalizing output');
        x32 = x32 .* (0.98/maxAbsVal);
    end
    
    audiowrite(['ltv32', filename(6:end)], x32, 32000);
    
    % Process 16 kHz
    x16 = resample(x, 16000, 48000);
    
    % Check if clipping would occur and normalize when necessary
    maxAbsVal = max(abs(x16),[],'all');
    if (maxAbsVal >= 1.0)
        warning('Clipping would occur, normalizing output');
        x16 = x16 .* (0.98/maxAbsVal);
    end

    audiowrite(['ltv16', filename(6:end)], x16, 16000);
end