3

在使用超级强大的Android音频效果(如flunge,echo,reverb等)实现项目时,我能够通过本机进行录制并将文件写入外部存储,然后使用超级强大的交叉推子示例打开该文件并对其应用效果很好。

现在我需要使用应用效果将输出文件写入外部存储,但不知道如何执行此操作。有类似的 iOS 示例SuperpoweredOfflineProcessingExample,但我没有找到它的 Android 文件解决方案。任何帮助都将非常感谢制作带有效果的音频输出 wav 文件。

4

1 回答 1

3

我需要对刚刚录制的音频应用效果(所以我有原始的 wav 并对其应用效果)。这是对原始文件应用效果并将其保存到单独文件的方法的示意图:

applyEffect(const char *input, const char *output, int effectId) {

SuperpoweredDecoder *decoder = new SuperpoweredDecoder();

const char *openError = decoder->open(input, false);
if (openError) {
    delete decoder;
    return false;
};

FILE *fd = createWAV(output, decoder->samplerate, 2);
if (!fd) {
    delete decoder;
    return false;
};

float effectMix = 0.5f;
SuperpoweredFX *effect = NULL;
if (effectId == 0) {
    effect = new SuperpoweredEcho(decoder->samplerate);
    ((SuperpoweredEcho *) effect)->setMix(effectMix);
} else if (effectId == 1) {
    effect = new SuperpoweredReverb(decoder->samplerate);
    ((SuperpoweredReverb *) effect)->setMix(effectMix);
}

if (effect == NULL) {
    delete decoder;
    return false;
}

effect->enable(true);

// Create a buffer for the 16-bit integer samples coming from the decoder.
short int *intBuffer = (short int *)malloc(decoder->samplesPerFrame * 2 * sizeof(short int) + 16384);
// Create a buffer for the 32-bit floating point samples required by the effect.
float *floatBuffer = (float *)malloc(decoder->samplesPerFrame * 2 * sizeof(float) + 1024);

// Processing.
while (true) {
    // Decode one frame. samplesDecoded will be overwritten with the actual decoded number of samples.
    unsigned int samplesDecoded = decoder->samplesPerFrame;
    if (decoder->decode(intBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
        break;
    }
    if (samplesDecoded < 1) {
        break;
    }

    // Apply the effect.

    // Convert the decoded PCM samples from 16-bit integer to 32-bit floating point.
    SuperpoweredShortIntToFloat(intBuffer, floatBuffer, samplesDecoded);

    effect->process(floatBuffer, floatBuffer, samplesDecoded);

    // Convert the PCM samples from 32-bit floating point to 16-bit integer.
    SuperpoweredFloatToShortInt(floatBuffer, intBuffer, samplesDecoded);
    }

    // Write the audio to disk.
    fwrite(intBuffer, 1, samplesDecoded * 4, fd);

};

// Cleanup.
closeWAV(fd);
delete decoder;
delete effect;
free(intBuffer);
free(floatBuffer);
return true;

}

将创建具有应用效果的新文件。希望它能以某种方式帮助你!

于 2017-02-20T13:23:35.763 回答