Skip to content

Commit

Permalink
Merge branch 'dev41' into unicode
Browse files Browse the repository at this point in the history
  • Loading branch information
starg2 committed Mar 16, 2024
2 parents 91b18ff + 3bb6b1f commit 3bc0acb
Show file tree
Hide file tree
Showing 147 changed files with 6,628 additions and 1,571 deletions.
25 changes: 24 additions & 1 deletion opus/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ add_definitions(
-DOPUS_X86_PRESUME_SSE4_1
)

if("${TIM41_X86_SIMD_LEVEL}" MATCHES "^(AVX2|AVX512)$")
add_definitions(
-DOPUS_X86_MAY_HAVE_AVX2
-DOPUS_X86_PRESUME_AVX2
)
elseif(MSVC)
add_definitions(
-DOPUS_HAVE_RTCD
-DOPUS_X86_MAY_HAVE_AVX2
)
endif()

add_library(
opus SHARED

Expand All @@ -32,6 +44,7 @@ add_library(

src/analysis.c
src/analysis.h
src/extensions.c
src/mlp.c
src/mlp.h
src/mlp_data.c
Expand All @@ -43,7 +56,6 @@ add_library(
src/opus_multistream_encoder.c
src/opus_private.h
src/repacketizer.c
src/tansig_table.h

celt/arch.h
celt/bands.c
Expand Down Expand Up @@ -95,12 +107,14 @@ add_library(
celt/_kiss_fft_guts.h
celt/x86/celt_lpc_sse4_1.c
celt/x86/celt_lpc_sse.h
celt/x86/pitch_avx.c
celt/x86/pitch_sse.c
celt/x86/pitch_sse.h
celt/x86/pitch_sse2.c
celt/x86/pitch_sse4_1.c
celt/x86/vq_sse.h
celt/x86/vq_sse2.c
celt/x86/x86_arch_macros.h
celt/x86/x86cpu.c
celt/x86/x86cpu.h
celt/x86/x86_celt_map.c
Expand Down Expand Up @@ -243,4 +257,13 @@ add_library(
silk/x86/x86_silk_map.c
)

if("${TIM41_X86_SIMD_LEVEL}" MATCHES "^(AVX2|AVX512)$" OR MSVC)
target_sources(
opus
PRIVATE
silk/float/x86/inner_product_FLP_avx2.c
silk/x86/NSQ_del_dec_avx2.c
)
endif()

install(TARGETS opus)
4 changes: 2 additions & 2 deletions opus/COPYING
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic,
Copyright 2001-2023 Xiph.Org, Skype Limited, Octasic,
Jean-Marc Valin, Timothy B. Terriberry,
CSIRO, Gregory Maxwell, Mark Borgerding,
Erik de Castro Lopo
Erik de Castro Lopo, Mozilla, Amazon

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
Expand Down
34 changes: 31 additions & 3 deletions opus/README
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ This package implements a shared library for encoding and decoding raw Opus
bitstreams. Raw Opus bitstreams should be used over RTP according to
https://tools.ietf.org/html/rfc7587

The package also includes a number of test tools used for testing the
The package also includes a number of test tools used for testing the
correct operation of the library. The bitstreams read/written by these
tools should not be used for Opus file distribution: They include
additional debugging data and cannot support seeking.
Expand All @@ -35,10 +35,32 @@ An opus-tools package is available which provides encoding and decoding of
Ogg encapsulated Opus files and includes a number of useful features.

Opus-tools can be found at:
https://git.xiph.org/?p=opus-tools.git
https://gitlab.xiph.org/xiph/opus-tools.git
or on the main Opus website:
https://opus-codec.org/

== Deep Learning and Opus ==

Lossy networks continue to be a challenge for real-time communications.
While the original implementation of Opus provides an excellent packet loss
concealment mechanism, the team has continued to advance the methodology used
to improve audio quality in challenge network environments.

In Opus 1.5, we added a deep learning based redundancy encoder that enhances
audio in lossy networks by embedding one second of recovery data in the padding
data of each packet. The underlying algorithm behind encoding and decoding the
recovery data is called the deep redundancy (DRED) algorithm. By leveraging
the padding data within the packet, Opus 1.5 is fully backward compatible with
prior revisions of Opus. Please see the README under the "dnn" subdirectory to
understand DRED.

DRED was developed by a team that Amazon Web Services initially sponsored,
who open-sourced the implementation as well as began the
standardization process at the IETF:
https://datatracker.ietf.org/doc/draft-ietf-mlcodec-opus-extension/
The license behind Opus or the intellectual property position of Opus does
not change with Opus 1.5.

== Compiling libopus ==

To build from a distribution tarball, you only need to do the following:
Expand Down Expand Up @@ -68,7 +90,7 @@ On Apple macOS, install Xcode and brew.sh, then in the Terminal enter:

1) Clone the repository:

% git clone https://git.xiph.org/opus.git
% git clone https://gitlab.xiph.org/xiph/opus.git
% cd opus

2) Compiling the source
Expand All @@ -77,6 +99,8 @@ On Apple macOS, install Xcode and brew.sh, then in the Terminal enter:
% ./configure
% make

On x86, it's a good idea to use a -march= option that allows the use of AVX2.

3) Install the codec libraries (optional)

% sudo make install
Expand Down Expand Up @@ -133,6 +157,10 @@ To run compare the code to these test vectors:
% tar -zxf opus_testvectors-rfc8251.tar.gz
% ./tests/run_vectors.sh ./ opus_newvectors 48000

== Compiling libopus for Windows and alternative build systems ==

See cmake/README.md or meson/README.md.

== Portability notes ==

This implementation uses floating-point by default but can be compiled to
Expand Down
3 changes: 3 additions & 0 deletions opus/celt/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ __attribute__((noreturn))
void celt_fatal(const char *str, const char *file, int line)
{
fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
#if defined(_MSC_VER)
_set_abort_behavior( 0, _WRITE_ABORT_MSG);
#endif
abort();
}
#endif
Expand Down
31 changes: 21 additions & 10 deletions opus/celt/arm/arm_celt_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ opus_val32 (*const CELT_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, c
celt_inner_prod_c, /* ARMv4 */
celt_inner_prod_c, /* EDSP */
celt_inner_prod_c, /* Media */
celt_inner_prod_neon /* NEON */
celt_inner_prod_neon,/* NEON */
celt_inner_prod_neon /* DOTPROD */
};

void (*const DUAL_INNER_PROD_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *x, const opus_val16 *y01, const opus_val16 *y02,
int N, opus_val32 *xy1, opus_val32 *xy2) = {
dual_inner_prod_c, /* ARMv4 */
dual_inner_prod_c, /* EDSP */
dual_inner_prod_c, /* Media */
dual_inner_prod_neon /* NEON */
dual_inner_prod_neon,/* NEON */
dual_inner_prod_neon /* DOTPROD */
};
# endif

Expand All @@ -61,7 +63,8 @@ opus_val32 (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
celt_pitch_xcorr_c, /* ARMv4 */
MAY_HAVE_EDSP(celt_pitch_xcorr), /* EDSP */
MAY_HAVE_MEDIA(celt_pitch_xcorr), /* Media */
MAY_HAVE_NEON(celt_pitch_xcorr) /* NEON */
MAY_HAVE_NEON(celt_pitch_xcorr), /* NEON */
MAY_HAVE_NEON(celt_pitch_xcorr) /* DOTPROD */
};

# endif
Expand All @@ -72,7 +75,8 @@ void (*const CELT_PITCH_XCORR_IMPL[OPUS_ARCHMASK+1])(const opus_val16 *,
celt_pitch_xcorr_c, /* ARMv4 */
celt_pitch_xcorr_c, /* EDSP */
celt_pitch_xcorr_c, /* Media */
celt_pitch_xcorr_float_neon /* Neon */
celt_pitch_xcorr_float_neon, /* Neon */
celt_pitch_xcorr_float_neon /* DOTPROD */
};
# endif
# endif /* FIXED_POINT */
Expand All @@ -90,6 +94,7 @@ void (*const XCORR_KERNEL_IMPL[OPUS_ARCHMASK + 1])(
xcorr_kernel_c, /* EDSP */
xcorr_kernel_c, /* Media */
xcorr_kernel_neon_fixed, /* Neon */
xcorr_kernel_neon_fixed /* DOTPROD */
};

#endif
Expand All @@ -101,14 +106,16 @@ int (*const OPUS_FFT_ALLOC_ARCH_IMPL[OPUS_ARCHMASK+1])(kiss_fft_state *st) = {
opus_fft_alloc_arch_c, /* ARMv4 */
opus_fft_alloc_arch_c, /* EDSP */
opus_fft_alloc_arch_c, /* Media */
opus_fft_alloc_arm_neon /* Neon with NE10 library support */
opus_fft_alloc_arm_neon, /* Neon with NE10 library support */
opus_fft_alloc_arm_neon /* DOTPROD with NE10 library support */
};

void (*const OPUS_FFT_FREE_ARCH_IMPL[OPUS_ARCHMASK+1])(kiss_fft_state *st) = {
opus_fft_free_arch_c, /* ARMv4 */
opus_fft_free_arch_c, /* EDSP */
opus_fft_free_arch_c, /* Media */
opus_fft_free_arm_neon /* Neon with NE10 */
opus_fft_free_arm_neon, /* Neon with NE10 */
opus_fft_free_arm_neon /* DOTPROD with NE10 */
};
# endif /* CUSTOM_MODES */

Expand All @@ -118,7 +125,8 @@ void (*const OPUS_FFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
opus_fft_c, /* ARMv4 */
opus_fft_c, /* EDSP */
opus_fft_c, /* Media */
opus_fft_neon /* Neon with NE10 */
opus_fft_neon, /* Neon with NE10 */
opus_fft_neon /* DOTPROD with NE10 */
};

void (*const OPUS_IFFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
Expand All @@ -127,7 +135,8 @@ void (*const OPUS_IFFT[OPUS_ARCHMASK+1])(const kiss_fft_state *cfg,
opus_ifft_c, /* ARMv4 */
opus_ifft_c, /* EDSP */
opus_ifft_c, /* Media */
opus_ifft_neon /* Neon with NE10 */
opus_ifft_neon, /* Neon with NE10 */
opus_ifft_neon /* DOTPROD with NE10 */
};

void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK+1])(const mdct_lookup *l,
Expand All @@ -139,7 +148,8 @@ void (*const CLT_MDCT_FORWARD_IMPL[OPUS_ARCHMASK+1])(const mdct_lookup *l,
clt_mdct_forward_c, /* ARMv4 */
clt_mdct_forward_c, /* EDSP */
clt_mdct_forward_c, /* Media */
clt_mdct_forward_neon /* Neon with NE10 */
clt_mdct_forward_neon, /* Neon with NE10 */
clt_mdct_forward_neon /* DOTPROD with NE10 */
};

void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK+1])(const mdct_lookup *l,
Expand All @@ -151,7 +161,8 @@ void (*const CLT_MDCT_BACKWARD_IMPL[OPUS_ARCHMASK+1])(const mdct_lookup *l,
clt_mdct_backward_c, /* ARMv4 */
clt_mdct_backward_c, /* EDSP */
clt_mdct_backward_c, /* Media */
clt_mdct_backward_neon /* Neon with NE10 */
clt_mdct_backward_neon, /* Neon with NE10 */
clt_mdct_backward_neon /* DOTPROD with NE10 */
};

# endif /* HAVE_ARM_NE10 */
Expand Down
62 changes: 60 additions & 2 deletions opus/celt/arm/armcpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#define OPUS_CPU_ARM_EDSP_FLAG (1<<OPUS_ARCH_ARM_EDSP)
#define OPUS_CPU_ARM_MEDIA_FLAG (1<<OPUS_ARCH_ARM_MEDIA)
#define OPUS_CPU_ARM_NEON_FLAG (1<<OPUS_ARCH_ARM_NEON)
#define OPUS_CPU_ARM_DOTPROD_FLAG (1<<OPUS_ARCH_ARM_DOTPROD)

#if defined(_MSC_VER)
/*For GetExceptionCode() and EXCEPTION_ILLEGAL_INSTRUCTION.*/
Expand Down Expand Up @@ -93,6 +94,8 @@ static OPUS_INLINE opus_uint32 opus_cpu_capabilities(void){

#elif defined(__linux__)
/* Linux based */
#include <stdio.h>

opus_uint32 opus_cpu_capabilities(void)
{
opus_uint32 flags = 0;
Expand Down Expand Up @@ -124,6 +127,14 @@ opus_uint32 opus_cpu_capabilities(void)
p = strstr(buf, " neon");
if(p != NULL && (p[5] == ' ' || p[5] == '\n'))
flags |= OPUS_CPU_ARM_NEON_FLAG;
p = strstr(buf, " asimd");
if(p != NULL && (p[6] == ' ' || p[6] == '\n'))
flags |= OPUS_CPU_ARM_NEON_FLAG | OPUS_CPU_ARM_MEDIA_FLAG | OPUS_CPU_ARM_EDSP_FLAG;
# endif
# if defined(OPUS_ARM_MAY_HAVE_DOTPROD)
p = strstr(buf, " asimddp");
if(p != NULL && (p[8] == ' ' || p[8] == '\n'))
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
# endif
}
# endif
Expand All @@ -142,10 +153,44 @@ opus_uint32 opus_cpu_capabilities(void)
# endif
}

#if defined(OPUS_ARM_PRESUME_AARCH64_NEON_INTR)
flags |= OPUS_CPU_ARM_EDSP_FLAG | OPUS_CPU_ARM_MEDIA_FLAG | OPUS_CPU_ARM_NEON_FLAG;
# if defined(OPUS_ARM_PRESUME_DOTPROD)
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
# endif
#endif

fclose(cpuinfo);
}
return flags;
}

