How to write a file to external storage using the super powerful SDK in Android?

When implementing a project that uses heavy-duty Android sound effects such as flunge, echo, reverb, etc. I can record through my own and the recording file in external storage, and then using the super-strong crossfader example. I open this file and apply effects to it, it works fine.

Now I need to write the output file to external storage using effects, but I don’t know how to do it. There are iOS examples for this, for example SuperpoweredOfflineProcessingExample , but I did not find its solution for the Android file. Any help would be greatly appreciated to make a wav file with audio effects with effects.

+2
source share
1 answer

I had a requirement to apply the effect only to the recorded audio (so I have the original wav and apply the effect to it). The following is a short method that affects the source file and saves it in a 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; 

}

A new file will be created using the effect. Hope this helps you!

+2
source

Source: https://habr.com/ru/post/1236432/


All Articles