Convert external/libopus to Android.bp

See build/soong/README.md for more information.

Test: m -j checkbuild
Change-Id: Ibb869e5fdeccd3755581fc1649f9fdd8102678dc
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..e3c8b8e
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,320 @@
+cc_library_shared {
+    name: "libopus",
+
+    export_include_dirs: ["include"],
+
+    local_include_dirs: [
+        "src",
+        "silk",
+        "celt",
+        "silk/fixed",
+    ],
+
+    srcs: [
+        // CELT_SOURCES
+        "celt/bands.c",
+        "celt/celt.c",
+        "celt/celt_encoder.c",
+        "celt/celt_decoder.c",
+        "celt/cwrs.c",
+        "celt/entcode.c",
+        "celt/entdec.c",
+        "celt/entenc.c",
+        "celt/kiss_fft.c",
+        "celt/laplace.c",
+        "celt/mathops.c",
+        "celt/mdct.c",
+        "celt/modes.c",
+        "celt/pitch.c",
+        "celt/celt_lpc.c",
+        "celt/quant_bands.c",
+        "celt/rate.c",
+        "celt/vq.c",
+
+        // SILK_SOURCES
+        "silk/CNG.c",
+        "silk/code_signs.c",
+        "silk/init_decoder.c",
+        "silk/decode_core.c",
+        "silk/decode_frame.c",
+        "silk/decode_parameters.c",
+        "silk/decode_indices.c",
+        "silk/decode_pulses.c",
+        "silk/decoder_set_fs.c",
+        "silk/dec_API.c",
+        "silk/enc_API.c",
+        "silk/encode_indices.c",
+        "silk/encode_pulses.c",
+        "silk/gain_quant.c",
+        "silk/interpolate.c",
+        "silk/LP_variable_cutoff.c",
+        "silk/NLSF_decode.c",
+        "silk/NSQ.c",
+        "silk/NSQ_del_dec.c",
+        "silk/PLC.c",
+        "silk/shell_coder.c",
+        "silk/tables_gain.c",
+        "silk/tables_LTP.c",
+        "silk/tables_NLSF_CB_NB_MB.c",
+        "silk/tables_NLSF_CB_WB.c",
+        "silk/tables_other.c",
+        "silk/tables_pitch_lag.c",
+        "silk/tables_pulses_per_block.c",
+        "silk/VAD.c",
+        "silk/control_audio_bandwidth.c",
+        "silk/quant_LTP_gains.c",
+        "silk/VQ_WMat_EC.c",
+        "silk/HP_variable_cutoff.c",
+        "silk/NLSF_encode.c",
+        "silk/NLSF_VQ.c",
+        "silk/NLSF_unpack.c",
+        "silk/NLSF_del_dec_quant.c",
+        "silk/process_NLSFs.c",
+        "silk/stereo_LR_to_MS.c",
+        "silk/stereo_MS_to_LR.c",
+        "silk/check_control_input.c",
+        "silk/control_SNR.c",
+        "silk/init_encoder.c",
+        "silk/control_codec.c",
+        "silk/A2NLSF.c",
+        "silk/ana_filt_bank_1.c",
+        "silk/biquad_alt.c",
+        "silk/bwexpander_32.c",
+        "silk/bwexpander.c",
+        "silk/debug.c",
+        "silk/decode_pitch.c",
+        "silk/inner_prod_aligned.c",
+        "silk/lin2log.c",
+        "silk/log2lin.c",
+        "silk/LPC_analysis_filter.c",
+        "silk/LPC_inv_pred_gain.c",
+        "silk/table_LSF_cos.c",
+        "silk/NLSF2A.c",
+        "silk/NLSF_stabilize.c",
+        "silk/NLSF_VQ_weights_laroia.c",
+        "silk/pitch_est_tables.c",
+        "silk/resampler.c",
+        "silk/resampler_down2_3.c",
+        "silk/resampler_down2.c",
+        "silk/resampler_private_AR2.c",
+        "silk/resampler_private_down_FIR.c",
+        "silk/resampler_private_IIR_FIR.c",
+        "silk/resampler_private_up2_HQ.c",
+        "silk/resampler_rom.c",
+        "silk/sigm_Q15.c",
+        "silk/sort.c",
+        "silk/sum_sqr_shift.c",
+        "silk/stereo_decode_pred.c",
+        "silk/stereo_encode_pred.c",
+        "silk/stereo_find_predictor.c",
+        "silk/stereo_quant_pred.c",
+
+        // SILK_SOURCES_FIXED
+        "silk/fixed/LTP_analysis_filter_FIX.c",
+        "silk/fixed/LTP_scale_ctrl_FIX.c",
+        "silk/fixed/corrMatrix_FIX.c",
+        "silk/fixed/encode_frame_FIX.c",
+        "silk/fixed/find_LPC_FIX.c",
+        "silk/fixed/find_LTP_FIX.c",
+        "silk/fixed/find_pitch_lags_FIX.c",
+        "silk/fixed/find_pred_coefs_FIX.c",
+        "silk/fixed/noise_shape_analysis_FIX.c",
+        "silk/fixed/prefilter_FIX.c",
+        "silk/fixed/process_gains_FIX.c",
+        "silk/fixed/regularize_correlations_FIX.c",
+        "silk/fixed/residual_energy16_FIX.c",
+        "silk/fixed/residual_energy_FIX.c",
+        "silk/fixed/solve_LS_FIX.c",
+        "silk/fixed/warped_autocorrelation_FIX.c",
+        "silk/fixed/apply_sine_window_FIX.c",
+        "silk/fixed/autocorr_FIX.c",
+        "silk/fixed/burg_modified_FIX.c",
+        "silk/fixed/k2a_FIX.c",
+        "silk/fixed/k2a_Q16_FIX.c",
+        "silk/fixed/pitch_analysis_core_FIX.c",
+        "silk/fixed/vector_ops_FIX.c",
+        "silk/fixed/schur64_FIX.c",
+        "silk/fixed/schur_FIX.c",
+
+        // OPUS_SOURCES
+        "src/opus.c",
+        "src/opus_decoder.c",
+        "src/opus_encoder.c",
+        "src/opus_multistream.c",
+        "src/opus_multistream_encoder.c",
+        "src/opus_multistream_decoder.c",
+        "src/repacketizer.c",
+
+        // OPUS_SOURCES_FLOAT
+        "src/analysis.c",
+        "src/mlp.c",
+        "src/mlp_data.c",
+
+        "src/repacketizer_demo.c",
+    ],
+
+    cflags: [
+        "-DNULL=0",
+        "-DSOCKLEN_T=socklen_t",
+        "-DLOCALE_NOT_USED",
+        "-D_LARGEFILE_SOURCE=1",
+        "-D_FILE_OFFSET_BITS=64",
+        "-Drestrict=",
+        "-D__EMX__",
+        "-DOPUS_BUILD",
+        "-DFIXED_POINT",
+        "-DUSE_ALLOCA",
+        "-DHAVE_LRINT",
+        "-DHAVE_LRINTF",
+        "-O2",
+        "-fno-math-errno",
+    ],
+    cppflags: [
+        "-DBSD=1",
+        "-ffast-math",
+        "-O2",
+        "-funroll-loops",
+    ],
+
+    arch: {
+        arm: {
+            srcs: [
+                // CELT_SOURCES_ARM
+                "celt/arm/armcpu.c",
+                "celt/arm/arm_celt_map.c",
+
+                // DSP, MEDIA and NEON instructions are in the same assembler
+                // file - thus we need to include it even if NEON is not
+                // supported on target platform.
+                // CELT_SOURCES_ARM_ASM
+                "celt/arm/celt_pitch_xcorr_arm_gnu.s",
+            ],
+
+            cflags: [
+                "-DOPUS_ARM_ASM",
+                "-DOPUS_ARM_INLINE_ASM",
+                "-DOPUS_ARM_MAY_HAVE_EDSP",
+                "-DOPUS_ARM_INLINE_EDSP",
+                "-DOPUS_ARM_MAY_HAVE_MEDIA",
+                "-DOPUS_ARM_INLINE_MEDIA",
+                "-DOPUS_HAVE_RTCD",
+            ],
+
+            // Note: OPUS enhanced DSP/NEON implementation is not yet
+            // compatible with arm64.  Only add the appropriate defines for
+            // 32-bit arm architecture.
+            armv7_a_neon: {
+                srcs: [
+                    // CELT_SOURCES_ARM_NEON_INTR
+                    "celt/arm/celt_neon_intr.c",
+
+                    // SILK_SOURCES_ARM_NEON_INTR,
+                    "silk/arm/arm_silk_map.c",
+                    "silk/arm/NSQ_neon.c",
+                ],
+
+                cflags: [
+                    "-DOPUS_ARM_MAY_HAVE_NEON",
+                    "-DOPUS_ARM_MAY_HAVE_NEON_INTR",
+                    "-DOPUS_ARM_PRESUME_NEON",
+                    "-DOPUS_ARM_INLINE_NEON",
+                ],
+            },
+
+        },
+
+        x86: {
+            ssse3: {
+                srcs: [
+                    // CELT_SOURCES_SSE
+                    "celt/x86/x86cpu.c",
+                    "celt/x86/x86_celt_map.c",
+                    "celt/x86/pitch_sse.c",
+
+                    // CELT_SOURCES_SSE2
+                    "celt/x86/pitch_sse2.c",
+                ],
+
+                cflags: [
+                    "-DOPUS_X86_MAY_HAVE_SSE",
+                    "-DOPUS_X86_PRESUME_SSE",
+                    "-DOPUS_X86_MAY_HAVE_SSE2",
+                    "-DOPUS_X86_PRESUME_SSE2",
+                ],
+            },
+
+            sse4_1: {
+                srcs: [
+                    // CELT_SOURCES_SSE4_1
+                    "celt/x86/celt_lpc_sse.c",
+                    "celt/x86/pitch_sse4_1.c",
+
+                    // SILK_SOURCES_SSE4_1
+                    "silk/x86/NSQ_sse.c",
+                    "silk/x86/NSQ_del_dec_sse.c",
+                    "silk/x86/x86_silk_map.c",
+                    "silk/x86/VAD_sse.c",
+                    "silk/x86/VQ_WMat_EC_sse.c",
+
+                    // SILK_SOURCES_FIXED_SSE4_1
+                    "silk/fixed/x86/vector_ops_FIX_sse.c",
+                    "silk/fixed/x86/burg_modified_FIX_sse.c",
+                    "silk/fixed/x86/prefilter_FIX_sse.c",
+                ],
+
+                cflags: [
+                    "-DOPUS_X86_MAY_HAVE_SSE4_1",
+                    "-DOPUS_X86_PRESUME_SSE4_1",
+                ],
+            },
+        },
+
+        x86_64: {
+            ssse3: {
+                srcs: [
+                    // CELT_SOURCES_SSE
+                    "celt/x86/x86cpu.c",
+                    "celt/x86/x86_celt_map.c",
+                    "celt/x86/pitch_sse.c",
+
+                    // CELT_SOURCES_SSE2
+                    "celt/x86/pitch_sse2.c",
+                ],
+
+                cflags: [
+                    "-DOPUS_X86_MAY_HAVE_SSE",
+                    "-DOPUS_X86_PRESUME_SSE",
+                    "-DOPUS_X86_MAY_HAVE_SSE2",
+                    "-DOPUS_X86_PRESUME_SSE2",
+                ],
+            },
+
+            sse4_1: {
+                srcs: [
+                    // CELT_SOURCES_SSE4_1
+                    "celt/x86/celt_lpc_sse.c",
+                    "celt/x86/pitch_sse4_1.c",
+
+                    // SILK_SOURCES_SSE4_1
+                    "silk/x86/NSQ_sse.c",
+                    "silk/x86/NSQ_del_dec_sse.c",
+                    "silk/x86/x86_silk_map.c",
+                    "silk/x86/VAD_sse.c",
+                    "silk/x86/VQ_WMat_EC_sse.c",
+
+                    // SILK_SOURCES_FIXED_SSE4_1
+                    "silk/fixed/x86/vector_ops_FIX_sse.c",
+                    "silk/fixed/x86/burg_modified_FIX_sse.c",
+                    "silk/fixed/x86/prefilter_FIX_sse.c",
+                ],
+
+                cflags: [
+                    "-DOPUS_X86_MAY_HAVE_SSE4_1",
+                    "-DOPUS_X86_PRESUME_SSE4_1",
+                ],
+            },
+        },
+    },
+
+    static_libs: ["libogg"],
+}
diff --git a/Android.mk b/Android.mk
deleted file mode 100644
index 47e499b..0000000
--- a/Android.mk
+++ /dev/null
@@ -1,60 +0,0 @@
-LOCAL_PATH := $(call my-dir)
-
-include $(CLEAR_VARS)
-
-include $(LOCAL_PATH)/celt_sources.mk
-include $(LOCAL_PATH)/opus_sources.mk
-include $(LOCAL_PATH)/silk_sources.mk
-
-LOCAL_MODULE    := libopus
-OGG_DIR         := external/libogg
-LOCAL_C_INCLUDES += $(LOCAL_PATH)/include $(LOCAL_PATH)/src $(LOCAL_PATH)/silk \
-                    $(LOCAL_PATH)/celt $(LOCAL_PATH)/silk/fixed $(OGG_DIR)/include
-LOCAL_SRC_FILES := $(CELT_SOURCES) $(SILK_SOURCES) $(SILK_SOURCES_FIXED) \
-                   $(OPUS_SOURCES) $(OPUS_SOURCES_FLOAT) src/repacketizer_demo.c
-
-LOCAL_CFLAGS        := -DNULL=0 -DSOCKLEN_T=socklen_t -DLOCALE_NOT_USED \
-                       -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 \
-                       -Drestrict='' -D__EMX__ -DOPUS_BUILD -DFIXED_POINT \
-                       -DUSE_ALLOCA -DHAVE_LRINT -DHAVE_LRINTF -O2 -fno-math-errno
-LOCAL_CPPFLAGS      := -DBSD=1 -ffast-math -O2 -funroll-loops
-
-# Note: OPUS enhanced DSP/NEON implementation is not yet compatible with arm64.
-# Only add the appropriate defines for 32-bit arm architecture.
-LOCAL_SRC_FILES_arm += $(CELT_SOURCES_ARM)
-LOCAL_CFLAGS_arm += -DOPUS_ARM_ASM -DOPUS_ARM_INLINE_ASM \
-                    -DOPUS_ARM_MAY_HAVE_EDSP -DOPUS_ARM_INLINE_EDSP \
-                    -DOPUS_ARM_MAY_HAVE_MEDIA -DOPUS_ARM_INLINE_MEDIA \
-                    -DOPUS_HAVE_RTCD
-# DSP, MEDIA and NEON instructions are in the same assembler file - thus we
-# need to include it even if NEON is not supported on target platform.
-LOCAL_SRC_FILES_arm += $(subst .s,_gnu.s,$(CELT_SOURCES_ARM_ASM))
-ifeq ($(ARCH_ARM_HAVE_NEON),true)
-LOCAL_SRC_FILES_arm += $(CELT_SOURCES_ARM_NEON_INTR) \
-                       $(SILK_SOURCES_ARM_NEON_INTR)
-LOCAL_CFLAGS_arm += -DOPUS_ARM_MAY_HAVE_NEON -DOPUS_ARM_MAY_HAVE_NEON_INTR \
-                    -DOPUS_ARM_PRESUME_NEON -DOPUS_ARM_INLINE_NEON
-endif
-
-LIBOPUS_X86_FILES :=
-LIBOPUS_X86_CFLAGS :=
-ifeq ($(ARCH_X86_HAVE_SSSE3),true)
-LIBOPUS_X86_FILES += $(CELT_SOURCES_SSE) $(CELT_SOURCES_SSE2)
-LIBOPUS_X86_CFLAGS += -DOPUS_X86_MAY_HAVE_SSE -DOPUS_X86_PRESUME_SSE \
-                      -DOPUS_X86_MAY_HAVE_SSE2 -DOPUS_X86_PRESUME_SSE2
-endif
-
-ifeq ($(ARCH_X86_HAVE_SSE4_1),true)
-LIBOPUS_X86_FILES += $(CELT_SOURCES_SSE4_1) \
-                   $(SILK_SOURCES_SSE4_1) $(SILK_SOURCES_FIXED_SSE4_1)
-LIBOPUS_X86_CFLAGS += -DOPUS_X86_MAY_HAVE_SSE4_1 -DOPUS_X86_PRESUME_SSE4_1
-endif
-
-LOCAL_SRC_FILES_x86 += $(LIBOPUS_X86_FILES)
-LOCAL_SRC_FILES_x86_64 += $(LIBOPUS_X86_FILES)
-LOCAL_CFLAGS_x86 += $(LIBOPUS_X86_CFLAGS)
-LOCAL_CFLAGS_x86_64 += $(LIBOPUS_X86_CFLAGS)
-
-LOCAL_STATIC_LIBRARIES := libogg
-
-include $(BUILD_SHARED_LIBRARY)