Loading apps/ambi_converter.c +11 −3 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ int main( int argc, char *argv[] ) order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int16_t err = 0; Loading @@ -97,7 +96,12 @@ int main( int argc, char *argv[] ) } } err = convert_ambi_format( in, out, order, in_format, out_format ); if ( (err = convert_ambi_format( in, out, order, in_format, out_format )) != 0 ) { printf("Error converting the input signal!\n"); return err; } for ( int16_t i = 0; i < numSamplesRead32; i++ ) { Loading @@ -107,7 +111,11 @@ int main( int argc, char *argv[] ) } } err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ); if ( (err = WriteWavShort( wavFile_out, samples, numSamplesRead32 )) != __TWO_SUCCESS ) { printf("Error writing output wave file!\n"); return err; } numSamplesRead32 = 0; } Loading lib_util/ambi_convert.c +48 −23 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, * Convert signal between ACN-SN3D and other common ambisonics conventions --------------------------------------------------------------------------*/ int16_t convert_ambi_format( AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -134,6 +134,7 @@ int16_t convert_ambi_format( float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; float *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; Loading Loading @@ -180,7 +181,7 @@ int16_t convert_ambi_format( ch_norm_in = AMBI_NORM_N3D; break; default: assert( 0 && "Unsupported in_format!" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } switch ( out_format ) Loading Loading @@ -210,40 +211,64 @@ int16_t convert_ambi_format( ch_norm_out = AMBI_NORM_N3D; break; default: assert( 0 && "Unsupported out_format!" ); 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 ) { renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); reorder_channels( p_tmp, out, order, 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 { renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); 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 ) { reorder_channels( in, out, order, 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 ) { reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ); renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_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 { renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); 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 ) { reorder_channels( in, out, order, 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 ) { Loading @@ -264,7 +289,7 @@ int16_t convert_ambi_format( assert( 0 && "This should never happen!" ); } return 0; return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* Loading @@ -273,7 +298,7 @@ int16_t convert_ambi_format( * Rescale audio channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ int16_t renormalize_channels( AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading Loading @@ -302,7 +327,7 @@ int16_t renormalize_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) Loading @@ -321,12 +346,12 @@ int16_t renormalize_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } Loading @@ -339,7 +364,7 @@ int16_t renormalize_channels( } } return 0; return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* Loading @@ -348,7 +373,7 @@ int16_t renormalize_channels( * Reorder channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ int16_t reorder_channels( AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -373,7 +398,7 @@ int16_t reorder_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) Loading @@ -388,12 +413,12 @@ int16_t reorder_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i = 0; i < L_FRAME48k; i++ ) Loading @@ -409,5 +434,5 @@ int16_t reorder_channels( } } return 0; return AMBI_CONVERT_OK; } lib_util/ambi_convert.h +9 −3 Original line number Diff line number Diff line Loading @@ -63,7 +63,13 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; int16_t convert_ambi_format( typedef enum { AMBI_CONVERT_OK = 0, AMBI_CONVERT_UNSUPPORTED_CONVERSION } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -71,7 +77,7 @@ int16_t convert_ambi_format( AMBI_FMT out_format /* i: output ambisonics format */ ); int16_t renormalize_channels( AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -79,7 +85,7 @@ int16_t renormalize_channels( AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); int16_t reorder_channels( AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading Loading
apps/ambi_converter.c +11 −3 Original line number Diff line number Diff line Loading @@ -79,7 +79,6 @@ int main( int argc, char *argv[] ) order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int16_t err = 0; Loading @@ -97,7 +96,12 @@ int main( int argc, char *argv[] ) } } err = convert_ambi_format( in, out, order, in_format, out_format ); if ( (err = convert_ambi_format( in, out, order, in_format, out_format )) != 0 ) { printf("Error converting the input signal!\n"); return err; } for ( int16_t i = 0; i < numSamplesRead32; i++ ) { Loading @@ -107,7 +111,11 @@ int main( int argc, char *argv[] ) } } err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ); if ( (err = WriteWavShort( wavFile_out, samples, numSamplesRead32 )) != __TWO_SUCCESS ) { printf("Error writing output wave file!\n"); return err; } numSamplesRead32 = 0; } Loading
lib_util/ambi_convert.c +48 −23 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, * Convert signal between ACN-SN3D and other common ambisonics conventions --------------------------------------------------------------------------*/ int16_t convert_ambi_format( AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -134,6 +134,7 @@ int16_t convert_ambi_format( float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; float *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; Loading Loading @@ -180,7 +181,7 @@ int16_t convert_ambi_format( ch_norm_in = AMBI_NORM_N3D; break; default: assert( 0 && "Unsupported in_format!" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } switch ( out_format ) Loading Loading @@ -210,40 +211,64 @@ int16_t convert_ambi_format( ch_norm_out = AMBI_NORM_N3D; break; default: assert( 0 && "Unsupported out_format!" ); 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 ) { renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); reorder_channels( p_tmp, out, order, 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 { renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); 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 ) { reorder_channels( in, out, order, 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 ) { reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ); renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_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 { renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); 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 ) { reorder_channels( in, out, order, 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 ) { Loading @@ -264,7 +289,7 @@ int16_t convert_ambi_format( assert( 0 && "This should never happen!" ); } return 0; return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* Loading @@ -273,7 +298,7 @@ int16_t convert_ambi_format( * Rescale audio channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ int16_t renormalize_channels( AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading Loading @@ -302,7 +327,7 @@ int16_t renormalize_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_NORM_SN3D ) Loading @@ -321,12 +346,12 @@ int16_t renormalize_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } Loading @@ -339,7 +364,7 @@ int16_t renormalize_channels( } } return 0; return AMBI_CONVERT_OK; } /*-------------------------------------------------------------------------* Loading @@ -348,7 +373,7 @@ int16_t renormalize_channels( * Reorder channels according to the selected ambisonics convention --------------------------------------------------------------------------*/ int16_t reorder_channels( AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -373,7 +398,7 @@ int16_t reorder_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else if ( out_format == AMBI_CHANNEL_ORDER_ACN ) Loading @@ -388,12 +413,12 @@ int16_t reorder_channels( } else { assert( 0 && "Unsupported conversion" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } } else { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } for ( i = 0; i < L_FRAME48k; i++ ) Loading @@ -409,5 +434,5 @@ int16_t reorder_channels( } } return 0; return AMBI_CONVERT_OK; }
lib_util/ambi_convert.h +9 −3 Original line number Diff line number Diff line Loading @@ -63,7 +63,13 @@ typedef enum AMBI_CHANNEL_ORDER_SID } AMBI_CHANNEL_ORDER; int16_t convert_ambi_format( typedef enum { AMBI_CONVERT_OK = 0, AMBI_CONVERT_UNSUPPORTED_CONVERSION } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -71,7 +77,7 @@ int16_t convert_ambi_format( AMBI_FMT out_format /* i: output ambisonics format */ ); int16_t renormalize_channels( AMBI_CONVERT_ERROR renormalize_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading @@ -79,7 +85,7 @@ int16_t renormalize_channels( AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); int16_t reorder_channels( AMBI_CONVERT_ERROR reorder_channels( float *in[], /* i: input ambisonics channels */ float *out[], /* o: output ambisonics channels */ int16_t order, /* i: ambisonics order */ Loading