1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
| using namespace FMOD;
#define TAG "Jack_Ou"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, TAG, __VA_ARGS__)
extern "C" JNIEXPORT void JNICALL Java_com_example_practicemethod_MainActivity_changeVoiceNative (JNIEnv *env, jobject thiz, jint mode, jstring path) { const char *content_ = "播放完毕";
const char *path_ = env->GetStringUTFChars(path, NULL);
System *system = 0;
Sound *sound = 0;
Channel *channel = 0;
DSP *dsp = 0;
System_Create(&system);
system->init(32, FMOD_INIT_NORMAL, 0);
system->createSound(path_, FMOD_DEFAULT, 0, &sound);
system->playSound(sound, 0, false, &channel);
switch (mode) { case com_example_practicemethod_MainActivity_MODE_NORMAL: content_ = "原生 播放完毕"; break; case com_example_practicemethod_MainActivity_MODE_GIRL: system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp); dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 2.0f); channel->addDSP(0, dsp); content_ = "女声 播放完毕"; LOGE("%s", content_); break; case com_example_practicemethod_MainActivity_MODE_UNCLE: system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp); dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 0.7f); channel->addDSP(0, dsp); content_ = "大叔 播放完毕"; break; case com_example_practicemethod_MainActivity_MODE_HORROR: system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp); dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 0.7f); channel->addDSP(0, dsp);
system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dsp); dsp->setParameterFloat(FMOD_DSP_ECHO_DELAY, 200); dsp->setParameterFloat(FMOD_DSP_ECHO_FEEDBACK, 10); channel->addDSP(1, dsp);
system->createDSPByType(FMOD_DSP_TYPE_TREMOLO, &dsp); dsp->setParameterFloat(FMOD_DSP_TREMOLO_FREQUENCY, 20); dsp->setParameterFloat(FMOD_DSP_TREMOLO_SKEW, 0.8f); channel->addDSP(2, dsp); content_ = "惊悚 播放完毕"; break; case com_example_practicemethod_MainActivity_MODE_FUN: float freq; channel->getFrequency(&freq);
channel->setFrequency(freq * 1.5f); content_ = "搞怪 播放完毕"; break; case com_example_practicemethod_MainActivity_MODE_ETHEREAL: system->createDSPByType(FMOD_DSP_TYPE_ECHO, &dsp); dsp->setParameterFloat(FMOD_DSP_ECHO_DELAY, 200); dsp->setParameterFloat(FMOD_DSP_ECHO_FEEDBACK, 0); channel->addDSP(0, dsp); content_ = "空灵 播放完毕"; break; }
bool isPlay = true; while (isPlay) { channel->isPlaying(&isPlay); LOGE("%s", content_); usleep(1000 * 1000); }
jclass clazz = env->GetObjectClass(thiz); jmethodID endMethod = env->GetMethodID(clazz, "playEnd", "(Ljava/lang/String;)V"); jstring value = env->NewStringUTF(content_); env->CallVoidMethod(thiz, endMethod, value);
sound->release(); system->close(); system->release(); env->ReleaseStringUTFChars(path, path_); }
|