#elif defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>

opus_uint32 opus_cpu_capabilities(void)
{
opus_uint32 flags = 0;

#if defined(OPUS_ARM_MAY_HAVE_DOTPROD)
size_t size = sizeof(uint32_t);
uint32_t value = 0;
if (!sysctlbyname("hw.optional.arm.FEAT_DotProd", &value, &size, NULL, 0) && value)
{
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
}
#endif

#if defined(OPUS_ARM_PRESUME_AARCH64_NEON_INTR)
flags |= OPUS_CPU_ARM_EDSP_FLAG | OPUS_CPU_ARM_MEDIA_FLAG | OPUS_CPU_ARM_NEON_FLAG;
# if defined(OPUS_ARM_PRESUME_DOTPROD)
flags |= OPUS_CPU_ARM_DOTPROD_FLAG;
# endif
#endif
return flags;
}

#else
/* The feature registers which can tell us what the processor supports are
* accessible in priveleged modes only, so we can't have a general user-space
Expand All @@ -154,7 +199,7 @@ opus_uint32 opus_cpu_capabilities(void)
"your platform. Reconfigure with --disable-rtcd (or send patches)."
#endif

int opus_select_arch(void)
static int opus_select_arch_impl(void)
{
opus_uint32 flags = opus_cpu_capabilities();
int arch = 0;
Expand All @@ -178,8 +223,21 @@ int opus_select_arch(void)
}
arch++;

celt_assert(arch == OPUS_ARCH_ARM_NEON);
if(!(flags & OPUS_CPU_ARM_DOTPROD_FLAG)) {
celt_assert(arch == OPUS_ARCH_ARM_NEON);
return arch;
}
arch++;

celt_assert(arch == OPUS_ARCH_ARM_DOTPROD);
return arch;
}

int opus_select_arch(void) {
int arch = opus_select_arch_impl();
#ifdef FUZZING
arch = rand()%(arch+1);
#endif
return arch;
}
#endif
Loading

0 comments on commit 3bc0acb

Please sign in to comment.