2017-02-18 30 views
2

雖然實現了一個項目,使用superpowered爲Android音頻效果,如flunge,回聲,混響等我可以通過本機和外部存儲器寫入文件,然後使用超級交叉淡化示例我打開該文件,並應用效果精細。如何在android中使用超級動力的SDK將文件寫入外部存儲?

現在我需要將輸出文件寫入具有應用效果的外部存儲器中,但不知道如何執行此操作。 有像這樣的iOS示例SuperpoweredOfflineProcessingExample, 但我沒有找到它的解決方案的Android文件。任何幫助將高度讚賞,使音頻輸出wav文件的影響。

+0

看到這篇文章,它可能會幫助你:http://stackoverflow.com/questions/28989182/superpowered-sdk-implementing-superpoweredrecorder-h-and-setting-up-recording-p – yakobom

回答

2

我有一個要求對剛剛錄製的音頻應用效果(所以我有原始的WAV和應用效果)。 這裏是一個對原始文件應用效果,並將其保存到單獨的文件方法的shapshot:

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; 

}

新文件將與應用效果進行創建。 希望它能以某種方式幫助你!

+0

當我將混響應用到音頻聲音變得越來越慢,變得越來越深(它的音高正在變化)。我已經工作了2天,試圖解決它,但無法成功。我試圖改變採樣率,緩衝區大小但沒有成功。你可以幫我嗎 ? – ACAkgul

相關問題