Commit b0d818ec authored by Dominik Weckbecker's avatar Dominik Weckbecker 💬
Browse files

add channel re-ordering tables

parent 7cf0c276
Loading
Loading
Loading
Loading
+77 −2
Original line number Diff line number Diff line
@@ -54,6 +54,10 @@

#define AMBI_MAX_CHANNELS 16

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

static const float N3D_SN3D[AMBI_MAX_CHANNELS] = { 1.0f,
                                                   SQRT_3, SQRT_3, SQRT_3,
                                                   SQRT_5, SQRT_5, SQRT_5, SQRT_5, SQRT_5,
@@ -77,6 +81,40 @@ static const float SN3D_MAXN[AMBI_MAX_CHANNELS] = { 1.0f,
                                                    INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3, 1.0f, INV_TWO_OVER_SQRT_3, INV_TWO_OVER_SQRT_3,
                                                    INV_SQRT_8_OVER_5, INV_SQRT_3_OVER_5, INV_SQRT_45_OVER_32, 1.0f, INV_SQRT_45_OVER_32, INV_SQRT_3_OVER_5, INV_SQRT_8_OVER_5 };

/* ----------------------------
    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
   ---------------------------------- */


int16_t convert_ambi_format( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format )
{
    assert( order <= 3 );
@@ -143,7 +181,9 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i
{
    int16_t n_chan = ( order + 1 ) * ( order + 1 );
    int16_t i_chan, i;
    float *conversion_table;
    const float *conversion_table;

	/* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */

	if ( in_format == AMBI_NORM_SN3D )
    {
@@ -180,7 +220,6 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i
        assert( 0 && "Conversion only supported to and from ACN-SN3D" );
    }

	/* conversion factors are aplpied on the channels assuming that they are still/already in ACN order */
	for (i_chan = 0; i_chan < n_chan; i_chan++)
	{
		float conversion_factor = conversion_table[i_chan];
@@ -196,6 +235,42 @@ int16_t renormalize_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], i
int16_t reorder_channels( float in[][L_FRAME48k], float out[][L_FRAME48k], int16_t order, AMBI_CHANNEL_ORDER in_format, AMBI_CHANNEL_ORDER out_format )
{
    int16_t nchan = ( order + 1 ) * ( order + 1 );
    int16_t *idx_table;

	if ( in_format == AMBI_CHANNEL_ORDER_ACN )
    {
        if ( out_format == AMBI_CHANNEL_ORDER_FM )
        {
            idx_table = REORDER_ACN_FM;
        }
        if ( out_format == AMBI_CHANNEL_ORDER_SID )
        {
            idx_table = REORDER_ACN_SID;
        }
        else
        {
            assert( 0 && "Unsupported conversion" );
        }
    }
    else if ( out_format == AMBI_CHANNEL_ORDER_ACN )
    {
        if ( in_format == AMBI_CHANNEL_ORDER_FM )
        {
            idx_table = REORDER_ACN_FM;
        }
        if ( in_format == AMBI_CHANNEL_ORDER_SID )
        {
            idx_table = REORDER_ACN_SID;
        }
        else
        {
            assert( 0 && "Unsupported conversion" );
        }
    }
    else
    {
        assert( 0 && "Conversion only supported to and from ACN-SN3D" );
    }

    return 0;
}