3

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.

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.

yakobom
  • 2,681
  • 1
  • 25
  • 33
arslan haktic
  • 4,348
  • 4
  • 22
  • 35
  • See this post, it may help you: http://stackoverflow.com/questions/28989182/superpowered-sdk-implementing-superpoweredrecorder-h-and-setting-up-recording-p – yakobom Feb 19 '17 at 05:05

1 Answers1

3

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!

kasurd
  • 476
  • 7
  • 16
  • when I apply reverb into a audio the sound gets slower and becoming deeper (its pitch is changing). I ve been working for 2 days to trying fix it but couldn't success. I tried to change sample rate, buffer size but no success. Can you help me ? – ACAkgul Apr 23 '17 at 11:54
  • I also wants to do the same... Do you get any solution? @ACAkgul – nidhi Nov 12 '18 at 11:27
  • @nidhi it s been too long that I gave up developing audio process on Android, sorry I didn't get any solution.. – ACAkgul Nov 12 '18 at 12:34
  • I have error in above code . 11-13 16:39:42.624 17813-18400/com.korakoepitchchanger A/libc: invalid address or address of corrupt block 0x5570c6d0a0 passed to dlfree – nidhi Nov 13 '18 at 11:11