3

I want to be able to do some Pitch and Tempo Shifting, mix and trim sounds and apply effects. I tried ffmpeg but unfortunately, it has some huge delay on processing the audio file (like 40secs for just pitch+tempo on a 36secs file).

So I searched the web for a library that could do all these features and I found FMod could be the answer.

I have never played with NDK though, and I'm bad at reading or even writing C code.

Could you help me on how to start this adventure ?

ChristopheCVB
  • 7,269
  • 1
  • 29
  • 54

2 Answers2

0

I'd start by taking a look at the examples provided with the FMOD SDK, they have simple usage for tasks like applying effects, changing playback frequency, etc.

Keep in mind that FMOD is primarily for realtime audio playback, so while you can write out .wav files (assuming this is your goal) it's not the main usage.

Mathew Block
  • 1,613
  • 1
  • 10
  • 9
0

I finally decided to make an SDK of my own using FMod to apply all the effects I want.

Here are the signatures of the Java class calling the 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);

where the abstract FMODDSP looks like :

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

and an example implementation of a FMODDSP of the pitch is :

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

I have not planned to make the whole thing open source but if you guys are interested, feel free to ask me, I'll do my best ;)

ChristopheCVB
  • 7,269
  • 1
  • 29
  • 54
  • Hi Christophe, I'm interested if you'd share some of the code e.g the the processDSP part – Shehabic Apr 04 '17 at 01:26
  • Hey Christophe, It'd be wonderful if you could share your code as I am walking the same path explained in the question. Waiting eaherly for your reply – Gurankas Aug 08 '17 at 06:14