Commit 49637baf authored by Dominik Weckbecker's avatar Dominik Weckbecker 💬
Browse files

fix bug in channel reordering

parent 1e6877f4
Loading
Loading
Loading
Loading
Loading
+47 −3
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@
*******************************************************************************************************/
#include <stdint.h>
#include <assert.h>
#include <stdio.h>
#include "ambi_convert.h"

#define L_FRAME48k 960
@@ -123,15 +124,24 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0,

int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT in_format, AMBI_FMT out_format )
{
    assert( order <= 3 );

    float tmp[AMBI_MAX_CHANNELS*L_FRAME48k];
    float *p_tmp[AMBI_MAX_CHANNELS];
    AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN, ch_ord_out = AMBI_NORM_SN3D;
    AMBI_CHANNEL_NORM ch_norm_in = AMBI_CHANNEL_ORDER_ACN, ch_norm_out = AMBI_NORM_SN3D;

    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++)
    {
        p_tmp[j]=&tmp[j*L_FRAME48k];
    }

    switch ( in_format )
    {
        case AMBI_FMT_ACN_SN3D:
@@ -194,13 +204,47 @@ int16_t convert_ambi_format( float *in[], float *out[], int16_t order, AMBI_FMT

    if ( in_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out )
    {
        renormalize_channels( in, out, order, ch_norm_in, ch_norm_out );
        renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out );
    }

#if 0
	{
		static FILE* f_foa = 0;
		if (f_foa == 0)
			f_foa = fopen("renorm.raw","wb");

		for (int16_t  j=0; j < 960;j++)
		{
			for ( int n = 0; n < 16; n++)
			{
				int16_t s1 = out[n][j];
				fwrite(&s1,sizeof(int16_t),1,f_foa);
			}
		}
	}
#endif

    if ( ch_ord_in != ch_ord_out )
    {
        reorder_channels( in, out, order, ch_ord_in, ch_ord_out );
        reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out );
    }

#if 0
	{
		static FILE* f_foa = 0;
		if (f_foa == 0)
			f_foa = fopen("reorder.raw","wb");

		for (int16_t  j=0; j < 960;j++)
		{
			for ( int n = 0; n < 16; n++)
			{
				int16_t s1 = out[n][j];
				fwrite(&s1,sizeof(int16_t),1,f_foa);
			}
		}
	}
#endif

    if ( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_out )
    {