我需要将输出文件写入具有应用效果的外部存储中,但是不知道如何执行。任何帮助将使音频输出mp3或mp4文件具有效果,将不胜感激。我已经成功完成了实时音高更改,我使用了write file to external storage的一些代码,但是生成的文件只有0个字节并且已损坏。我使用了以下代码
Bitmap memBitmap(4961, 7016);
Graphics memGraphics(&memBitmap);
HDC memHDC = memGraphics.getHDC();
int iTmp1 = GetDeviceCaps(memHDC, HORZRES);
int iTmp2 = GetDeviceCaps(memHDC, VERTRES);
//doSomething...
memGraphics.ReleaseHDC(memHDC);
请帮助提供此代码。
我有如下错误。
const char *output1 = "/storage/emulated/0/Music/123456.mp3";
const char *openError = decoder->open(input, false, 0, 0, 0);
if (openError) {
delete decoder;
return false;
};
FILE *fd = createWAV(output1, decoder->samplerate, 2);
if (!fd) {
delete decoder;
return false;
};
float effectMix = 0.5f;
SuperpoweredFX *effect = NULL;
if (effectId == 0) {
player->setPitchShift(10);
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);
short int *intBuffer = (short int *) malloc(
decoder->samplesPerFrame * 2 * sizeof(short int) + 16384);
float *floatBuffer = (float *) malloc(decoder->samplesPerFrame * 2 * sizeof(float) + 1024);
unsigned int samplesDecoded;
while (true) {
samplesDecoded = decoder->samplesPerFrame;
if (decoder->decode(intBuffer, &samplesDecoded) == SUPERPOWEREDDECODER_ERROR) {
break;
}
if (samplesDecoded < 1) {
break;
}
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);
}
fwrite(intBuffer, 1, samplesDecoded * 4, fd);
closeWAV(fd);
delete decoder;
delete effect;
free(intBuffer);
free(floatBuffer);
return true;
答案 0 :(得分:2)
错误日志显示了一些Firebase问题,但是代码中发现的一个主要问题是您放置
fwrite(intBuffer, 1, samplesDecoded * 4, fd);
while循环之外。
它应该在它的内部,因为intBuffer在每次迭代中都会填充音频数据块。