diff --git a/CMakeLists.txt b/CMakeLists.txt index b17978926a8b25e4171b49c66c5d154c917c1785..b608a37b3929d0d0b41b9c6a1cbdf78a826201be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -206,6 +206,13 @@ add_executable(ISAR_post_rend apps/isar_post_rend.c) target_link_libraries(ISAR_post_rend lib_isar lib_util) target_include_directories(ISAR_post_rend PRIVATE lib_isar) +add_executable(ambi_converter apps/ambi_converter.c) + target_link_libraries(ambi_converter lib_util) +if(UNIX) + target_link_libraries(ambi_converter m) +endif() +target_include_directories(ambi_converter PRIVATE lib_util) + if(COPY_EXECUTABLES_FROM_BUILD_DIR) # Optionally copy executables to the same place where Make puts them (useful for tests that expect executables in specific places) add_custom_command(TARGET IVAS_cod POST_BUILD VERBATIM COMMAND "${CMAKE_COMMAND}" -E copy "$" "${CMAKE_CURRENT_SOURCE_DIR}/") diff --git a/Makefile b/Makefile index 63ac29842bb6109347cb23165b22538b037adb2d..c72aaacd8dbf36dbf8bc00552745d666a442b100 100644 --- a/Makefile +++ b/Makefile @@ -20,6 +20,7 @@ CLI_APIDEC ?= IVAS_dec CLI_APIENC ?= IVAS_cod CLI_APIREND ?= IVAS_rend CLI_APIPOSTREND ?= ISAR_post_rend +CLI_AMBICONVERT ?= ambi_converter LIB_LIBCOM ?= libivascom.a LIB_LIBDEBUG ?= libivasdebug.a LIB_LIBDEC ?= libivasdec.a @@ -150,10 +151,12 @@ OBJS_LIBREND = $(addprefix $(OBJDIR)/,$(SRCS_LIBREND:.c=.o)) OBJS_LIBISAR = $(addprefix $(OBJDIR)/,$(SRCS_LIBISAR:.c=.o)) OBJS_LC3PLUS = $(addprefix $(OBJDIR)/,$(SRCS_LC3PLUS:.c=.o)) OBJS_LIBUTIL = $(addprefix $(OBJDIR)/,$(SRCS_LIBUTIL:.c=.o)) +OBJS_AMBICONVERT = $(OBJDIR)/ambi_convert.o OBJS_CLI_APIDEC = $(OBJDIR)/decoder.o OBJS_CLI_APIENC = $(OBJDIR)/encoder.o OBJS_CLI_APPREND = $(OBJDIR)/renderer.o OBJS_CLI_APPPOSTREND = $(OBJDIR)/isar_post_rend.o +OBJS_CLI_AMBICONVERT = $(OBJDIR)/ambi_converter.o DEPS = $(addprefix $(OBJDIR)/,$(SRCS_LIBCOM:.c=.P) $(SRCS_LIBDEBUG:.c=.P) $(SRCS_LIBDEC:.c=.P) \ $(SRCS_LIBENC:.c=.P) $(SRCS_LIBUTIL:.c=.P) $(SRCS_LIBREND:.c=.P) $(SRCS_LIBISAR:.c=.P) \ @@ -204,13 +207,16 @@ $(CLI_APIREND): $(OBJS_CLI_APPREND) $(LIB_LIBREND) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(CLI_APIPOSTREND): $(OBJS_CLI_APPPOSTREND) $(LIB_LIBISAR) $(LIB_LIBCOM) $(LIB_LIBUTIL) $(LIB_LIBDEBUG) $(LIB_LC3PLUS) $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPPOSTREND) -L. -lisar -livasutil -livasdebug -livascom -llc3plus $(LDLIBS) -o $(CLI_APIPOSTREND) +$(CLI_AMBICONVERT): $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) $(LDLIBS) -o $(CLI_AMBICONVERT) + libs: $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(LIB_LIBUTIL) clean: $(QUIET)$(RM) $(OBJS_LIBENC) $(OBJS_LIBDEC) $(DEPS) $(QUIET)$(RM) $(DEPS:.P=.d) $(QUIET)test ! -d $(OBJDIR) || rm -rf $(OBJDIR) - $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) + $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(OBJDIR)/%.o : %.c | $(OBJDIR) $(QUIET_CC)$(CC) $(CFLAGS) -c -MD -o $@ $< diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln index ac2e76b52f0224eefb2fb6c56cbd2a41be66812c..6a38a0e4304fea3680886ea0b2080bfd04630b34 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -31,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lib_isar", "lib_isar.vcxpro EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "isar_post_rend", "isar_post_rend.vcxproj", "{12374ADC-0E5C-4FDD-B903-71D572413831}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ambi_converter", "ambi_converter.vcxproj", "{2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -111,6 +113,12 @@ Global {12374ADC-0E5C-4FDD-B903-71D572413831}.Release|Win32.ActiveCfg = Release|Win32 {12374ADC-0E5C-4FDD-B903-71D572413831}.Release|Win32.Build.0 = Release|Win32 {12374ADC-0E5C-4FDD-B903-71D572413831}.Release|x64.ActiveCfg = Release|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Debug|Win32.ActiveCfg = Debug|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Debug|Win32.Build.0 = Debug|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Debug|x64.ActiveCfg = Debug|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Release|Win32.ActiveCfg = Release|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Release|Win32.Build.0 = Release|Win32 + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Workspace_msvc/ambi_converter.vcxproj b/Workspace_msvc/ambi_converter.vcxproj new file mode 100644 index 0000000000000000000000000000000000000000..5a489f378675bb26ca5e2f6c65204bce29e63537 --- /dev/null +++ b/Workspace_msvc/ambi_converter.vcxproj @@ -0,0 +1,166 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + ambi_converter + {2074FFD6-8056-4C5F-8A08-0B2607D1FEFF} + renderer + 10.0.17763.0 + + + + Application + v141 + false + MultiByte + + + Application + v141 + false + MultiByte + + + + + + + + + + + + + + + <_ProjectFileVersion>15.0.27428.2015 + + + ..\ + .\Debug_$(ProjectName)\ + false + false + ambi_converter + + + ..\ + .\Release_$(ProjectName)\ + false + false + ambi_converter + + + + $(IntDir)$(ProjectName).tlb + + + + Disabled + ..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) + + EnableFastChecks + MultiThreadedDebug + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + OldStyle + Default + %(DisableSpecificWarnings) + false + + + _DEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + + $(OutDir)$(TargetName).exe + true + + true + $(IntDir)$(ProjectName).pdb + Console + false + + MachineX86 + + + + + $(IntDir)$(ProjectName).tlb + + + + MaxSpeed + AnySuitable + false + Neither + false + false + ..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions) + true + + Default + MultiThreaded + true + Precise + false + + + $(IntDir)$(ProjectName).pdb + Level4 + true + + Default + %(DisableSpecificWarnings) + false + + + NDEBUG;%(PreprocessorDefinitions) + 0x0c0c + + + $(OutDir)$(TargetName).exe + true + + false + $(IntDir)$(ProjectName).pdb + Console + false + + MachineX86 + libcmtd.lib + + + + + + + + {2FA8F384-0775-F3B7-F8C3-85209222FC70} + false + + + + + + + + + + + \ No newline at end of file diff --git a/Workspace_msvc/lib_util.vcxproj b/Workspace_msvc/lib_util.vcxproj index 79e5545f3fee266b8433f1b74a1926d40b570aa5..12dfa7610686a14b0f6fb63967747c6ddd745173 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -100,6 +100,7 @@ + @@ -163,4 +164,4 @@ - \ No newline at end of file + diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c new file mode 100644 index 0000000000000000000000000000000000000000..ea880d26a95507365b016dcc7910b18e89412a56 --- /dev/null +++ b/apps/ambi_converter.c @@ -0,0 +1,192 @@ +/****************************************************************************************************** + + (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 +#include +#include +#include +#include "tinywavein_c.h" +#include "tinywaveout_c.h" +#include "ambi_convert.h" + +/*-------------------------------------------------------------------------------------* + * Ambisonics converter program + * + * gcc ambi_converter.c ../lib_util/ambi_convert.c -I../lib_util/ -lm -o ambi_converter + *--------------------------------------------------------------------------------------*/ + +int main( int argc, char *argv[] ) +{ + + WAVEFILEIN *wavFile_in; + WAVEFILEOUT *wavFile_out; + char *fileName_in, *fileName_out; + + uint32_t samplingRate; + uint32_t samplesInFile; + uint32_t numSamples = AMBI_MAX_FRAME_LENGTH; + uint32_t numSamplesRead32 = 0; + uint32_t numSamplesClipped = 0; + + int16_t bps; + int16_t samples[AMBI_MAX_FRAME_LENGTH * AMBI_MAX_CHANNELS]; + int16_t order = 0; + int16_t numChannels; + const char *name_conventions[6] = { "ACN-SN3D", "ACN-N3D", "FuMa-MaxN", "FuMa-FuMa", "SID-SN3D", "SID-N3D" }; + + AMBI_FMT in_format, out_format; + + float samples_f_in[AMBI_MAX_FRAME_LENGTH * AMBI_MAX_CHANNELS]; + float samples_f_out[AMBI_MAX_FRAME_LENGTH * AMBI_MAX_CHANNELS]; + float *in[AMBI_MAX_CHANNELS], *out[AMBI_MAX_CHANNELS]; + + for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) + { + in[j] = &samples_f_in[j * AMBI_MAX_FRAME_LENGTH]; + out[j] = &samples_f_out[j * AMBI_MAX_FRAME_LENGTH]; + } + + printf( "Ambisonics converter program\n" ); + if ( argc != 5 ) + { + printf( "----------------------------------------------------------------------------------\n" ); + printf( "Usage:\n" ); + printf( "./ambi_converter input_file output_file input_convention output_convention\n" ); + printf( "\n" ); + printf( "input_convention and output convention must be an integer number in [0,5]\n" ); + printf( "the following conventions are supported:\n" ); + printf( "0 : ACN-SN3D\n" ); + printf( "1 : ACN-N3D\n" ); + printf( "2 : FuMa-MaxN\n" ); + printf( "3 : FuMa-FuMa\n" ); + printf( "4 : SID-SN3D\n" ); + printf( "5 : SID-N3D\n" ); + printf( "\n" ); + printf( "Either the input or the output convention must always be ACN-SN3D!\n" ); + return -1; + } + + fileName_in = argv[1]; + fileName_out = argv[2]; + in_format = atoi( argv[3] ); + out_format = atoi( argv[4] ); + if ( in_format < 0 || out_format < 0 || in_format > 5 || out_format > 5 ) + { + printf( "input_convention and output convention must be an integer number in [0,5]\n" ); + return -1; + } + printf( "In: [%s], Out: [%s]\n", name_conventions[in_format], name_conventions[out_format] ); + + wavFile_in = OpenWav( fileName_in, &samplingRate, &numChannels, &samplesInFile, &bps ); + if ( !wavFile_in ) + { + fprintf( stderr, "Failed to open input wav file: %s\n", fileName_in ); + return -1; + } + + wavFile_out = CreateWav( fileName_out, samplingRate, numChannels, 16 ); + if ( !wavFile_out ) + { + fprintf( stderr, "Failed to open output wav file: %s\n", fileName_out ); + return -1; + } + + order = (int16_t) sqrtf( numChannels ) - 1; + assert( order > 0 && order <= 3 ); + + numSamples = ( samplingRate * 20 * numChannels ) / 1000; /* 20ms worth of samples */ + while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) + { + int32_t err = 0; + + if ( !numSamplesRead32 ) + { + break; + } + + for ( uint16_t i = 0; i < (uint16_t) numSamplesRead32 / numChannels; i++ ) + { + for ( int16_t j = 0; j < numChannels; j++ ) + { + in[j][i] = (float) samples[i * numChannels + j]; + } + } + + if ( ( err = convert_ambi_format( in, out, order, in_format, out_format, ( const uint16_t )( numSamples / numChannels ) ) ) != 0 ) + { + printf( "Error converting the input signal!\n" ); + return err; + } + + + for ( uint16_t i = 0; i < (uint16_t) numSamplesRead32 / numChannels; i++ ) + { + for ( int16_t j = 0; j < numChannels; j++ ) + { + int16_t s1_i; + float s1 = out[j][i]; + if ( s1 < INT16_MIN ) + { + s1_i = INT16_MIN; + numSamplesClipped++; + } + else if ( s1 > INT16_MAX ) + { + s1_i = INT16_MAX; + numSamplesClipped++; + } + else + { + s1_i = (int16_t) s1; + } + samples[i * numChannels + j] = s1_i; + } + } + + if ( ( err = WriteWavShort( wavFile_out, samples, numSamplesRead32 ) ) != __TWO_SUCCESS ) + { + printf( "Error writing output wave file!\n" ); + return err; + } + + numSamplesRead32 = 0; + } + + CloseWav( wavFile_out ); + CloseWavIn( wavFile_in ); + + if ( numSamplesClipped ) + { + printf( "Warning: %d samples have clipped!\n", numSamplesClipped ); + } + + return 0; +} diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 282f4a08726273423d57d4986c8cad17d2666b1e..e91dd0f989bd0fcd62e6f0a19a7eb79ef490f759 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -124,15 +124,16 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR convert_ambi_format( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_FMT in_format, /* i: input ambisonics format */ + const AMBI_FMT out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ) { - float tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; + float tmp[AMBI_MAX_CHANNELS * AMBI_MAX_FRAME_LENGTH]; float *p_tmp[AMBI_MAX_CHANNELS]; AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; @@ -144,6 +145,11 @@ AMBI_CONVERT_ERROR convert_ambi_format( assert( order <= 3 ); + if ( frame_length > AMBI_MAX_FRAME_LENGTH ) + { + return AMBI_CONVERT_UNSUPPORTED_FRAME_LENGTH; + } + if ( in_format != AMBI_FMT_ACN_SN3D && out_format != AMBI_FMT_ACN_SN3D ) { assert( 0 && "Conversion only supported to and from ACN-SN3D" ); @@ -151,7 +157,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) { - p_tmp[j] = &tmp[j * L_FRAME48k]; + p_tmp[j] = &tmp[j * frame_length]; } switch ( in_format ) @@ -218,18 +224,18 @@ AMBI_CONVERT_ERROR convert_ambi_format( { 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, frame_length ) ) != 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } } 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } @@ -237,7 +243,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } @@ -246,18 +252,18 @@ AMBI_CONVERT_ERROR convert_ambi_format( { 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, frame_length ) ) != 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } } 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } @@ -265,7 +271,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } 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, frame_length ) ) != AMBI_CONVERT_OK ) { return err; } @@ -278,7 +284,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { int16_t i = 0; - for ( i = 0; i < L_FRAME48k; i++ ) + for ( i = 0; i < frame_length; i++ ) { out[i_chan][i] = in[i_chan][i]; } @@ -299,11 +305,12 @@ AMBI_CONVERT_ERROR convert_ambi_format( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR renormalize_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + const AMBI_CHANNEL_NORM out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); @@ -358,7 +365,7 @@ AMBI_CONVERT_ERROR renormalize_channels( for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { float conversion_factor = conversion_table[i_chan]; - for ( i = 0; i < L_FRAME48k; i++ ) + for ( i = 0; i < frame_length; i++ ) { out[i_chan][i] = in[i_chan][i] * conversion_factor; } @@ -374,11 +381,12 @@ AMBI_CONVERT_ERROR renormalize_channels( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR reorder_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + const AMBI_CHANNEL_ORDER out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ) { int16_t n_chan = ( order + 1 ) * ( order + 1 ); @@ -421,7 +429,7 @@ AMBI_CONVERT_ERROR reorder_channels( return AMBI_CONVERT_UNSUPPORTED_CONVERSION; } - for ( i = 0; i < L_FRAME48k; i++ ) + for ( i = 0; i < frame_length; i++ ) { for ( i_chan = 0; i_chan < n_chan; i_chan++ ) { diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 825d65127c3a1e8bd922d68f737ab1258390679e..1b2ffb8c607acc39a812b67b20c250a2b564d7ed 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -35,8 +35,8 @@ #include -#define L_FRAME48k 960 -#define AMBI_MAX_CHANNELS 16 +#define AMBI_MAX_FRAME_LENGTH 960 /* 20ms at 48 kHz Sampling rate */ +#define AMBI_MAX_CHANNELS 16 typedef enum { @@ -66,30 +66,34 @@ typedef enum typedef enum { AMBI_CONVERT_OK = 0, - AMBI_CONVERT_UNSUPPORTED_CONVERSION + AMBI_CONVERT_UNSUPPORTED_CONVERSION, + AMBI_CONVERT_UNSUPPORTED_FRAME_LENGTH } 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 */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_FMT in_format, /* i: input ambisonics format */ + const AMBI_FMT out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ); AMBI_CONVERT_ERROR renormalize_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ + const AMBI_CHANNEL_NORM out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ); AMBI_CONVERT_ERROR reorder_channels( - float *in[], /* i: input ambisonics channels */ - float *out[], /* o: output ambisonics channels */ - int16_t order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ + float *in[], /* i: input ambisonics channels */ + float *out[], /* o: output ambisonics channels */ + const int16_t order, /* i: ambisonics order */ + const AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ + const AMBI_CHANNEL_ORDER out_format, /* i: output ambisonics format */ + const int16_t frame_length /* i: input/output frame length */ ); #endif