package {
    default_applicable_licenses: ["external_sonivox_arm-wt-22k_license"],
}

// Added automatically by a large-scale-change
// See: http://go/android-license-faq
license {
    name: "external_sonivox_arm-wt-22k_license",
    visibility: [":__subpackages__"],
    license_kinds: [
        "SPDX-license-identifier-Apache-2.0",
    ],
    license_text: [
        "NOTICE",
    ],
}

cc_defaults {
    name: "libsonivox-defaults",
    srcs: [
        "lib_src/eas_chorus.c",
        "lib_src/eas_chorusdata.c",
        "lib_src/eas_data.c",
        "lib_src/eas_dlssynth.c",
        "lib_src/eas_flog.c",
        "lib_src/eas_ima_tables.c",
        "lib_src/eas_imaadpcm.c",
        "lib_src/eas_imelody.c",
        "lib_src/eas_imelodydata.c",
        "lib_src/eas_math.c",
        "lib_src/eas_mdls.c",
        "lib_src/eas_midi.c",
        "lib_src/eas_mididata.c",
        "lib_src/eas_mixbuf.c",
        "lib_src/eas_mixer.c",
        "lib_src/eas_ota.c",
        "lib_src/eas_otadata.c",
        "lib_src/eas_pan.c",
        "lib_src/eas_pcm.c",
        "lib_src/eas_pcmdata.c",
        "lib_src/eas_public.c",
        "lib_src/eas_reverb.c",
        "lib_src/eas_reverbdata.c",
        "lib_src/eas_rtttl.c",
        "lib_src/eas_rtttldata.c",
        "lib_src/eas_smf.c",
        "lib_src/eas_smfdata.c",
        "lib_src/eas_voicemgt.c",
        "lib_src/eas_wtengine.c",
        "lib_src/eas_wtsynth.c",
        "lib_src/eas_xmf.c",
        "lib_src/eas_xmfdata.c",
        "lib_src/wt_22khz.c",
        "host_src/eas_config.c",
        "host_src/eas_hostmm.c",
        "host_src/eas_report.c",

        // not using these modules
        //"host_src/eas_main.c",
        //"host_src/eas_wave.c",
        //"lib_src/eas_wavefile.c",
        //"lib_src/eas_wavefiledata.c",
    ],

    cflags: [
        "-O2",
        "-DUNIFIED_DEBUG_MESSAGES",
        "-DEAS_WT_SYNTH",
        "-D_IMELODY_PARSER",
        "-D_RTTTL_PARSER",
        "-D_OTA_PARSER",
        "-D_XMF_PARSER",
        "-DNUM_OUTPUT_CHANNELS=2",
        "-D_SAMPLE_RATE_22050",
        "-DMAX_SYNTH_VOICES=64",
        "-D_16_BIT_SAMPLES",
        "-D_FILTER_ENABLED",
        "-DDLS_SYNTHESIZER",
        "-D_REVERB_ENABLED",

        "-Wno-unused-parameter",
        "-Werror",

        // not using these options
        // "-D_WAVE_PARSER",
        // "-D_IMA_DECODER", // (needed for IMA-ADPCM wave files)
        // "-D_CHORUS_ENABLED",
    ],

    local_include_dirs: [
        "host_src",
        "lib_src",
    ],
    export_include_dirs: ["include"],

    shared_libs: [
        "liblog",
    ],

    host_supported: true,

    target: {
        darwin: {
            enabled: false,
        },
    },

    arch: {
        arm: {
            instruction_set: "arm",

            srcs: [
                "lib_src/ARM-E_filter_gnu.s",
                //"lib_src/ARM-E_interpolate_loop_gnu.s",
                //"lib_src/ARM-E_interpolate_noloop_gnu.s",
                "lib_src/ARM-E_mastergain_gnu.s",
                //"lib_src/ARM-E_voice_gain_gnu.s",
            ],

            asflags: [
                // In order to use #include instead of .include
                "-xassembler-with-cpp",

                "-DSAMPLE_RATE_22050=1",
                "-DSTEREO_OUTPUT=1",
                "-DFILTER_ENABLED=1",
                "-DSAMPLES_16_BIT=1",
            ],

            cflags: [
                "-DNATIVE_EAS_KERNEL",
            ],
        },
    },
    sanitize: {
        cfi: true,
        misc_undefined: [
            "bounds",
            "unsigned-integer-overflow",
            "signed-integer-overflow",
        ],
    }
}

cc_library {
    name: "libsonivoxwithoutjet",
    defaults: ["libsonivox-defaults"],
    apex_available: [
        "//apex_available:platform",
        "com.android.media",
    ],
    min_sdk_version: "29",
}

cc_library {
    name: "libsonivox",
    defaults: ["libsonivox-defaults"],
    srcs: [
        "lib_src/jet.c",
    ],

    cflags: [
        "-DJET_INTERFACE",
    ],
}
