# Optimize saving speed in android

**URL:** <https://qa.fmod.com/t/optimize-saving-speed-in-android/20306>\
**Category:** FMOD Engine\
**Tags:** android\
**Created:** [June 12, 2023, 10:54am UTC](https://qa.fmod.com/t/optimize-saving-speed-in-android/20306 "2023-06-12T10:54:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bovietvidai](https://avatars.discourse-cdn.com/v4/letter/b/7ea924/32.png) [@bovietvidai](https://qa.fmod.com/u/bovietvidai)\
**Post date:** [June 12, 2023, 10:54am UTC](https://qa.fmod.com/t/optimize-saving-speed-in-android/20306/1 "2023-06-12T10:54:25Z")

</div>

I am making a voice changer app, which means the input is an audio file, after being processed in a function, it should generate an effect audio file with DSP

```auto
extern "C" JNIEXPORT jint JNICALL
Java_io_microshow_aisound_AiSound_saveMixSound(JNIEnv *env, jclass clazz, jstring main_audio,
                                               jstring sub_audio, jstring output_audio,
                                               jint type,
                                               jfloat main_audio_volume,
                                               jfloat sub_audio_volume,
                                               jobject on_progress_listener) {
    System *system = nullptr;
    Sound *mainSound = nullptr, *subSound = nullptr;
    Channel *mainChannel = nullptr, *subChannel = nullptr;
    bool isMainSoundPlaying = true;
    jint result = 1;
    unsigned int length = 0, position = 0;
    DSP *dsp;
    float mFrequency;
    JNIEnv *mEnv = env;
    System_Create(&system);
    system->setSoftwareFormat(22050, FMOD_SPEAKERMODE_STEREO, 1);
    const char *cstr_main_audio = mEnv->GetStringUTFChars(main_audio, nullptr);
    const char *cstr_sub_audio = mEnv->GetStringUTFChars(sub_audio, nullptr);
    const char *cstr_output_audio = mEnv->GetStringUTFChars(output_audio, nullptr);
    char cDest[200];
    strcpy(cDest, cstr_output_audio);
    system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER_NRT);
    system->init(1024, FMOD_INIT_STREAM_FROM_UPDATE | FMOD_INIT_PROFILE_ENABLE, cDest);
    try {
        system->createSound(cstr_main_audio,FMOD_CREATESAMPLE, nullptr,
                            &mainSound);
        switch (type) {
            case TYPE_NORMAL:
                system->playSound(mainSound, nullptr, false, &mainChannel);
                break;
          
            default:
                break;
        }
        if (env->GetStringLength(sub_audio) != 0) {
            LOGI("%s", "Saving background")
            system->createSound(cstr_sub_audio,
                                FMOD_LOOP_NORMAL | FMOD_CREATESAMPLE , nullptr,
                                &subSound);

            system->playSound(subSound, nullptr, false, &subChannel);
            subChannel->setVolume(sub_audio_volume);
        }
    } catch (...) {
        LOGE("%s", "catch exception...")
        result = 0;
    }

    mainSound->getLength(&length, FMOD_TIMEUNIT_MS);
    mainChannel->setVolume(main_audio_volume);
    try {
        const float CALLBACK_THRESHOLD = 0.01f;
        float lastCallbackProgress = 0.0f;
        float lengthReciprocal = 1.0f / float(length);
        while (isMainSoundPlaying) {
            usleep(1000);
            mainChannel->isPlaying(&isMainSoundPlaying);
            mainChannel->getPosition(&position, FMOD_TIMEUNIT_MS);
            float progress = float(position) * lengthReciprocal;
            if (progress - lastCallbackProgress >= CALLBACK_THRESHOLD) {
                callJNICallBack(env, on_progress_listener, progress);
                lastCallbackProgress = progress;
            }
            system->update();
        }
        callJNICallBack(env, on_progress_listener, 1.0);
        env->ReleaseStringUTFChars(main_audio, cstr_main_audio);
        env->ReleaseStringUTFChars(sub_audio, cstr_sub_audio);
        env->ReleaseStringUTFChars(output_audio, cstr_output_audio);
        mainSound->release();
        subSound->release();
        system->close();
        system->release();
    }
    catch (...) {
        LOGE("%s", "FILE DID NOT SAVE")
        result = 0;
    }
    return result;
}

```

But the issue here is the file takes a long time to generate, I want to optimize the saving speed as fast as possible

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [June 13, 2023, 11:29pm UTC](https://qa.fmod.com/t/optimize-saving-speed-in-android/20306/2 "2023-06-13T23:29:46Z")

</div>

Hi,

What version of FMOD are you using?

What is the average length of the audio file and how long are they taking to export?
