2015-02-24 211 views
3

我希望能够进行一些音高和速度转换,混合和修剪声音以及应用效果。 我试过ffmpeg,但不幸的是,它在处理音频文件上有一些巨大的延迟(比如在36secs文件上只有40secs的音调+节奏)。在Android中使用FMod进行音高/速度/混音/微调

所以我搜索了一个可以做所有这些功能的图书馆,我发现FMod可能是答案。

虽然我从来没有玩过NDK,但我在阅读甚至编写C代码时都很糟糕。

你能帮助我如何开始这个冒险吗?

回答

0

我终于决定使用FMod来制作我自己的SDK来应用所有我想要的效果。

下面是Java类调用NDK的签名:

public static native String mix(String[] inputFiles, float secondaryVolume, String outFile); 

public static native String trim(String inFile, String outFile, long startMs, long endMs); 

public static native String fadeOut(String inFile, String outFile, long startMs, long endMs); 

public static native String processDSPs(String inFile, String outFile, FMODDSP[] dsps); 

在抽象FMODDSP样子:

public abstract class FMODDSP 
{ 
    public static final int FMOD_DSP_TYPE_COMPRESSION = 1; 
    public static final int FMOD_DSP_TYPE_ECHO = 2; 
    public static final int FMOD_DSP_TYPE_FLANGE = 3; 
    public static final int FMOD_DSP_TYPE_LOWPASS = 4; 
    public static final int FMOD_DSP_TYPE_HIGHPASS = 5; 
    public static final int FMOD_DSP_TYPE_PITCH = 6; 
    public static final int FMOD_DSP_TYPE_REVERBERATION = 7; 
    public static final int FMOD_DSP_TYPE_DISTORTION = 8; 
    public static final int FMOD_DSP_TYPE_TEMPO = 9; 
    public static final int FMOD_DSP_TYPE_CHORUS = 10; 

    protected int type; 

    public FMODDSP(int type) 
    { 
     this.type = type; 
    } 

    public int getType() 
    { 
     return this.type; 
    } 
} 

和间距的FMODDSP的示例实现是:

public class FMODDSPPitch extends FMODDSP 
{ 
    /** 
    * Pitch value. 0.5 to 2.0. Default = 1.0. 0.5 = one octave down, 2.0 = one octave up. 1.0 does not change the pitch. 
    */ 
    public float pitch = 1f; 
    /** 
    * FFT window size. 256, 512, 1024, 2048, 4096. Default = 1024. Increase this to reduce 'smearing'. This effect is a warbling sound similar to when an mp3 is encoded at very low bitrates. 
    */ 
    public float fftSize = 1024f; 

    public FMODDSPPitch() 
    { 
     super(FMODDSP.FMOD_DSP_TYPE_PITCH); 
    } 

    public FMODDSPPitch(float pitch, float fftSize) 
    { 
     super(FMODDSP.FMOD_DSP_TYPE_PITCH); 

     this.pitch = pitch; 
     this.fftSize = fftSize; 
    } 

    public float getPitch() 
    { 
     return this.pitch; 
    } 

    public float getFFTSize() 
    { 
     return this.fftSize; 
    } 
} 

我还没打算做整个事情的开源,但如果你们有兴趣,随时问我,我会尽我所能;)

+0

嗨克里斯托夫,我感兴趣,如果你想分享一些代码,例如processDSP部分 – Shehabix 2017-04-04 01:26:59

+0

嘿Christophe,如果你能分享你的代码,我会走在问题中解释的同一条路径上,这将是美好的。等待你的回复 – Gurankas 2017-08-08 06:14:06

0

我会通过考虑看看提供的FMOD SDK的例子开始,他们有像应用效果,改变播放频率任务使用简单等

请记住,FMOD主要是用于实时音频播放,所以虽然你可以写出.wav文件(假设这是你的目标),但这不是主要用法。