2

I am developing an app for android using the native pitch shifting cpp code available here:

www.dspdimension.com/admin/pitch-shifting-using-the-ft/

the app will read wav files, change its pitch and then write back the file on the sd card. The reading wav file and write back methods are working fine, but when I apply pitch shift and then write, i get back static only i.e. the original audio is lost and just static is heard..

seems that there is se problem while passing the data from java to the cpp code

Can anyone help me with this?

the cpp code is at that link, and I have made a function in cpp to use that code:

JNIEXPORT jfloatArray JNICALL Java_com_pitch_PitchActivity_pitchShift (JNIEnv * pEnv, jobject pThis, jfloat pitchShift, jlong numSampsToProcess, jlong fftFrameSize, jlong osamp, jfloat sampleRate, jfloatArray inputdata) {
    jfloat* ind,ata = pEnv->GetFloatArrayElements(inputdata,0);
    float outdata[numSampsToProcess];
    jfloatArray res;
    res = pEnv->NewFloatArray(numSampsToProcess);
    memset(outdata, 0, numSampsToProcess*sizeof(float));
    smbPitchShift(pitchShift, numSampsToProcess, fftFrameSize, osamp, sampleRate, indata, outdata);
    pEnv->SetFloatArrayRegion(res, 0, numSampsToProcess, outdata);
    return res;
}

this code calls the smbPitchShift method of the cpp code.

from the java code i am passing the following values:

float[] parr = new float[data.length];
parr = pitchShift(0.6f, (long)data.length, (long)2048, (long) 4, (float) sampleRate, data);

here data is a float array, containing the data extracted from the wav file and it is in the range of [-1.0,1.0)

Sumit
  • 2,189
  • 7
  • 32
  • 50
  • Without seeing any code I doubt that anyone can help with this – Paul R May 08 '12 at 06:43
  • What is `o.6f` ? Is this the *actual* code or did you just re-type an approximate version of it ? – Paul R May 08 '12 at 09:28
  • 0.6f is the float value by which i want to do the pitch shift, according to the code documentation, it can be in the range 0.5 to 2.0 – Sumit May 08 '12 at 10:16
  • Sure - but you have `o.6f` in the code above, not `0.6f`, which makes me think that this is a re-typed approximate version of the code, rather than the actual code. You should only ever post actual code, i.e. copy and paste. – Paul R May 08 '12 at 10:37
  • ohh, sorry yes my mistake, its supposed to be 0.6f only, – Sumit May 08 '12 at 11:00
  • Hi @sumit do you have any sample of this code, I'm trying to make it run, but I'm with troubles defining my main.cpp class that calls the smbPitchShift.cpp? :) – João M Feb 19 '15 at 20:45

0 Answers0