From d453510db32bbbd47e9647f0c1ff0952f7320851 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sat, 20 Sep 2025 21:00:24 +0200 Subject: [PATCH 01/13] add ambi_converter demo program --- CMakeLists.txt | 7 + Makefile | 9 +- Workspace_msvc/Workspace_msvc.sln | 11 ++ Workspace_msvc/ambi_converter.vcxproj | 169 ++++++++++++++++++++++ Workspace_msvc/lib_util.vcxproj | 7 +- apps/ambi_converter.c | 193 ++++++++++++++++++++++++++ lib_util/ambi_convert.c | 7 +- 7 files changed, 395 insertions(+), 8 deletions(-) create mode 100644 Workspace_msvc/ambi_converter.vcxproj create mode 100644 apps/ambi_converter.c mode change 100644 => 100755 lib_util/ambi_convert.c diff --git a/CMakeLists.txt b/CMakeLists.txt index ecd8f11c5..6d165c472 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 lib_com) +if(UNIX) + target_link_libraries(ambi_converter m) +endif() +target_include_directories(ambi_converter PRIVATE lib_util lib_com) + 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 62306b674..bb5892856 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,3 @@ - # GNU Makefile # Paths @@ -23,6 +22,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 @@ -170,10 +170,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) \ @@ -238,13 +240,16 @@ ifeq "$(INCLUDE_SPLIT)" "1" $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPPOSTREND) -L. -lisar -livasutil -livasdebug -livascom -llc3plus $(LDLIBS) -o $(CLI_APIPOSTREND) endif +$(CLI_AMBICONVERT): $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) $(LIB_LIBCOM) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) -L. -livascom $(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 ac2e76b52..14657b0c0 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -31,6 +31,11 @@ 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}" + ProjectSection(ProjectDependencies) = postProject + {39EC200D-7795-4FF8-B214-B24EDA5526AE} = {39EC200D-7795-4FF8-B214-B24EDA5526AE} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -111,6 +116,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 000000000..a9884f12c --- /dev/null +++ b/Workspace_msvc/ambi_converter.vcxproj @@ -0,0 +1,169 @@ + + + + + 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_enc;..\lib_dec;..\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_enc;..\lib_dec;..\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 + + + + + + + + {39ec200d-7795-4ff8-b214-b24eda5526ae} + + + {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 b6b7fedfa..ab86c9eee 100644 --- a/Workspace_msvc/lib_util.vcxproj +++ b/Workspace_msvc/lib_util.vcxproj @@ -100,6 +100,7 @@ + @@ -123,7 +124,7 @@ - + @@ -150,7 +151,7 @@ - + @@ -160,4 +161,4 @@ - + \ No newline at end of file diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c new file mode 100644 index 000000000..63ccadc7b --- /dev/null +++ b/apps/ambi_converter.c @@ -0,0 +1,193 @@ +/****************************************************************************************************** + + (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 "../lib_util/tinywavein_c.h" +#include "../lib_util/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 = L_FRAME48k; + uint32_t numSamplesRead32 = 0; + //uint32_t numSamplesClipped = 0; + uint32_t numFramesClipped = 0; + + int16_t bps; + int16_t samples[L_FRAME48k * AMBI_MAX_CHANNELS]; + int16_t order = 0; + int16_t numChannels; + + AMBI_FMT in_format, out_format; + + Word16 samples_f_in[L_FRAME48k * AMBI_MAX_CHANNELS]; + Word16 samples_f_out[L_FRAME48k * AMBI_MAX_CHANNELS]; + Word16 *in[AMBI_MAX_CHANNELS], *out[AMBI_MAX_CHANNELS]; + + for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) + { + in[j] = &samples_f_in[j * L_FRAME48k]; + out[j] = &samples_f_out[j * L_FRAME48k]; + } + + if ( argc != 5 ) + { + printf( "Ambisonics converter program\n" ); + 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] ); + + printf( "In %d, Out: %d\n", in_format, 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 ); + + while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) + { + int32_t err = 0; + + if ( !numSamplesRead32 ) + { + break; + } + + for ( uint16_t i = 0; i < numSamplesRead32; i++ ) + { + for ( int16_t j = 0; j < numChannels; j++ ) + { + in[j][i] = (Word16) samples[i * numChannels + j]; + } + } + + err = convert_ambi_format( in, out, order, in_format, out_format ); + if ( err == AMBI_CONVERT_CLIPPING_DETECTED ) + { + numFramesClipped++; + } + else if ( err != 0 ) + { + printf( "Error converting the input signal!\n" ); + return err; + } + + + for ( uint16_t i = 0; i < numSamplesRead32; i++ ) + { + for ( int16_t j = 0; j < numChannels; j++ ) + { + //int s1_i; + //Word16 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; + samples[i * numChannels + j] = out[j][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 ( numFramesClipped ) + { + printf( "Warning: %d frames have clipped!\n", numFramesClipped ); + } + + return 0; +} diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c old mode 100644 new mode 100755 index 0bf2bf226..6fd03ac8d --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -34,6 +34,7 @@ #include #include "wmc_auto.h" #include "ambi_convert.h" +#include "stl.h" #define ONE_1_Q29 536870912l /* 1.0f */ #define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */ @@ -311,11 +312,11 @@ AMBI_CONVERT_ERROR convert_ambi_format( FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { - int16_t i = 0; + int16_t i_s = 0; move16(); - FOR( i = 0; i < L_FRAME48k; i++ ) + FOR( i_s = 0; i_s < L_FRAME48k; i_s++ ) { - out[i_chan][i] = in[i_chan][i]; + out[i_chan][i_s] = in[i_chan][i_s]; move16(); } } -- GitLab From 00a8c57db9097a294b57afddce4a5c5591f491a8 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sat, 20 Sep 2025 21:54:04 +0200 Subject: [PATCH 02/13] formatting --- apps/ambi_converter.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 63ccadc7b..a1ac955fa 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -54,7 +54,7 @@ int main( int argc, char *argv[] ) uint32_t samplesInFile; uint32_t numSamples = L_FRAME48k; uint32_t numSamplesRead32 = 0; - //uint32_t numSamplesClipped = 0; + // uint32_t numSamplesClipped = 0; uint32_t numFramesClipped = 0; int16_t bps; @@ -151,23 +151,23 @@ int main( int argc, char *argv[] ) { for ( int16_t j = 0; j < numChannels; j++ ) { - //int s1_i; - //Word16 s1 = out[j][i]; - //if ( s1 < INT16_MIN ) + // int s1_i; + // Word16 s1 = out[j][i]; + // if ( s1 < INT16_MIN ) //{ - // s1_i = INT16_MIN; - // numSamplesClipped++; - //} - //else if ( s1 > INT16_MAX ) + // s1_i = INT16_MIN; + // numSamplesClipped++; + // } + // else if ( s1 > INT16_MAX ) //{ - // s1_i = INT16_MAX; - // numSamplesClipped++; - //} - //else + // s1_i = INT16_MAX; + // numSamplesClipped++; + // } + // else //{ - // s1_i = (int16_t) s1; - //} - //samples[i * numChannels + j] = s1_i; + // s1_i = (int16_t) s1; + // } + // samples[i * numChannels + j] = s1_i; samples[i * numChannels + j] = out[j][i]; } } -- GitLab From efa0e3fda9fec7d8483efa2a4d2eae8d12a706c6 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 26 Sep 2025 13:52:58 +0200 Subject: [PATCH 03/13] the ambi_converter app is reading the correct amount of samples per frame now. --- apps/ambi_converter.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index a1ac955fa..7d37040a1 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -118,6 +118,7 @@ int main( int argc, char *argv[] ) order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); + numSamples = L_FRAME48k * numChannels; while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int32_t err = 0; @@ -127,7 +128,7 @@ int main( int argc, char *argv[] ) break; } - for ( uint16_t i = 0; i < numSamplesRead32; i++ ) + for ( uint16_t i = 0; i < numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { @@ -147,7 +148,7 @@ int main( int argc, char *argv[] ) } - for ( uint16_t i = 0; i < numSamplesRead32; i++ ) + for ( uint16_t i = 0; i < numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { -- GitLab From 30f3b2de8dce03c0891fff9dea092309b005d1da Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 26 Sep 2025 14:01:00 +0200 Subject: [PATCH 04/13] Removed a warning in the main() function of the ambi_converter, where a 16 bit value was compared to a 32 bit value. --- apps/ambi_converter.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 7d37040a1..7dc4ebe76 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -128,7 +128,7 @@ int main( int argc, char *argv[] ) break; } - for ( uint16_t i = 0; i < numSamplesRead32 / numChannels; i++ ) + for ( uint16_t i = 0; i < (uint16_t)numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { @@ -148,7 +148,7 @@ int main( int argc, char *argv[] ) } - for ( uint16_t i = 0; i < numSamplesRead32 / numChannels; i++ ) + for ( uint16_t i = 0; i < (uint16_t)numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { -- GitLab From 782439be3e63a387770a3447b7946a35b0f5e0da Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 26 Sep 2025 14:30:21 +0200 Subject: [PATCH 05/13] changed the output of the ambi_converter application --- apps/ambi_converter.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 7dc4ebe76..88626e994 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -61,6 +61,7 @@ int main( int argc, char *argv[] ) int16_t samples[L_FRAME48k * 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; @@ -74,9 +75,9 @@ int main( int argc, char *argv[] ) out[j] = &samples_f_out[j * L_FRAME48k]; } + printf( "Ambisonics converter program\n" ); if ( argc != 5 ) { - printf( "Ambisonics converter program\n" ); printf( "----------------------------------------------------------------------------------\n" ); printf( "Usage:\n" ); printf( "./ambi_converter input_file output_file input_convention output_convention\n" ); @@ -98,8 +99,12 @@ int main( int argc, char *argv[] ) fileName_out = argv[2]; in_format = atoi( argv[3] ); out_format = atoi( argv[4] ); - - printf( "In %d, Out: %d\n", in_format, out_format ); + 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 ) -- GitLab From 8a11c97aedcac211b465b6c076329187c60a00f0 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Fri, 26 Sep 2025 14:42:31 +0200 Subject: [PATCH 06/13] applied the clang patch. --- apps/ambi_converter.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 88626e994..8681b5558 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -61,7 +61,7 @@ int main( int argc, char *argv[] ) int16_t samples[L_FRAME48k * 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" }; + const char *name_conventions[6] = { "ACN-SN3D", "ACN-N3D", "FuMa-MaxN", "FuMa-FuMa", "SID-SN3D", "SID-N3D" }; AMBI_FMT in_format, out_format; @@ -104,7 +104,7 @@ int main( int argc, char *argv[] ) 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] ); + 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 ) @@ -133,7 +133,7 @@ int main( int argc, char *argv[] ) break; } - for ( uint16_t i = 0; i < (uint16_t)numSamplesRead32 / numChannels; i++ ) + for ( uint16_t i = 0; i < (uint16_t) numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { @@ -153,7 +153,7 @@ int main( int argc, char *argv[] ) } - for ( uint16_t i = 0; i < (uint16_t)numSamplesRead32 / numChannels; i++ ) + for ( uint16_t i = 0; i < (uint16_t) numSamplesRead32 / numChannels; i++ ) { for ( int16_t j = 0; j < numChannels; j++ ) { -- GitLab From 489494e7235199654d5a67e4002de0622cabc855 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 28 Sep 2025 17:26:01 +0200 Subject: [PATCH 07/13] fix Makefile --- Makefile | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index d9ddbf795..ab55a322d 100644 --- a/Makefile +++ b/Makefile @@ -247,24 +247,16 @@ ifeq "$(INCLUDE_SPLIT)" "1" $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_APPPOSTREND) -L. -livasbasop -lisar -livasutil -livasdebug -livascom -llc3plus $(LDLIBS) -o $(CLI_APIPOSTREND) endif -<<<<<<< HEAD -$(CLI_AMBICONVERT): $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) $(LIB_LIBCOM) - $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) -L. -livascom $(LDLIBS) -o $(CLI_AMBICONVERT) +$(CLI_AMBICONVERT): $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) $(LIB_LIBBASOP) $(LIB_LIBCOM) + $(QUIET_LINK)$(CC) $(LDFLAGS) $(OBJS_CLI_AMBICONVERT) $(OBJS_AMBICONVERT) -L. -livascom -livasbasop $(LDLIBS) -o $(CLI_AMBICONVERT) -libs: $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(LIB_LIBUTIL) -======= libs: $(LIB_LIBBASOP) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(LIB_LIBUTIL) ->>>>>>> main clean: $(QUIET)$(RM) $(OBJS_LIBENC) $(OBJS_LIBDEC) $(DEPS) $(QUIET)$(RM) $(DEPS:.P=.d) $(QUIET)test ! -d $(OBJDIR) || rm -rf $(OBJDIR) -<<<<<<< HEAD - $(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) -======= - $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(OBJS_LIBBASOP) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) ->>>>>>> main + $(QUIET)$(RM) $(CLI_APIENC) $(CLI_APIDEC) $(CLI_APIREND) $(CLI_APIPOSTREND) $(CLI_AMBICONVERT) $(LIB_LIBENC) $(LIB_LIBDEBUG) $(OBJS_LIBBASOP) $(LIB_LIBCOM) $(LIB_LIBDEC) $(LIB_LIBUTIL) $(LIB_LIBREND) $(LIB_LIBISAR) $(LIB_LC3PLUS) $(OBJDIR)/%.o : %.c | $(OBJDIR) $(QUIET_CC)$(CC) $(CFLAGS) -c -MD -o $@ $< -- GitLab From fc50a35c070d70193d6a461907eec348a9713684 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 28 Sep 2025 18:06:18 +0200 Subject: [PATCH 08/13] cleanup includes, remove remaining intXX_t types --- CMakeLists.txt | 4 +-- apps/ambi_converter.c | 1 - lib_util/ambi_convert.c | 54 ++++++++++++++++++++--------------------- lib_util/ambi_convert.h | 15 ++++-------- 4 files changed, 34 insertions(+), 40 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 082956f0e..ab640932f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -216,11 +216,11 @@ target_link_libraries(ISAR_post_rend lib_basop lib_isar lib_util lib_com) target_include_directories(ISAR_post_rend PRIVATE lib_basop lib_isar) add_executable(ambi_converter apps/ambi_converter.c) - target_link_libraries(ambi_converter lib_util lib_com) +target_link_libraries(ambi_converter lib_util lib_com lib_basop) if(UNIX) target_link_libraries(ambi_converter m) endif() -target_include_directories(ambi_converter PRIVATE lib_util lib_com) +target_include_directories(ambi_converter PRIVATE lib_basop lib_util lib_com lib_debug) 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) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 8681b5558..202916918 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "../lib_util/tinywavein_c.h" #include "../lib_util/tinywaveout_c.h" #include "ambi_convert.h" diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 6fd03ac8d..1f915371e 100755 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -32,9 +32,9 @@ #include #include -#include "wmc_auto.h" -#include "ambi_convert.h" #include "stl.h" +#include "ambi_convert.h" +#include "wmc_auto.h" #define ONE_1_Q29 536870912l /* 1.0f */ #define ONE_OVER_2_Q29 268435456l /* 1.0f/2.0f */ @@ -99,25 +99,25 @@ static const Word32 FM_SN3D[AMBI_MAX_CHANNELS] = { SQRT_2_Q29, 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 Word16 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, +static const Word16 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 Word16 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 }; +static const Word16 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 @@ -132,7 +132,7 @@ static const int16_t REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, AMBI_CONVERT_ERROR convert_ambi_format( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_FMT in_format, /* i: input ambisonics format */ AMBI_FMT out_format /* i: output ambisonics format */ ) @@ -307,12 +307,12 @@ AMBI_CONVERT_ERROR convert_ambi_format( } 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 ) ); + Word16 i_chan = 0; + Word16 n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { - int16_t i_s = 0; + Word16 i_s = 0; move16(); FOR( i_s = 0; i_s < L_FRAME48k; i_s++ ) { @@ -338,13 +338,13 @@ AMBI_CONVERT_ERROR convert_ambi_format( AMBI_CONVERT_ERROR renormalize_channels( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ) { - int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); - int16_t i_chan, i; + Word16 n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); + Word16 i_chan, i; const Word32 *conversion_table = 0; Word32 minval = 0; Word32 maxval = 0; @@ -436,15 +436,15 @@ AMBI_CONVERT_ERROR renormalize_channels( AMBI_CONVERT_ERROR reorder_channels( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ ) { - int16_t n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); - int16_t i_chan, i; + Word16 n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); + Word16 i_chan, i; Word16 tmp[AMBI_MAX_CHANNELS]; - const int16_t *idx_table = 0; + const Word16 *idx_table = 0; IF( in_format == AMBI_CHANNEL_ORDER_ACN ) { @@ -489,7 +489,7 @@ AMBI_CONVERT_ERROR reorder_channels( { FOR( i_chan = 0; i_chan < n_chan; i_chan++ ) { - int16_t idx = idx_table[i_chan]; + Word16 idx = idx_table[i_chan]; move16(); tmp[i_chan] = in[idx][i]; move16(); diff --git a/lib_util/ambi_convert.h b/lib_util/ambi_convert.h index 207bd276f..b1e5d1ec0 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -33,14 +33,9 @@ #ifndef AMBI_CONVERT_H #define AMBI_CONVERT_H -#include #include "options.h" -#include "prot_fx.h" -#include "ivas_cnst.h" -#include -#include "wmc_auto.h" -#include "ivas_prot_fx.h" - +#include "stl.h" +#include "cnst.h" #define L_FRAME48k 960 #define AMBI_MAX_CHANNELS 16 @@ -80,7 +75,7 @@ typedef enum AMBI_CONVERT_ERROR convert_ambi_format( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_FMT in_format, /* i: input ambisonics format */ AMBI_FMT out_format /* i: output ambisonics format */ ); @@ -88,7 +83,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( AMBI_CONVERT_ERROR renormalize_channels( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ ); @@ -96,7 +91,7 @@ AMBI_CONVERT_ERROR renormalize_channels( AMBI_CONVERT_ERROR reorder_channels( Word16 *in[], /* i: input ambisonics channels, Q0 */ Word16 *out[], /* o: output ambisonics channels, Q0 */ - int16_t order, /* i: ambisonics order */ + Word16 order, /* i: ambisonics order */ AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ ); -- GitLab From 198236fa04e54b084e157bbedbde216ee233f3e2 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 28 Sep 2025 19:33:20 +0200 Subject: [PATCH 09/13] formatting --- lib_util/ambi_convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100755 => 100644 lib_util/ambi_convert.c diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c old mode 100755 new mode 100644 index 1f915371e..41bf32d8e --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -105,9 +105,9 @@ static const Word16 REORDER_FM_ACN[AMBI_MAX_CHANNELS] = { 0, 15, 13, 11, 9, 10, 12, 14 }; static const Word16 REORDER_SID_ACN[AMBI_MAX_CHANNELS] = { 0, - 2, 3, 1, - 5, 7, 8, 6, 4, - 10, 12, 14, 15, 13, 11, 9 }; + 2, 3, 1, + 5, 7, 8, 6, 4, + 10, 12, 14, 15, 13, 11, 9 }; static const Word16 REORDER_ACN_FM[AMBI_MAX_CHANNELS] = { 0, 3, 1, 2, -- GitLab From cf71b878e232852ad712105e100ba6afdfa818b4 Mon Sep 17 00:00:00 2001 From: Markus Multrus Date: Sun, 28 Sep 2025 19:39:29 +0200 Subject: [PATCH 10/13] fix VS dependencies --- Workspace_msvc/Workspace_msvc.sln | 6 ++++++ Workspace_msvc/ambi_converter.vcxproj | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Workspace_msvc/Workspace_msvc.sln b/Workspace_msvc/Workspace_msvc.sln index 430678edc..abb9650fc 100644 --- a/Workspace_msvc/Workspace_msvc.sln +++ b/Workspace_msvc/Workspace_msvc.sln @@ -136,6 +136,12 @@ Global {63747FE7-94BA-410C-8D7F-EB47555DD994}.Release|Win32.ActiveCfg = Release|Win32 {63747FE7-94BA-410C-8D7F-EB47555DD994}.Release|Win32.Build.0 = Release|Win32 {63747FE7-94BA-410C-8D7F-EB47555DD994}.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 index a9884f12c..caedd2c6f 100644 --- a/Workspace_msvc/ambi_converter.vcxproj +++ b/Workspace_msvc/ambi_converter.vcxproj @@ -65,7 +65,7 @@ Disabled - ..\lib_enc;..\lib_dec;..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_basop;..\lib_enc;..\lib_dec;..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;WIN32;$(Macros);%(PreprocessorDefinitions) EnableFastChecks @@ -110,7 +110,7 @@ Neither false false - ..\lib_enc;..\lib_dec;..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) + ..\lib_basop;..\lib_enc;..\lib_dec;..\lib_com;..\lib_debug;..\lib_util;..\lib_isar;..\lib_rend;..\lib_lc3plus;%(AdditionalIncludeDirectories) _CRT_SECURE_NO_WARNINGS;$(Macros);%(PreprocessorDefinitions) true @@ -150,6 +150,9 @@ + + {63747fe7-94ba-410c-8d7f-eb47555dd994} + {39ec200d-7795-4ff8-b214-b24eda5526ae} -- GitLab From 3930f5a833df85f0a416c2622ff00adba370dd94 Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 29 Sep 2025 09:36:21 +0200 Subject: [PATCH 11/13] convert_ambi_format() saturates the samples instead of just returning a warning. --- lib_util/ambi_convert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 41bf32d8e..5831bb4f1 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -417,6 +417,7 @@ AMBI_CONVERT_ERROR renormalize_channels( outval = W_extract_l( W_shr( tmp, Q29 ) ); minval = L_min( minval, outval ); maxval = L_min( maxval, outval ); + outval = L_min( MAX16B, L_max( MIN16B, outval ) ); /* saturation */ out[i_chan][i] = extract_l( outval ); } } -- GitLab From aa67214885a1c2cb832db69666487d15a9b4f7cf Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 29 Sep 2025 09:47:57 +0200 Subject: [PATCH 12/13] in case of clipping, convert_ambi_format() took a shortcut which caused uninitialized output samples. --- lib_util/ambi_convert.c | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 5831bb4f1..4c4b6aae3 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -140,7 +140,8 @@ AMBI_CONVERT_ERROR convert_ambi_format( Word16 tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; Word16 *p_tmp[AMBI_MAX_CHANNELS]; - AMBI_CONVERT_ERROR err = AMBI_CONVERT_OK; + AMBI_CONVERT_ERROR err_normalize = AMBI_CONVERT_OK; + AMBI_CONVERT_ERROR err_reorder = AMBI_CONVERT_OK; AMBI_CHANNEL_ORDER ch_ord_in = AMBI_CHANNEL_ORDER_ACN; AMBI_CHANNEL_ORDER ch_ord_out = AMBI_CHANNEL_ORDER_ACN; @@ -253,56 +254,59 @@ 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 ) + err_normalize = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); + IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { - return err; + return err_normalize; } - IF( ( err = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_reorder = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { - return err; + return err_reorder; } } ELSE { - IF( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { - return err; + return err_normalize; } } } 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 = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { - return err; + return err_reorder; } } ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_norm_in != ch_norm_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 = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { - return err; + return err_reorder; } - IF( ( err = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + err_normalize = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ); + IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { - return err; + return err_normalize; } } ELSE { - IF( ( err = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) { - return err; + return err_normalize; } } } 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 = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) { - return err; + return err_reorder; } } ELSE IF( out_format == AMBI_FMT_ACN_SN3D && in_format == AMBI_FMT_ACN_SN3D ) @@ -326,7 +330,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( assert( 0 && "This should never happen!" ); } - return AMBI_CONVERT_OK; + return err_normalize; } /*-------------------------------------------------------------------------* -- GitLab From 80d92c6c97368f0cec3f598e44f23138fe2e26ad Mon Sep 17 00:00:00 2001 From: Thomas Dettbarn Date: Mon, 29 Sep 2025 12:56:54 +0200 Subject: [PATCH 13/13] ambi_converter() takes frame_length as input and can be used for samplerates other than 48 kHz. --- apps/ambi_converter.c | 16 +++++------ lib_util/ambi_convert.c | 64 +++++++++++++++++++++++------------------ lib_util/ambi_convert.h | 38 +++++++++++++----------- 3 files changed, 65 insertions(+), 53 deletions(-) diff --git a/apps/ambi_converter.c b/apps/ambi_converter.c index 202916918..76619c904 100644 --- a/apps/ambi_converter.c +++ b/apps/ambi_converter.c @@ -51,27 +51,27 @@ int main( int argc, char *argv[] ) uint32_t samplingRate; uint32_t samplesInFile; - uint32_t numSamples = L_FRAME48k; + uint32_t numSamples = AMBI_MAX_FRAME_LENGTH; uint32_t numSamplesRead32 = 0; // uint32_t numSamplesClipped = 0; uint32_t numFramesClipped = 0; int16_t bps; - int16_t samples[L_FRAME48k * AMBI_MAX_CHANNELS]; + 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; - Word16 samples_f_in[L_FRAME48k * AMBI_MAX_CHANNELS]; - Word16 samples_f_out[L_FRAME48k * AMBI_MAX_CHANNELS]; + Word16 samples_f_in[AMBI_MAX_FRAME_LENGTH * AMBI_MAX_CHANNELS]; + Word16 samples_f_out[AMBI_MAX_FRAME_LENGTH * AMBI_MAX_CHANNELS]; Word16 *in[AMBI_MAX_CHANNELS], *out[AMBI_MAX_CHANNELS]; for ( int16_t j = 0; j < AMBI_MAX_CHANNELS; j++ ) { - in[j] = &samples_f_in[j * L_FRAME48k]; - out[j] = &samples_f_out[j * L_FRAME48k]; + 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" ); @@ -122,7 +122,7 @@ int main( int argc, char *argv[] ) order = (int16_t) sqrtf( numChannels ) - 1; assert( order > 0 && order <= 3 ); - numSamples = L_FRAME48k * numChannels; + numSamples = ( samplingRate * 20 * numChannels ) / 1000; /* 20ms worth of samples */ while ( ReadWavShort( wavFile_in, samples, numSamples, &numSamplesRead32 ) == __TWI_SUCCESS ) { int32_t err = 0; @@ -140,7 +140,7 @@ int main( int argc, char *argv[] ) } } - err = convert_ambi_format( in, out, order, in_format, out_format ); + err = convert_ambi_format( in, out, order, in_format, out_format, ( const uint16_t )( numSamples / numChannels ) ); if ( err == AMBI_CONVERT_CLIPPING_DETECTED ) { numFramesClipped++; diff --git a/lib_util/ambi_convert.c b/lib_util/ambi_convert.c index 4c4b6aae3..430d7ade2 100644 --- a/lib_util/ambi_convert.c +++ b/lib_util/ambi_convert.c @@ -130,15 +130,16 @@ static const Word16 REORDER_ACN_SID[AMBI_MAX_CHANNELS] = { 0, --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR convert_ambi_format( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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 */ ) { - Word16 tmp[AMBI_MAX_CHANNELS * L_FRAME48k]; + Word16 tmp[AMBI_MAX_CHANNELS * AMBI_MAX_FRAME_LENGTH]; Word16 *p_tmp[AMBI_MAX_CHANNELS]; AMBI_CONVERT_ERROR err_normalize = AMBI_CONVERT_OK; AMBI_CONVERT_ERROR err_reorder = AMBI_CONVERT_OK; @@ -153,6 +154,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" ); @@ -163,7 +169,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( { p_tmp[j] = &tmp[i]; move32(); - i = add( i, L_FRAME48k ); + i = add( i, frame_length ); } SWITCH( in_format ) @@ -254,19 +260,19 @@ AMBI_CONVERT_ERROR convert_ambi_format( { IF( ch_ord_in != ch_ord_out ) { - err_normalize = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out ); + err_normalize = renormalize_channels( in, p_tmp, order, ch_norm_in, ch_norm_out, frame_length ); IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { return err_normalize; } - IF( ( err_reorder = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_reorder = reorder_channels( p_tmp, out, order, ch_ord_in, ch_ord_out, frame_length ) ) != AMBI_CONVERT_OK ) { return err_reorder; } } ELSE { - err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ); + err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out, frame_length ); IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { return err_normalize; @@ -275,7 +281,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } ELSE IF( in_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - IF( ( err_reorder = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_reorder = reorder_channels( in, out, order, ch_ord_in, ch_ord_out, frame_length ) ) != AMBI_CONVERT_OK ) { return err_reorder; } @@ -284,11 +290,11 @@ AMBI_CONVERT_ERROR convert_ambi_format( { IF( ch_ord_in != ch_ord_out ) { - IF( ( err_reorder = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_reorder = reorder_channels( in, p_tmp, order, ch_ord_in, ch_ord_out, frame_length ) ) != AMBI_CONVERT_OK ) { return err_reorder; } - err_normalize = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out ); + err_normalize = renormalize_channels( p_tmp, out, order, ch_norm_in, ch_norm_out, frame_length ); IF( ( err_normalize != AMBI_CONVERT_OK ) && ( err_normalize != AMBI_CONVERT_CLIPPING_DETECTED ) ) { return err_normalize; @@ -296,7 +302,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } ELSE { - IF( ( err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_normalize = renormalize_channels( in, out, order, ch_norm_in, ch_norm_out, frame_length ) ) != AMBI_CONVERT_OK ) { return err_normalize; } @@ -304,7 +310,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( } ELSE IF( out_format == AMBI_FMT_ACN_SN3D && ch_ord_in != ch_ord_out ) { - IF( ( err_reorder = reorder_channels( in, out, order, ch_ord_in, ch_ord_out ) ) != AMBI_CONVERT_OK ) + IF( ( err_reorder = reorder_channels( in, out, order, ch_ord_in, ch_ord_out, frame_length ) ) != AMBI_CONVERT_OK ) { return err_reorder; } @@ -318,7 +324,7 @@ AMBI_CONVERT_ERROR convert_ambi_format( { Word16 i_s = 0; move16(); - FOR( i_s = 0; i_s < L_FRAME48k; i_s++ ) + FOR( i_s = 0; i_s < frame_length; i_s++ ) { out[i_chan][i_s] = in[i_chan][i_s]; move16(); @@ -340,11 +346,12 @@ AMBI_CONVERT_ERROR convert_ambi_format( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR renormalize_channels( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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 */ ) { Word16 n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); @@ -413,7 +420,7 @@ AMBI_CONVERT_ERROR renormalize_channels( Word32 conversion_factor = conversion_table[i_chan]; Word32 outval; move32(); - FOR( i = 0; i < L_FRAME48k; i++ ) + FOR( i = 0; i < frame_length; i++ ) { Word64 tmp; tmp = W_mult0_32_32( (Word32) in[i_chan][i], conversion_factor ); @@ -439,11 +446,12 @@ AMBI_CONVERT_ERROR renormalize_channels( --------------------------------------------------------------------------*/ AMBI_CONVERT_ERROR reorder_channels( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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 */ ) { Word16 n_chan = i_mult2( add( order, 1 ), add( order, 1 ) ); @@ -490,7 +498,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 b1e5d1ec0..cbb50af3f 100644 --- a/lib_util/ambi_convert.h +++ b/lib_util/ambi_convert.h @@ -37,8 +37,8 @@ #include "stl.h" #include "cnst.h" -#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 { @@ -69,30 +69,34 @@ typedef enum { AMBI_CONVERT_OK = 0, AMBI_CONVERT_UNSUPPORTED_CONVERSION, + AMBI_CONVERT_UNSUPPORTED_FRAME_LENGTH, AMBI_CONVERT_CLIPPING_DETECTED } AMBI_CONVERT_ERROR; AMBI_CONVERT_ERROR convert_ambi_format( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_FMT in_format, /* i: input ambisonics format */ - AMBI_FMT out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_CHANNEL_NORM in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_NORM out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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( - Word16 *in[], /* i: input ambisonics channels, Q0 */ - Word16 *out[], /* o: output ambisonics channels, Q0 */ - Word16 order, /* i: ambisonics order */ - AMBI_CHANNEL_ORDER in_format, /* i: input ambisonics format */ - AMBI_CHANNEL_ORDER out_format /* i: output ambisonics format */ + Word16 *in[], /* i: input ambisonics channels, Q0 */ + Word16 *out[], /* o: output ambisonics channels, Q0 */ + const Word16 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 -- GitLab