Как сохранить файл с FMOD_OUTPUTTYPE_WAVWRITER_NRT с эффектом dsp на Android? - PullRequest
0 голосов
/ 03 октября 2019

Я столкнулся с проблемой при сохранении звука, обработанного FMOD, в Android при использовании выходного типа FMOD_OUTPUTTYPE_WAVWRITER_NRT. Выходной файл, который я получаю всегда, имеет нулевой размер. но когда я использую выходной тип FMOD_OUTPUTTYPE_WAVWRITER, он выводит звук нормально, но процесс выхода очень медленный. Мой код ниже

#include <jni.h>
#include “inc/fmod.hpp”
#include <string>

#include <unistd.h>

using namespace FMOD;

#define MODE_NORMAL 0
#define MODE_TEST 1

#include <android/log.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);

extern “C”
JNIEXPORT void JNICALL
Java_com_example_voicechanger_EffectUtils_fix(JNIEnv *env, jclass cls, jstring path_str, jstring output_path, jint type) {
//Many of them are second-level pointers, but here you can define first-level pointers, and here you can achieve the same effect by reference.
System * system;
Sound * sound;
Channel *channel;
DSP *dsp;
DSP *dsp1;
bool playing= true;
float frequency=1;

//Initialization
System_Create(&system);

system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER_NRT);
 const char* outpath=env->GetStringUTFChars(output_path,NULL);
system->init(32, FMOD_INIT_NORMAL, (void *) outpath);
//Convert string to char*
const char* path=env->GetStringUTFChars(path_str,NULL);
//
// //Create voice
system->createSound(path,FMOD_DEFAULT, NULL, &sound);

try {
    //Change the sound according to the type
    switch (type) {
        case MODE_NORMAL:
            //Normal voice
            system->playSound(sound, 0, false, &channel);
            break;
        case MODE_TEST:
            //TEST
            //DSP digital signal process
            //DSP - > Sound effects create predefined sound effects in fmod
            //FMOD_DSP_TYPE_PITCHSHIFT dsp, a sound effect that promotes or reduces voice calls

            system->createDSPByType(FMOD_DSP_TYPE_PITCHSHIFT, &dsp);
            //Improving sound effects
            dsp->setParameterFloat(FMOD_DSP_PITCHSHIFT_PITCH, 0.85);
            dsp->setParameterFloat(FMOD_DSP_TYPE_ITECHO, 0.7);
            dsp-> setParameterFloat(FMOD_DSP_FLANGE_DEPTH, 0.1);
            //Play sound
            system->playSound(sound, 0, false, &channel);

            break;


        default:
            break;
    }
}
catch (...){
    //Catching anomalies
    LOGE("%s","exception occurred");
}
system->update();
//Release resources
//The unit is microseconds.
//Decide whether or not to play every second
while(playing){
    channel->isPlaying(&playing);
    usleep(1000 * 1000);
}

//release
sound->release();
system->close();
system->release();
env->ReleaseStringUTFChars(path_str,path);
...