其他分享
首页 > 其他分享> > 如何使用Android中的超级功能SDK将文件写入外部存储?

如何使用Android中的超级功能SDK将文件写入外部存储?

作者:互联网

在使用超强大的Android音频效果(例如插入,回声,混响等)实施项目时,我能够通过本机录制并在外部存储中写入文件,然后使用超强大的交叉渐变器示例打开该文件并在其上应用效果良好的文件.

现在,我需要将输出文件写入具有应用效果的外部存储中,但是不知道如何执行此操作.
有iOS范例,例如SuperpoweredOfflineProcessingExample,
但我找不到适用于Android文件的解决方案.任何帮助将高度赞赏,以使音频输出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;

}

新文件将创建并生效.
希望它能以某种方式对您有所帮助!

标签:android-ndk,audio-recording,superpowered,audio,android
来源: https://codeday.me/bug/20191111/2021711.html