Commit f84afb41 authored by Mohammadreza Naghibzadeh's avatar Mohammadreza Naghibzadeh
Browse files

Merge remote-tracking branch 'origin/main' into 1721_fix_activated_hp20_recoding

parents a15d5d0c 3782eb08
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1415,10 +1415,15 @@ typedef enum
#define LFE_CHANNEL                             3

#define MIN_LFE_NRG                             0.5f
#ifdef ADJUST_MCT_CHANNELS_MAX   
#define MCT_MAX_CHANNELS                        11                          /* == 7.1.4 LS channels without the LFE channel */
#define MCT_MAX_BLOCKS                          ( ( MCT_MAX_CHANNELS + 1 ) / CPE_CHANNELS )    /* max. number of channel pairs (MCT_MAX_CHANNELS/2) within MCT*/
#else
#define MCT_MAX_CHANNELS                        MAX_TRANSPORT_CHANNELS
#define MCT_MAX_BLOCKS                          ( MCT_MAX_CHANNELS / CPE_CHANNELS )    /* max. number of channel pairs (MCT_MAX_CHANNELS/2) within MCT*/

#define MAX_NUM_DATA                            max( MCT_MAX_CHANNELS, 4 )
#endif

#define NBBITS_MCT_RATIO                        4
#define BITRATE_MCT_RATIO_RANGE                 ( 1 << NBBITS_MCT_RATIO )   /* Range of the coded bitrate distribution ratio */
+2 −1
Original line number Diff line number Diff line
@@ -119,7 +119,8 @@
#define NONBE_FIX_1220_OMASA_JBM_EXT_USAN               /* Nokia: fix issue 1220 OMASA EXT JBM USAN, also fix similar cases of free to avoid future problems */
#define NONBE_FIX_1376_MDCT_CONCEALMENT                 /* FhG: fix concealment artifact in MDCT Stereo with DTX, in case transition frame gets lost */
#define NONBE_1377_REND_DIRATT_CONF                     /* Eri: Issue 1377: Error in directivity attenuation configuration for both IVAS_dec and IVAS_rend */

#define FIX_1999_TEMPORARY_DISABLE_DIST_ATT_CHECK       /* Eri: Issue 1999: Range check on float values of distance attenuation, while the float values are not propagated to this function. The test is not correct, but configurable distance attenuation is not used in Characterization.*/
#define ADJUST_MCT_CHANNELS_MAX                         /* FhG: set correct max mct channels constant*/

/* #################### End BASOP porting switches ############################ */

+21 −5
Original line number Diff line number Diff line
@@ -75,9 +75,16 @@ void ivas_mct_side_bits_fx(
    {
        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
#ifdef ADJUST_MCT_CHANNELS_MAX
            IF( LT_16( i, MCT_MAX_CHANNELS ) )
            {
#endif
                sts[i] = hCPE[cpe_id]->hCoreCoder[ch];
                i = add( i, 1 );
                move16();
#ifdef ADJUST_MCT_CHANNELS_MAX
            }
#endif
        }
    }

@@ -218,10 +225,19 @@ void ivas_mct_core_dec(
    {
        FOR( ch = 0; ch < CPE_CHANNELS; ( ch++, i++ ) )
        {
#ifdef ADJUST_MCT_CHANNELS_MAX
            IF( LT_16( i, MCT_MAX_CHANNELS ) )
            {
#endif
                sts[i] = hCPE[cpe_id]->hCoreCoder[ch];
#ifdef ADJUST_MCT_CHANNELS_MAX
            }
#endif
        }
    }

#ifndef ADJUST_MCT_CHANNELS_MAX
    /*seems like obsolete code*/
    i = 0;
    move16();
    FOR( ch = 0; ch < nChannels; ch++ )
@@ -232,7 +248,7 @@ void ivas_mct_core_dec(
        }
        i = add( i, 1 );
    }

#endif
    bfi = sts[0]->bfi;
    move16();

