如何在android中使用超级SDK将文件写入外部存储? [英] How to write file to external storage using superpowered SDK in android?

查看:54
本文介绍了如何在android中使用超级SDK将文件写入外部存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用超强的 Android 音频效果(如甩尾、回声、混响等)实施项目时,我能够通过本机进行录音并在外部存储中写入文件,然后使用超强的交叉推子示例我打开该文件并对其应用效果工作正常.

While implementing a project using superpowered for Android audio effects like flunge, echo, reverb etc I am able to make recording through native and write file in external storage, then using superpowered crossfader example I open that file and apply effects on it that works fine.

现在我需要使用应用效果将输出文件写入外部存储,但不知道如何执行此操作.有 iOS 示例,例如 超能力离线处理示例,但我没有找到针对 Android 文件的解决方案.制作带有效果的音频输出 wav 文件的任何帮助将不胜感激.

Now I need to write the output file in external storage with applied effects but don't know how to do this. There are iOS examples for this like SuperpoweredOfflineProcessingExample, but I didn't find its solution for Android file. Any help will be highly appreciated to make audio output wav file with effects.

推荐答案

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

I had a requirement to apply effect on just recorded audio (so I have original wav and apply effect to it). Here is a shapshot of method which apply effect on original file and save it to separate file:

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;

}

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

New file will be created with applied effect. Hope it will help you somehow!

这篇关于如何在android中使用超级SDK将文件写入外部存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