使用FMOD将输出保存到文件

时间:2014-09-08 23:22:07

标签: android c++ save fmod

我正在使用FMOD并且我有一个有效的音频,但我不知道如何将效果保存在文件中。

    #include "fmod.hpp"
#include "common.h"
#include <android/log.h>

int FMOD_Main(int position, const char *fileName) {

    FMOD::System *system = 0;
    FMOD::Sound *sound = 0;
    FMOD::Channel *channel = 0;
    FMOD::ChannelGroup *mastergroup = 0;
    FMOD::DSP *effect1 = 0;
    FMOD_RESULT result;

    int pos = position;
    void *extradriverdata = 0;
    FMOD::Sound *sound2 = 0;

    Common_Init(&extradriverdata);

    __android_log_print(ANDROID_LOG_DEBUG, "LOG",
            "Need to print : %d ", pos);

    __android_log_print(ANDROID_LOG_DEBUG, "LOG",
            "Need to print fileName : %s ", fileName);
    char cDest[200] = {0};
    result = FMOD::System_Create(&system);
    system->setOutput(FMOD_OUTPUTTYPE_WAVWRITER);

    result = system->init(2, FMOD_INIT_NORMAL, cDest);

    result = system->getMasterChannelGroup(&mastergroup);
    result = system->setStreamBufferSize(64 * 1024, FMOD_TIMEUNIT_RAWBYTES);

    result = system->createSound(Common_MediaPath(fileName), FMOD_DEFAULT, 0,
            &sound);

    result = system->playSound(sound, 0, false, &channel);
    if (pos == 0) {
        __android_log_print(ANDROID_LOG_DEBUG, "LOG", "Original");
    } else if (pos == 1) {
        result = system->createDSPByType(FMOD_DSP_TYPE_ECHO, &effect1);
        __android_log_print(ANDROID_LOG_DEBUG, "LOG", "ecco");

    } else {
        result = system->createDSPByType(FMOD_DSP_TYPE_SFXREVERB, &effect1);
        __android_log_print(ANDROID_LOG_DEBUG, "LOG", "Original");
    }
    result = mastergroup->addDSP(0, effect1);

    result = effect1->setBypass(true);

    bool bypass;
    result = effect1->getBypass(&bypass);
    bypass = !bypass;
    result = effect1->setBypass(bypass);

    bool isPlaying = true;
    do {
        result = system->update();
        result = channel->isPlaying(&isPlaying);
        if (!isPlaying) {
            break;
        }
        {
            bool paused = 0;
            if (channel) {
                result = channel->getPaused(&paused);
                if ((result != FMOD_OK) && (result != FMOD_ERR_INVALID_HANDLE)
                        && (result != FMOD_ERR_CHANNEL_STOLEN)) {
                    __android_log_print(ANDROID_LOG_ERROR, "LOG",
                            "Error al reproducir ");
                    break;
                }
            }
        }
        Common_Sleep(10);

    } while (1);

    result = sound->release();
    result = system->close();
    result = system->release();
    __android_log_print(ANDROID_LOG_DEBUG, "LOG", "end Playing");
    Common_Close();
    return 0;
}

我使用system-&gt; setOutput(FMOD_OUTPUTTYPE_WAVWRITER),但我不知道我把输出文件的名称放在哪里。

1 个答案:

答案 0 :(得分:1)

您可以通过System :: init extradriverdata参数将路径传递给输出文件。对于Android,您可能希望使用SD卡路径以便于访问。