+10 −1
Original line number Diff line number Diff line
@@ -293,6 +293,7 @@ void ivas_mct_core_enc_fx(
        inv_spectrum_fx[ch][1] = inv_spectrum_long_cpe0_fx[ch] + N_TCX10_MAX;
        powerSpec_fx[ch] = powerSpec_long_cpe0_fx[ch];
    }

    FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
    {
        q_powSpec[ch] = 0;
@@ -332,7 +333,15 @@ void ivas_mct_core_enc_fx(
    {
        FOR( ch = 0; ch < CPE_CHANNELS; ch++ )
        {
#ifdef ADJUST_MCT_CHANNELS_MAX
            IF( LT_16( add( i_mult( cpe_id, CPE_CHANNELS ), ch ), nChannels ) )
            {
#endif
                sts[i] = hCPE[cpe_id]->hCoreCoder[ch];
#ifdef ADJUST_MCT_CHANNELS_MAX
            }
#endif

            IF( EQ_32( hCPE[cpe_id]->hCoreCoder[ch]->mct_chan_mode, MCT_CHAN_MODE_IGNORE ) )
            {
                i = add( i, 1 );
+504 −0
Original line number Diff line number Diff line
/******************************************************************************************************

   (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.

*******************************************************************************************************/

#include <assert.h>
#include <stdio.h>
#include "wmc_auto.h"
#include "ambi_convert.h"

#define ONE_1_Q29      536870912l /* 1.0f */
#define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */

#define SQRT_2_Q29 759250112l  /* sqrtf(2.0f) */
#define SQRT_3_Q29 929887680l  /* sqrtf(3.0f) */
#define SQRT_5_Q29 1200479872l /* sqrtf(5.0f) */
#define SQRT_7_Q29 1420426880l /* sqrtf(7.0f) */

#define INV_SQRT_2_Q29 379625024l /* 1.0f/sqrtf(2.0f) */
#define INV_SQRT_3_Q29 309962528l /* 1.0f/sqrtf(3.0f) */
#define INV_SQRT_5_Q29 240095920l /* 1.0f/sqrtf(5.0f) */
#define INV_SQRT_7_Q29 202918096l /* 1.0f/sqrtf(7.0f) */

#define TWO_OVER_SQRT_3_Q29   619925120l /* 2.0f/sqrtf(3.0f)   */
#define THREE_OVER_SQRT_5_Q29 720287936l /* 3.0f/sqrtf(5.0f)   */
#define SQRT_8_OVER_5_Q29     679093952l /* sqrtf(8.0f/5.0f)   */
#define SQRT_45_OVER_32_Q29   636650560l /* sqrtf(45.0f/32.0f) */

#define INV_TWO_OVER_SQRT_3_Q29   464943840l /* 1.0f/TWO_OVER_SQRT_3_Q29   */
#define INV_THREE_OVER_SQRT_5_Q29 400159968l /* 1.0f/THREE_OVER_SQRT_5_Q29 */
#define INV_SQRT_8_OVER_5_Q29     424433728l /* 1.0f/INV_SQRT_8_OVER_5_Q29 */
#define INV_SQRT_45_OVER_32_Q29   452729280l /* 1.0f/SQRT_45_OVER_32_Q29   */


/* --------------------------------
   normalization conversion tables
   -------------------------------- */

static const Word32 SN3D_N3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29,
                                                    SQRT_3_Q29, SQRT_3_Q29, SQRT_3_Q29,
                                                    SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29, SQRT_5_Q29,
                                                    SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29, SQRT_7_Q29 };

static const Word32 N3D_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29,
                                                    INV_SQRT_3_Q29, INV_SQRT_3_Q29, INV_SQRT_3_Q29,
                                                    INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29, INV_SQRT_5_Q29,
                                                    INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29, INV_SQRT_7_Q29 };


static const Word32 SN3D_MAXN[AMBI_MAX_CHANNELS] = { ONE_1_Q29,
                                                     ONE_1_Q29, ONE_1_Q29, ONE_1_Q29,
                                                     TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29,
                                                     SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 };

static const Word32 MAXN_SN3D[AMBI_MAX_CHANNELS] = { ONE_1_Q29,
                                                     ONE_1_Q29, ONE_1_Q29, ONE_1_Q29,
                                                     INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29,
                                                     INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 };

static const Word32 SN3D_FM[AMBI_MAX_CHANNELS] = { INV_SQRT_2_Q29,
                                                   ONE_1_Q29, ONE_1_Q29, ONE_1_Q29,
                                                   TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29, ONE_1_Q29, TWO_OVER_SQRT_3_Q29, TWO_OVER_SQRT_3_Q29,
                                                   SQRT_8_OVER_5_Q29, THREE_OVER_SQRT_5_Q29, SQRT_45_OVER_32_Q29, ONE_1_Q29, SQRT_45_OVER_32_Q29, THREE_OVER_SQRT_5_Q29, SQRT_8_OVER_5_Q29 };

static const Word32 FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_Q29,
                                                   ONE_1_Q29, ONE_1_Q29, ONE_1_Q29,
                                                   INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29, ONE_1_Q29, INV_TWO_OVER_SQRT_3_Q29, INV_TWO_OVER_SQRT_3_Q29,
                                                   INV_SQRT_8_OVER_5_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_45_OVER_32_Q29, ONE_1_Q29, INV_SQRT_45_OVER_32_Q29, INV_THREE_OVER_SQRT_5_Q29, INV_SQRT_8_OVER_5_Q29 };

/* ----------------------------
    channel re-ordering tables
   ---------------------------- */

static const int16_t REORDER_FM_ACN[AMBI_MAX_CHANNELS] = { 0,
                                                           2, 3, 1,
                                                           8, 6, 4, 5, 7,
                                                           15, 13, 11, 9, 10, 12, 14 };

static const int16_t REORDER_SID_ACN[AMBI_MAX_CHANNELS] = { 0,
                                                            2, 3, 1,
                                                            5, 7, 8, 6, 4,
                                                            10, 12, 14, 15, 13, 11, 9 };

static const int16_t REORDER_ACN_FM[AMBI_MAX_CHANNELS] = { 0,
                                                           3, 1, 2,
                                                           6, 7, 5, 8, 4,
                                                           12, 13, 11, 14, 10, 15, 9 };

static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0,
                                                            3, 1, 2,
                                                            8, 4, 7, 5, 6,
                                                            15, 9, 14, 10, 13, 11, 12 };

/* ----------------------------------
    API functions for the conversion
   ---------------------------------- */

/*-------------------------------------------------------------------------*
* convert_ambi_format()
*
* Convert signal between ACN-SN3D and other common ambisonics conventions
--------------------------------------------------------------------------*/

AMBI_CONVERT_ERROR convert_ambi_format(
    Word16 *in[],       /* i: input ambisonics channels, Q0  */
    Word16 *out[],      /* o: output ambisonics channels, Q0 */
    int16_t order,      /* i: ambisonics order               */
    AMBI_FMT in_format, /* i: input ambisonics format        */
    AMBI_FMT out_format /* i: output ambisonics format       */
)
{

    Word16 tmp[AMBI_MAX_CHANNELS * L_FRAME48k];
    Word16 *p_tmp[AMBI_MAX_CHANNELS];
    AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK;

    AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN;
    AMBI_CHANNEL_ORDER ch_ord_out = AMBI_CHANNEL_ORDER_ACN;

    AMBI_CHANNEL_NORM ch_norm_in = AMBI_NORM_SN3D;
    AMBI_CHANNEL_NORM ch_norm_out = AMBI_NORM_SN3D;

    Word16 i, j;

    assert( order <= 3 );

    if ( in_format != AMBI_FMT_ACN_SN3D && out_format != AMBI_FMT_ACN_SN3D )
    {
        assert( 0 && "Conversion only supported to and from ACN-SN3D" );
    }
    i = 0;
    move16();
    FOR( j = 0; j < AMBI_MAX_CHANNELS; j++ )
    {
        p_tmp[j] = &tmp[i];
        move32();
        i = add( i, L_FRAME48k );
    }

    SWITCH( in_format )
    {
        case AMBI_FMT_ACN_SN3D:
            ch_ord_in = AMBI_CHANNEL_ORDER_ACN;
            ch_norm_in = AMBI_NORM_SN3D;
            move16();
            move16();
            break;
        case AMBI_FMT_ACN_N3D:
            ch_ord_in = AMBI_CHANNEL_ORDER_ACN;
            ch_norm_in = AMBI_NORM_N3D;
            move16();
            move16();
            break;
        case AMBI_FMT_FM_MAXN:
            ch_ord_in = AMBI_CHANNEL_ORDER_FM;
            ch_norm_in = AMBI_NORM_MAXN;
            move16();
            move16();
            break;
        case AMBI_FMT_FM_FM:
            ch_ord_in = AMBI_CHANNEL_ORDER_FM;
            ch_norm_in = AMBI_NORM_FM;
            move16();
            move16();
            break;
        case AMBI_FMT_SID_SN3D:
            ch_ord_in = AMBI_CHANNEL_ORDER_SID;
            ch_norm_in = AMBI_NORM_SN3D;
            move16();
            move16();
            break;
        case AMBI_FMT_SID_N3D:
            ch_ord_in = AMBI_CHANNEL_ORDER_SID;
            ch_norm_in = AMBI_NORM_N3D;
            move16();
            move16();
            break;
        default:
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
    }

    SWITCH( out_format )
    {
        case AMBI_FMT_ACN_SN3D:
            ch_ord_out = AMBI_CHANNEL_ORDER_ACN;
            ch_norm_out = AMBI_NORM_SN3D;
            move16();
            move16();
            break;
        case AMBI_FMT_ACN_N3D:
            ch_ord_out = AMBI_CHANNEL_ORDER_ACN;
            ch_norm_out = AMBI_NORM_N3D;
            move16();
            move16();
            break;
        case AMBI_FMT_FM_MAXN:
            ch_ord_out = AMBI_CHANNEL_ORDER_FM;
            ch_norm_out = AMBI_NORM_MAXN;
            move16();
            move16();
            break;
        case AMBI_FMT_FM_FM:
            ch_ord_out = AMBI_CHANNEL_ORDER_FM;
            ch_norm_out = AMBI_NORM_FM;
            move16();
            move16();
            break;
        case AMBI_FMT_SID_SN3D:
            ch_ord_out = AMBI_CHANNEL_ORDER_SID;
            ch_norm_out = AMBI_NORM_SN3D;
            move16();
            move16();
            break;
        case AMBI_FMT_SID_N3D:
            ch_ord_out = AMBI_CHANNEL_ORDER_SID;
            ch_norm_out = AMBI_NORM_N3D;
            move16();
            move16();
            break;
        default:
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
    }

    IF( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out )
    {
        IF( ch_ord_in != ch_ord_out )
        {
            IF( ( err = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
            IF( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
        }
        ELSE
        {
            IF( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
        }
    }
    ELSE IF( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out )
    {
        IF( ( err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK )
        {
            return err;
        }
    }
    ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out )
    {
        IF( ch_ord_in != ch_ord_out )
        {
            IF( ( err = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
            IF( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
        }
        ELSE
        {
            IF( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK )
            {
                return err;
            }
        }
    }
    ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out )
    {
        IF( ( err = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK )
        {
            return err;
        }
    }
    ELSE IF( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D )
    {
        int16_t i_chan = 0;
        int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) );

        FOR( i_chan = 0; i_chan < n_chan; i_chan++ )
        {
            int16_t i = 0;
            move16();
            FOR( i = 0; i < L_FRAME48k; i++ )
            {
                out[i_chan][i] = in[i_chan][i];
                move16();
            }
        }
    }
    ELSE
    {
        assert( 0 && "This should never happen!" );
    }

    return AMBI_CONVERT_OK;
}

/*-------------------------------------------------------------------------*
* renormalize_channels()
*
* Rescale audio channels according to the selected ambisonics convention
--------------------------------------------------------------------------*/

AMBI_CONVERT_ERROR renormalize_channels(
    Word16 *in[],                /* i: input ambisonics channels, Q0  */
    Word16 *out[],               /* o: output ambisonics channels, Q0 */
    int16_t order,               /* i: ambisonics order               */
    AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format        */
    AMBI_CHANNEL_NORM out_format /* i: output ambisonics format       */
)
{
    int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) );
    int16_t i_chan, i;
    const Word32 *conversion_table = 0;
    Word32 minval = 0;
    Word32 maxval = 0;
    move32();
    move32();
    move32();


    /* conversion factors are applied on the channels assuming that they are still/already in ACN order */
    IF( in_format == AMBI_NORM_SN3D )
    {
        IF( out_format == AMBI_NORM_N3D )
        {
            conversion_table = SN3D_N3D;
            move32();
        }
        ELSE IF( out_format == AMBI_NORM_MAXN )
        {
            conversion_table = SN3D_MAXN;
            move32();
        }
        ELSE IF( out_format == AMBI_NORM_FM )
        {
            conversion_table = SN3D_FM;
            move32();
        }
        ELSE
        {
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
        }
    }
    ELSE IF( out_format == AMBI_NORM_SN3D )
    {
        IF( in_format == AMBI_NORM_N3D )
        {
            conversion_table = N3D_SN3D;
            move32();
        }
        ELSE IF( in_format == AMBI_NORM_MAXN )
        {
            conversion_table = MAXN_SN3D;
            move32();
        }
        ELSE IF( in_format == AMBI_NORM_FM )
        {
            conversion_table = FM_SN3D;
            move32();
        }
        ELSE
        {
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
        }
    }
    ELSE
    {
        return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
    }


    FOR( i_chan = 0; i_chan < n_chan; i_chan++ )
    {
        Word32 conversion_factor = conversion_table[i_chan];
        Word32 outval;
        move32();
        FOR( i = 0; i < L_FRAME48k; i++ )
        {
            Word64 tmp;
            tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor );
            /* tmp = W_add( tmp, ONE_OVER_2_Q29); */ /* rounding up */
            outval = W_extract_l( W_shr( tmp, Q29 ) );
            minval = L_min( minval, outval );
            maxval = L_min( maxval, outval );
            out[i_chan][i] = extract_l( outval );
        }
    }
    IF( ( minval < MIN16B ) || ( maxval > MAX16B ) )
    {
        return AMBI_CONVERT_CLIPPING_DETECTED;
    }
    return AMBI_CONVERT_OK;
}

/*-------------------------------------------------------------------------*
* reorder_channels()
*
* Reorder channels according to the selected ambisonics convention
--------------------------------------------------------------------------*/

AMBI_CONVERT_ERROR reorder_channels(
    Word16 *in[],                 /* i: input ambisonics channels, Q0  */
    Word16 *out[],                /* o: output ambisonics channels, Q0 */
    int16_t order,                /* i: ambisonics order               */
    AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format        */
    AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format       */
)
{
    int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) );
    int16_t i_chan, i;
    Word16 tmp[AMBI_MAX_CHANNELS];
    const int16_t *idx_table = 0;

    IF( in_format == AMBI_CHANNEL_ORDER_ACN )
    {
        IF( out_format == AMBI_CHANNEL_ORDER_FM )
        {
            idx_table = REORDER_ACN_FM;
            move16();
        }
        ELSE IF( out_format == AMBI_CHANNEL_ORDER_SID )
        {
            idx_table = REORDER_ACN_SID;
            move16();
        }
        ELSE
        {
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
        }
    }
    ELSE IF( out_format == AMBI_CHANNEL_ORDER_ACN )
    {
        IF( in_format == AMBI_CHANNEL_ORDER_FM )
        {
            idx_table = REORDER_FM_ACN;
            move16();
        }
        ELSE IF( in_format == AMBI_CHANNEL_ORDER_SID )
        {
            idx_table = REORDER_SID_ACN;
            move16();
        }
        ELSE
        {
            return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
        }
    }
    ELSE
    {
        return AMBI_CONVERT_UNSUPPORTED_CONVERSION;
    }

    FOR( i = 0; i < L_FRAME48k; i++ )
    {
        FOR( i_chan = 0; i_chan < n_chan; i_chan++ )
        {
            int16_t idx = idx_table[i_chan];
            move16();
            tmp[i_chan] = in[idx][i];
            move16();
        }
        FOR( i_chan = 0; i_chan < n_chan; i_chan++ )
        {
            out[i_chan][i] = tmp[i_chan];
            move16();
        }
    }

    return AMBI_CONVERT_OK;
}
Loading