Play sound on android driver with fmod

#include <jni.h>
#include
#include “fmodlinux.h”
#include “fmod.hpp”
#include <stdlib.h>
#include “common.h”
#include “fmod_errors.h”
#include “fmod_codec.h”
#define LOGI(FORMAT,…) __android_log_print(ANDROID_LOG_INFO,“jason”,FORMAT,##VA_ARGS);
#define LOGE(FORMAT,…) __android_log_print(ANDROID_LOG_ERROR,“jason”,FORMAT,##VA_ARGS);

#define MODE_NORMAL 0
#define MODE_LUOLI 1
#define MODE_DASHU 2
#define MODE_JINGSONG 3
#define MODE_GAOGUAI 4
#define MODE_KONGLING 5
using namespace FMOD;
extern “C”
JNIEXPORT jstring JNICALL
Java_com_example_administrator_myapplication_MainActivity_stringFromJNI(
JNIEnv* env, jstring path_jstr,jint type,
jobject /* this */) {
std::string hello = “Hello from C++”;
System *system;
Sound *sound;
Channel *channel;
DSP *dsp;
bool playing = true;
float frequency = 0;

const char* path_cstr = env->GetStringUTFChars(path_jstr,NULL);
try {
    //初始化
    System_Create(&system);
    system->init(32, FMOD_INIT_NORMAL, NULL);

    //创建声音
    system->createSound(path_cstr, FMOD_DEFAULT, NULL, &sound);
    switch (type) {
        case MODE_NORMAL:
            //原生播放
            system->playSound(sound, 0, false, &channel);
            break;
        case MODE_LUOLI:
            //萝莉
            //DSP digital signal process
            //dsp -> 音效 创建fmod中预定义好的音效
            //FMOD_DSP_TYPE_PITCHSHIFT dsp,提升或者降低音调用的一种音效
            system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT,&dsp);
            //设置音调的参数
            dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH,2.5);

            system->playSound(sound, 0, false, &channel);
            //添加到channel
            channel->addDSP(0,dsp);
            break;

        case MODE_JINGSONG:
            //惊悚
            system->createDSPByType(FMOD_DSP_TYPE_TREMOLO,&dsp);
            dsp->setParameterFloat(FMOD_DSP_TREMOLO_SKEW, 0.5);
            system->playSound(sound, 0, false, &channel);
            channel->addDSP(0,dsp);

            break;
        case MODE_DASHU:
            //大叔
            system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT,&dsp);
            dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH,0.8);

            system->playSound(sound, 0, false, &channel);
            //添加到channel
            channel->addDSP(0,dsp);
            break;
        case MODE_GAOGUAI:
            //搞怪
            //提高说话的速度
            system->playSound(sound, 0, false, &channel);
            channel->getFrequency(&frequency);
            frequency = frequency * 1.6;
            channel->setFrequency(frequency);
            break;
        case MODE_KONGLING:
            //空灵
            system->createDSPByType(FMOD_DSP_TYPE_ECHO,&dsp);
            dsp->setParameterFloat(FMOD_DSP_ECHO_DELAY,300);
            dsp->setParameterFloat(FMOD_DSP_ECHO_FEEDBACK,20);
            system->playSound(sound, 0, false, &channel);
            channel->addDSP(0,dsp);
            break;

        default:
            break;
    }
} catch (...) {
    goto end;
}
system->update();

//释放资源
//单位是微秒
//每秒钟判断下是否在播放
while(playing){
    channel->isPlaying(&playing);
}
goto end;
end:
env->ReleaseStringUTFChars(path_jstr,path_cstr);
sound->release();
system->close();
system->release();
return env->NewStringUTF(hello.c_str());

}

I get this error

Error:(56) undefined reference to FMOD::ChannelControl::addDSP(int, FMOD::DSP*)' Error:(39) undefined reference toFMOD::System::createSound(char const*, unsigned int, FMOD_CREATESOUNDEXINFO*, FMOD::Sound**)’
Error:(54) undefined reference to FMOD::System::playSound(FMOD::Sound*, FMOD::ChannelGroup*, bool, FMOD::Channel**)' Error:(52) undefined reference toFMOD::DSP::setParameterFloat(int, float)’
Error:(43) undefined reference to FMOD::System::playSound(FMOD::Sound*, FMOD::ChannelGroup*, bool, FMOD::Channel**)' Error:(36) undefined reference toFMOD::System::init(int, unsigned int, void*)’
Error:(62) undefined reference to FMOD::DSP::setParameterFloat(int, float)' Error:(61) undefined reference toFMOD::System::createDSPByType(FMOD_DSP_TYPE, FMOD::DSP**)’
Error:(50) undefined reference to FMOD::System::createDSPByType(FMOD_DSP_TYPE, FMOD::DSP**)' Error:(63) undefined reference toFMOD::System::playSound(FMOD::Sound*, FMOD::ChannelGroup*, bool, FMOD::Channel**)’
Error:(64) undefined reference to `FMOD::ChannelControl::addDSP(int, FMOD::DSP*)’

how to deal with it, i just want to play sound in android system with fmod

Hello Allen,

From the looks of your code, it seems you getting linker errors and not really issues with FMOD Studio.

You will need to ensure you have set up your environment as stated here:

http://www.fmod.org/documentation/#content/generated/platform_android/basics.html

Once you have resolved your linker errors you should be able to build your project.

Thanks,
Richard

F:\BackUp Software\Fmod\api\lowlevel\examples>ndk-build NDK_PROJECT_PATH=. APP_B
UILD_SCRIPT=Android.mk NDK_APPLICATION_MK=Application.mk
[armeabi] Install : libfmodL.so => libs/armeabi/libfmodL.so
[armeabi] Install : libfmodstudioL.so => libs/armeabi/libfmodstudioL.so
[armeabi-v7a] Install : libfmodL.so => libs/armeabi-v7a/libfmodL.so
[armeabi-v7a] Install : libfmodstudioL.so => libs/armeabi-v7a/libfmodstud
ioL.so
[x86] Install : libfmodL.so => libs/x86/libfmodL.so
[x86] Install : libfmodstudioL.so => libs/x86/libfmodstudioL.so
[arm64-v8a] Install : libfmodL.so => libs/arm64-v8a/libfmodL.so
[arm64-v8a] Install : libfmodstudioL.so => libs/arm64-v8a/libfmodstudioL.
so

still error show??can you help me? and thank you

i just want to play sound in andriod driver with fmod, don’t want to use fmodstudio.

Hi Allen,

Thanks for the update, but unfortunately that isn’t enough information for us to help.

Could you please try building the Android example that is mentioned in the same link?
http://www.fmod.org/documentation/#content/generated/platform_android/basics.html

Let me know how you go. If you get any specific errors, please list them in their entirety.

Thanks,
Richard