diff options
Diffstat (limited to 'util/adt_generate_qt.m')
-rw-r--r-- | util/adt_generate_qt.m | 123 |
1 files changed, 28 insertions, 95 deletions
diff --git a/util/adt_generate_qt.m b/util/adt_generate_qt.m index 45b3dcd03..453732273 100644 --- a/util/adt_generate_qt.m +++ b/util/adt_generate_qt.m @@ -1,31 +1,6 @@ %{ -**************************************************************************** -** ** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is the build configuration utility of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -**************************************************************************** +** SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 %} % Create mapping matrixes to convert ambisonic to different speaker layouts supported in Qt Multimedia @@ -43,47 +18,11 @@ function adt_generate_qt() radius = 2; [outfile,msg] = fopen("qambisonicdecoderdata_p.h",'w'); - fprintf(outfile, "/****************************************************************************\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** Copyright (C) 2016 The Qt Company Ltd.\n"); - fprintf(outfile, "** Contact: https://www.qt.io/licensing/\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** This file is part of the Qt Toolkit.\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** $QT_BEGIN_LICENSE:LGPL$\n"); - fprintf(outfile, "** Commercial License Usage\n"); - fprintf(outfile, "** Licensees holding valid commercial Qt licenses may use this file in\n"); - fprintf(outfile, "** accordance with the commercial license agreement provided with the\n"); - fprintf(outfile, "** Software or, alternatively, in accordance with the terms contained in\n"); - fprintf(outfile, "** a written agreement between you and The Qt Company. For licensing terms\n"); - fprintf(outfile, "** and conditions see https://www.qt.io/terms-conditions. For further\n"); - fprintf(outfile, "** information use the contact form at https://www.qt.io/contact-us.\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** GNU Lesser General Public License Usage\n"); - fprintf(outfile, "** Alternatively, this file may be used under the terms of the GNU Lesser\n"); - fprintf(outfile, "** General Public License version 3 as published by the Free Software\n"); - fprintf(outfile, "** Foundation and appearing in the file LICENSE.LGPL3 included in the\n"); - fprintf(outfile, "** packaging of this file. Please review the following information to\n"); - fprintf(outfile, "** ensure the GNU Lesser General Public License version 3 requirements\n"); - fprintf(outfile, "** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** GNU General Public License Usage\n"); - fprintf(outfile, "** Alternatively, this file may be used under the terms of the GNU\n"); - fprintf(outfile, "** General Public License version 2.0 or (at your option) the GNU General\n"); - fprintf(outfile, "** Public license version 3 or any later version approved by the KDE Free\n"); - fprintf(outfile, "** Qt Foundation. The licenses are as published by the Free Software\n"); - fprintf(outfile, "** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3\n"); - fprintf(outfile, "** included in the packaging of this file. Please review the following\n"); - fprintf(outfile, "** information to ensure the GNU General Public License requirements will\n"); - fprintf(outfile, "** be met: https://www.gnu.org/licenses/gpl-2.0.html and\n"); - fprintf(outfile, "** https://www.gnu.org/licenses/gpl-3.0.html.\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "** $QT_END_LICENSE$\n"); - fprintf(outfile, "**\n"); - fprintf(outfile, "****************************************************************************/\n"); + fprintf(outfile, "// Copyright (C) 2016 The Qt Company Ltd.\n"); + fprintf(outfile, "//SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only\n"); fprintf(outfile, "#ifndef QAMBISONICDECODERDATA_P_H\n"); fprintf(outfile, "#define QAMBISONICDECODERDATA_P_H\n\n"); - fprintf(outfile, "#include <qtmultimediaglobal_p.h>\n\n"); + fprintf(outfile, "#include <qtspatialaudioglobal_p.h>\n\n"); fprintf(outfile, "// W A R N I N G\n"); fprintf(outfile, "// -------------\n"); fprintf(outfile, "//\n"); @@ -98,34 +37,6 @@ function adt_generate_qt() fprintf(outfile, "\n\n"); fprintf(outfile, "QT_BEGIN_NAMESPACE\n\n"); - % cover top/bottom and back for mono and stereo - imag_speakers = [0,0,radius; 0,0,-radius; 0,radius,0; 0,-radius,0; -radius,0,0]; - - % Mono, one speaker up front - S = ambi_spkr_array(... - ... % array name - 'mono', ... - ... % coordinate codes, unit codes - ... % Azimuth, Elevation, Radius; Degrees, Degrees, Meters - 'AER', 'DDM', ... - ... % speaker name, [azimuth, elevation, radius] - 'C', [ 0, 0, radius] ... - ); - createDecoders(S, imag_speakers, outfile); - - % Stereo, assume -30 and 30 degree speakers - S = ambi_spkr_array(... - 'stereo', ... - 'AER', 'DDM', ... - 'L', [ 30, 0, radius], ... - 'R', [ -30, 0, radius] ... - ); - createDecoders(S, imag_speakers, outfile); - - S.lfeRow = 3; - S.name = "2dot1"; - createDecoders(S, imag_speakers, outfile); - % cover top/bottom for surround imag_speakers = [0,0,radius; 0,0,-radius]; @@ -197,6 +108,26 @@ function writeLFERow(outfile, m, suffix) fprintf(outfile, "// LFE\n"); end +function [n, m] = getnm(l) +% Computes spherical harmonic degree and order from Ambisonic Channel Number. + n = floor(sqrt(l)); + m = l-n.^2-n; +end + +function channels = normalizeSN3D(channels) + for i = 1:columns(channels) + [n, m] = getnm(i-1); + if (m == 0) + factor = 1; + else + factor = sqrt(2 * factorial(n - abs(m)) / (factorial(n + abs(m)))); + endif + % There's an adjustment factor of 1.5 here, to match the volumes generated by the matrices + % here with what we get from a simple stereo decoding. The factor is heuristically determined + channels(i) *= factor*1.5; + endfor +end + function writeMatrix(outfile, level, S, M, suffix) m = trimMatrix(M); hasLFE = isfield(S, "lfeRow"); @@ -208,7 +139,8 @@ function writeMatrix(outfile, level, S, M, suffix) fprintf(outfile, "// Decoder matrix for %s, ambisonic level %d\n", S.name, level); fprintf(outfile, "static constexpr float decoderMatrix_%s_%d_%s[%d*%d] = {\n", S.name, level, suffix, r, c); for i = 1:rows(S.id) - fprintf(outfile, "%ff, ", m(i, :)); + channels = normalizeSN3D(m(i, :)) + fprintf(outfile, "%ff, ", channels); fprintf(outfile, "// %s\n", S.id(i, 1){1}); if (hasLFE && S.lfeRow == i + 1) writeLFERow(outfile, m, suffix); @@ -218,7 +150,8 @@ function writeMatrix(outfile, level, S, M, suffix) end function createOneDecoder(S, imag_speakers, outfile, level) - [D,S,M,C] = ambi_run_allrad(S, level, imag_speakers, [S.name '_' int2str(level)], false, "amb", 1, 3); + ambi_order = ambi_channel_definitions_convention(level, 'ambix2011') + [D,S,M,C] = ambi_run_allrad(S, ambi_order, imag_speakers, [S.name '_' int2str(level)], false, "amb", 1, 3); writeMatrix(outfile, level, S, M.lf, "lf"); m = ambi_apply_gamma(M.hf, D.hf_gains, C); writeMatrix(outfile, level, S, m, "hf"); |