Loading lib_util/ambi_convert.c +95 −50 Original line number Diff line number Diff line Loading @@ -146,149 +146,180 @@ AMBI_CONVERT_ERROR convert_ambi_format( 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" ); } for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) i = 0; move16(); FOR( j = 0; j < AMBI_MAX_CHANNELS; j++ ) { p_tmp[j] = &tmp[j * L_FRAME48k]; p_tmp[j] = &tmp[i]; move32(); i = add( i, L_FRAME48k ); } switch ( in_format ) 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 ) 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( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_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 ) 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 ) IF( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { return err; } } else ELSE { if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) 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 ) 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 ) 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 ) ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_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 ) 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 ) IF( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) { return err; } } else ELSE { if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) 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 ) 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 ) 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 ) 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++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { int16_t i = 0; for ( i = 0; i < L_FRAME48k; i++ ) move16(); FOR( i = 0; i < L_FRAME48k; i++ ) { out[i_chan][i] = in[i_chan][i]; move16(); } } } else ELSE { assert( 0 && "This should never happen!" ); } Loading Loading @@ -316,54 +347,61 @@ AMBI_CONVERT_ERROR renormalize_channels( /* conversion factors are applied on the channels assuming that they are still/already in ACN order */ if ( in_format == AMBI_NORM_SN3D ) IF( in_format == AMBI_NORM_SN3D ) { if ( out_format == AMBI_NORM_N3D ) IF( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; move32(); } else if ( out_format == AMBI_NORM_MAXN ) ELSE IF( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; move32(); } else if ( out_format == AMBI_NORM_FM ) ELSE IF( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; move32(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) ELSE IF( out_format == AMBI_NORM_SN3D ) { if ( in_format == AMBI_NORM_N3D ) IF( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; move32(); } else if ( in_format == AMBI_NORM_MAXN ) ELSE IF( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; move32(); } else if ( in_format == AMBI_NORM_FM ) ELSE IF( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; move32(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i_chan = 0; i_chan < n_chan; i_chan++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { Word32 conversion_factor = conversion_table[i_chan]; for ( i = 0; i < L_FRAME48k; i++ ) move32(); FOR( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); Loading Loading @@ -395,51 +433,58 @@ AMBI_CONVERT_ERROR reorder_channels( Word16 tmp[AMBI_MAX_CHANNELS]; const int16_t *idx_table = 0; if ( in_format == AMBI_CHANNEL_ORDER_ACN ) IF( in_format == AMBI_CHANNEL_ORDER_ACN ) { if ( out_format == AMBI_CHANNEL_ORDER_FM ) IF( out_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_ACN_FM; move16(); } else if ( out_format == AMBI_CHANNEL_ORDER_SID ) ELSE IF( out_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_ACN_SID; move16(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) ELSE IF( out_format == AMBI_CHANNEL_ORDER_ACN ) { if ( in_format == AMBI_CHANNEL_ORDER_FM ) IF( in_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_FM_ACN; move16(); } else if ( in_format == AMBI_CHANNEL_ORDER_SID ) ELSE IF( in_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_SID_ACN; move16(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i = 0; i < L_FRAME48k; i++ ) FOR( i = 0; i < L_FRAME48k; i++ ) { for ( i_chan = 0; i_chan < n_chan; i_chan++ ) 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++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { out[i_chan][i] = tmp[i_chan]; move16(); } } Loading Loading
lib_util/ambi_convert.c +95 −50 Original line number Diff line number Diff line Loading @@ -146,149 +146,180 @@ AMBI_CONVERT_ERROR convert_ambi_format( 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" ); } for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) i = 0; move16(); FOR( j = 0; j < AMBI_MAX_CHANNELS; j++ ) { p_tmp[j] = &tmp[j * L_FRAME48k]; p_tmp[j] = &tmp[i]; move32(); i = add( i, L_FRAME48k ); } switch ( in_format ) 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 ) 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( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_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 ) 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 ) IF( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { return err; } } else ELSE { if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) 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 ) 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 ) 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 ) ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out ) { if ( ch_ord_in != ch_ord_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 ) 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 ) IF( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) { return err; } } else ELSE { if ( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) 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 ) 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 ) 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 ) 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++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { int16_t i = 0; for ( i = 0; i < L_FRAME48k; i++ ) move16(); FOR( i = 0; i < L_FRAME48k; i++ ) { out[i_chan][i] = in[i_chan][i]; move16(); } } } else ELSE { assert( 0 && "This should never happen!" ); } Loading Loading @@ -316,54 +347,61 @@ AMBI_CONVERT_ERROR renormalize_channels( /* conversion factors are applied on the channels assuming that they are still/already in ACN order */ if ( in_format == AMBI_NORM_SN3D ) IF( in_format == AMBI_NORM_SN3D ) { if ( out_format == AMBI_NORM_N3D ) IF( out_format == AMBI_NORM_N3D ) { conversion_table = SN3D_N3D; move32(); } else if ( out_format == AMBI_NORM_MAXN ) ELSE IF( out_format == AMBI_NORM_MAXN ) { conversion_table = SN3D_MAXN; move32(); } else if ( out_format == AMBI_NORM_FM ) ELSE IF( out_format == AMBI_NORM_FM ) { conversion_table = SN3D_FM; move32(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) ELSE IF( out_format == AMBI_NORM_SN3D ) { if ( in_format == AMBI_NORM_N3D ) IF( in_format == AMBI_NORM_N3D ) { conversion_table = N3D_SN3D; move32(); } else if ( in_format == AMBI_NORM_MAXN ) ELSE IF( in_format == AMBI_NORM_MAXN ) { conversion_table = MAXN_SN3D; move32(); } else if ( in_format == AMBI_NORM_FM ) ELSE IF( in_format == AMBI_NORM_FM ) { conversion_table = FM_SN3D; move32(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i_chan = 0; i_chan < n_chan; i_chan++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { Word32 conversion_factor = conversion_table[i_chan]; for ( i = 0; i < L_FRAME48k; i++ ) move32(); FOR( i = 0; i < L_FRAME48k; i++ ) { Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); Loading Loading @@ -395,51 +433,58 @@ AMBI_CONVERT_ERROR reorder_channels( Word16 tmp[AMBI_MAX_CHANNELS]; const int16_t *idx_table = 0; if ( in_format == AMBI_CHANNEL_ORDER_ACN ) IF( in_format == AMBI_CHANNEL_ORDER_ACN ) { if ( out_format == AMBI_CHANNEL_ORDER_FM ) IF( out_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_ACN_FM; move16(); } else if ( out_format == AMBI_CHANNEL_ORDER_SID ) ELSE IF( out_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_ACN_SID; move16(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) ELSE IF( out_format == AMBI_CHANNEL_ORDER_ACN ) { if ( in_format == AMBI_CHANNEL_ORDER_FM ) IF( in_format == AMBI_CHANNEL_ORDER_FM ) { idx_table = REORDER_FM_ACN; move16(); } else if ( in_format == AMBI_CHANNEL_ORDER_SID ) ELSE IF( in_format == AMBI_CHANNEL_ORDER_SID ) { idx_table = REORDER_SID_ACN; move16(); } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else ELSE { return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i = 0; i < L_FRAME48k; i++ ) FOR( i = 0; i < L_FRAME48k; i++ ) { for ( i_chan = 0; i_chan < n_chan; i_chan++ ) 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++ ) FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { out[i_chan][i] = tmp[i_chan]; move16(); } } Loading