在Android中使用FMod进行音高/节奏/混音/修剪

3
我希望能够进行音高和节奏变化,混合和裁剪声音并应用效果。我尝试了ffmpeg,但不幸的是,处理音频文件需要很长时间(对于一个36秒的文件,仅进行音高+节奏就需要40秒左右)。
所以,我在网上搜索了一个可以完成所有这些功能的库,我发现FMod可能是答案。
虽然我从未使用过NDK,而且我也不擅长阅读或编写C代码。
你能帮我开始这个冒险吗?
2个回答

0

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

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

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;
    }
}

我没有计划把整个东西开源,但如果你们感兴趣的话,请随时问我,我会尽力而为;)


嗨,Christophe,我很感兴趣,你能分享一些代码吗?例如processDSP部分。 - Shehabic
嗨,克里斯托夫,如果您能分享您的代码,那将是非常棒的,因为我正在按照问题中所述的路径前进。迫不及待地等待您的回复。 - Gurankas

0
我建议先查看FMOD SDK提供的示例,它们提供了简单的用法,如应用效果、更改播放频率等。
请记住,FMOD主要用于实时音频播放,因此虽然您可以写出.wav文件(假设这是您的目标),但这不是主要用途。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接