0
0

Hi,

I have just started to port code from iOS to Android. I am essentially trying to port the Pitch Detection sample from iOS to Android but I am running into a problem.

The code I have doesn’t seem to return any results from the call to getSpectrum.

Below is the code I am using and I am following the Android example pattern of using a delayed Message Handler.

The below code is being executed on the device however the log statement is always returning 0 for both values.

Any pointers would be great, there is no obvious errors being throw up by the application.

[code:13yrd4pv]

include <jni.h>

include <android/log.h>

include <stdlib.h>

include <stdio.h>

include "fmod.h"

include "fmod_errors.h"

define OUTPUTRATE 44100

define SPECTRUMSIZE 8192

define SPECTRUMRANGE ((float)OUTPUTRATE / 2.0f) /* 0 to nyquist */

define BINSIZE (SPECTRUMRANGE / (float)SPECTRUMSIZE)

FMOD_SYSTEM *gSystem = 0;
FMOD_CHANNEL *gChannel = 0;
FMOD_SOUND *gSound = 0;
FMOD_BOOL gLoopFlag = 1;
int running = 0;

define CHECK_RESULT(x) \

{ \
FMOD_RESULT _result = x; \
if (_result != FMOD_OK) \
{ \
android_log_print(ANDROID_LOG_ERROR, "fmod", "FMOD error! (%d) %s\n%s:%d", _result, FMOD_ErrorString(_result), __FILE, LINE); \
exit(-1); \
} \
}

void Java_org_fmod_recording_Example_cBegin(JNIEnv *env, jobject thiz)
{
FMOD_RESULT result = FMOD_OK;

result = FMOD_System_Create(&amp;gSystem);
CHECK_RESULT(result);

result = FMOD_System_Init(gSystem, 32, FMOD_INIT_NORMAL, 0);
CHECK_RESULT(result);

FMOD_CREATESOUNDEXINFO exinfo;
memset(&amp;exinfo, 0, sizeof(FMOD_CREATESOUNDEXINFO));

exinfo.cbsize           = sizeof(FMOD_CREATESOUNDEXINFO);
exinfo.numchannels      = 1;
exinfo.format           = FMOD_SOUND_FORMAT_PCM32;
    exinfo.defaultfrequency = OUTPUTRATE;
    exinfo.length           = exinfo.defaultfrequency * sizeof(short) * exinfo.numchannels * 5;

result = FMOD_System_CreateSound(gSystem, NULL, FMOD_2D | FMOD_SOFTWARE | FMOD_LOOP_NORMAL | FMOD_OPENUSER, &amp;exinfo, &amp;gSound);
CHECK_RESULT(result);

result = FMOD_System_RecordStart(gSystem, 0, gSound, gLoopFlag);
CHECK_RESULT(result);
///Give me some time to hear something
usleep(200 * 1000);

result = FMOD_System_PlaySound(gSystem, FMOD_CHANNEL_REUSE, gSound, 0, &amp;gChannel);
CHECK_RESULT(result);

/* Dont hear what is being recorded otherwise it will feedback.  Spectrum analysis is done before volume scaling in the DSP chain */
result = FMOD_Channel_SetVolume(gChannel,0);

CHECK_RESULT(result);

running = 1;

}

void Java_org_fmod_recording_Example_cUpdate(JNIEnv *env, jobject thiz)
{
FMOD_RESULT result = FMOD_OK;

result = FMOD_System_Update(gSystem);
CHECK_RESULT(result);

}

void Java_org_fmod_recording_Example_cEnd(JNIEnv *env, jobject thiz)
{
FMOD_RESULT result = FMOD_OK;

result = FMOD_Sound_Release(gSound);
CHECK_RESULT(result);

result = FMOD_System_Release(gSystem);
CHECK_RESULT(result);

}

void Java_org_fmod_recording_Example_cStopAll(JNIEnv *env, jobject thiz)
{
FMOD_RESULT result = FMOD_OK;

result = FMOD_System_RecordStop(gSystem, 0);
CHECK_RESULT(result);

if (gChannel)
{
    FMOD_Channel_Stop(gChannel);
    gChannel = 0;
}

}

jfloat Java_org_fmod_recording_Example_cGetRecievedFrequency(JNIEnv *env, jobject thiz)
{
FMOD_RESULT result = FMOD_OK;
static float spectrum[SPECTRUMSIZE] = {0};

float           dominanthz              = 0.0f;
float           max                     = 0.0f;
int             bin                     = 0;

result = FMOD_Channel_GetSpectrum(gChannel,spectrum,SPECTRUMSIZE,0,FMOD_DSP_FFT_WINDOW_TRIANGLE);

CHECK_RESULT(result);
int i = 0;
for (i = 0; i &lt; SPECTRUMSIZE; i++)
{

    if (spectrum[i] &gt; 0.01f &amp;&amp; spectrum[i] &gt; max)
    {
            max = spectrum[i];
            bin = i;
            __android_log_print(ANDROID_LOG_ERROR, &quot;fmod&quot;, &quot;Found Frequency: (%d) %f&quot;, (bin * BINSIZE), max);
    }
}
__android_log_print(ANDROID_LOG_ERROR, &quot;fmod&quot;, &quot;Returning Frequency: (%d) %f&quot;, (bin * BINSIZE), max);

return (bin * BINSIZE);

}

[/code:13yrd4pv]

  • You must to post comments
0
0

Thought it might be useful, here is the Java code calling out the library:

[code:1ip4gwcq]
package org.fmod.recording;

import org.fmod.FMODAudioDevice;
import org.fmod.effects.R;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;

public class Example extends Activity
{
private FMODAudioDevice mFMODAudioDevice = new FMODAudioDevice();
private Handler mUpdateHandler = new Handler()
{
public void handleMessage(Message msg)
{
cUpdate();
float tempValue = cGetRecievedFrequency();
Log.i("Example", "Got value: "+tempValue);
removeMessages(0);
sendMessageDelayed(obtainMessage(0), 1000);
}
};
//

public void stopAll(View view)
{
    cStopAll();
}    

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

@Override
public void onStart()
{
    super.onStart();  
    mFMODAudioDevice.start();
}

@Override
public void onStop()
{
    mUpdateHandler.removeMessages(0);
    cEnd();
    mFMODAudioDevice.stop();    
    super.onStop();
}

public void recordSound(View caller){
    cBegin();
    mUpdateHandler.sendMessageDelayed(mUpdateHandler.obtainMessage(0), 1000);
}

static 
{
    System.loadLibrary(&quot;fmodex&quot;);
    System.loadLibrary(&quot;main&quot;);
}

public native void cBegin();
public native void cUpdate();
public native void cEnd();
public native float cGetRecievedFrequency();
public native void cStopAll();

}

[/code:1ip4gwcq]

  • You must to post comments
0
0

So on further investigation, I can’t seem to be able to get the recording sample app running on the Nexus S device. I was wondering if this is a known issue? Is there anything I can do to further debug the issue to identify the root cause ?

  • You must to post comments
0
0

Are you using the SDK level 9 API? We only support recording with that level, and hence the fmod android-9 lib.

I’ll look into making this fact clear in the documentation because I can’t find where (or if) it’s mentioned.

  • You must to post comments
0
0

Mathew,

Thanks for the reply, at the moment I am just building the app as per the instructions.

My make file:
[code:2lus92b4]
LOCAL_PATH := $(call my-dir)
TARGET_ANDROID_SDK := android-9
#

FMOD Ex Shared Library

include $(CLEAR_VARS)

LOCAL_MODULE := fmodex
LOCAL_SRC_FILES := ../../FMODLIB/api/lib/$(TARGET_ANDROID_SDK)/$(TARGET_ARCH_ABI)/libfmodex.so
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../FMODLIB/api/inc/

include $(PREBUILT_SHARED_LIBRARY)

#

Example Library

#
include $(CLEAR_VARS)

LOCAL_MODULE := main
LOCAL_SRC_FILES := main.c
LOCAL_LDLIBS := -llog
LOCAL_SHARED_LIBRARIES := fmodex

include $(BUILD_SHARED_LIBRARY)
[/code:2lus92b4]

Output from make file using the android ndk

[code:2lus92b4]
Prebuilt : libfmodex.so <= jni/../../FMODLIB/api/lib/android-9/armeabi/
Install : libfmodex.so => libs/armeabi/libfmodex.so
Compile thumb : main <= main.c
SharedLibrary : libmain.so
Install : libmain.so => libs/armeabi/libmain.so
Prebuilt : libfmodex.so <= jni/../../FMODLIB/api/lib/android-9/armeabi-v7a/
Install : libfmodex.so => libs/armeabi-v7a/libfmodex.so
Compile thumb : main <= main.c
SharedLibrary : libmain.so
Install : libmain.so => libs/armeabi-v7a/libmain.so
[/code:2lus92b4]

I am seeing the following in my LogCat which is a little worrying but could be a false negative all the same:
In the following the dalvijvm, doesn’t seem to like the fact the onload is missing.
[code:2lus92b4]
08-09 09:54:26.499: DEBUG/dalvikvm(13376): Trying to load lib /data/data/org.fmod.recording/lib/libfmodex.so 0x40513970
08-09 09:54:26.503: DEBUG/dalvikvm(13376): Added shared lib /data/data/org.fmod.recording/lib/libfmodex.so 0x40513970
08-09 09:54:26.503: DEBUG/dalvikvm(13376): No JNI_OnLoad found in /data/data/org.fmod.recording/lib/libfmodex.so 0x40513970, skipping init
08-09 09:54:26.503: DEBUG/dalvikvm(13376): Trying to load lib /data/data/org.fmod.recording/lib/libmain.so 0x40513970
08-09 09:54:26.503: DEBUG/dalvikvm(13376): Added shared lib /data/data/org.fmod.recording/lib/libmain.so 0x40513970
08-09 09:54:26.503: DEBUG/dalvikvm(13376): No JNI_OnLoad found in /data/data/org.fmod.recording/lib/libmain.so 0x40513970, skipping init
08-09 09:54:26.535: DEBUG/AudioHardware(75): AudioHardware pcm playback is exiting standby.
08-09 09:54:26.535: DEBUG/AudioHardware(75): openPcmOut_l() mPcmOpenCnt: 0
08-09 09:54:26.558: VERBOSE/RenderScript_jni(210): surfaceDestroyed
[/code:2lus92b4]
Also in the Example Activity: write blocked for 113 msecs, 144 delayed writes, thread 0xcb08
[code:2lus92b4]
08-09 10:14:33.714: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() input_source=1;routing=262144
08-09 10:14:33.714: DEBUG/AudioHardware(75): AudioHardware pcm capture is exiting standby.
08-09 10:14:33.726: DEBUG/AudioHardware(75): closePcmOut_l() mPcmOpenCnt: 1
08-09 10:14:33.730: DEBUG/AudioHardware(75): openPcmOut_l() mPcmOpenCnt: 0
08-09 10:14:33.843: WARN/AudioFlinger(75): write blocked for 113 msecs, 144 delayed writes, thread 0xcb08
08-09 10:14:42.628: INFO/WindowManager(114): Setting rotation to 3, animFlags=0
08-09 10:14:42.648: INFO/ActivityManager(114): Config changed: { scale=1.0 imsi=272/2 loc=en_GB touch=3 keys=1/1/2 nav=1/1 orien=2 layout=34 uiMode=17 seq=234}
08-09 10:14:42.796: DEBUG/dalvikvm(191): GC_EXTERNAL_ALLOC freed 115K, 51% free 3064K/6215K, external 5765K/5771K, paused 41ms
08-09 10:14:42.804: DEBUG/AudioHardware(75): AudioHardware pcm capture is going to standby.
08-09 10:14:42.808: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() routing=0
08-09 10:14:43.562: INFO/WindowManager(114): Setting rotation to 0, animFlags=0
08-09 10:14:43.582: INFO/ActivityManager(114): Config changed: { scale=1.0 imsi=272/2 loc=en_GB touch=3 keys=1/1/2 nav=1/1 orien=1 layout=34 uiMode=17 seq=235}
08-09 10:14:45.957: DEBUG/dalvikvm(114): GC_EXPLICIT freed 956K, 46% free 6222K/11399K, external 3270K/4084K, paused 141ms
08-09 10:14:48.410: DEBUG/dalvikvm(13376): GC_CONCURRENT freed 335K, 58% free 2854K/6663K, external 1625K/2137K, paused 16ms+2ms
08-09 10:14:54.933: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() input_source=1;routing=262144
08-09 10:14:54.933: DEBUG/AudioHardware(75): AudioHardware pcm capture is exiting standby.
08-09 10:14:54.949: DEBUG/AudioHardware(75): closePcmOut_l() mPcmOpenCnt: 1
08-09 10:14:54.953: DEBUG/AudioHardware(75): openPcmOut_l() mPcmOpenCnt: 0
08-09 10:14:55.078: WARN/AudioFlinger(75): write blocked for 128 msecs, 145 delayed writes, thread 0xcb08
08-09 10:15:25.269: DEBUG/dalvikvm(13376): GC_CONCURRENT freed 501K, 58% free 2820K/6663K, external 1625K/2137K, paused 18ms+2ms
08-09 10:15:26.195: DEBUG/dalvikvm(10179): GC_EXPLICIT freed 4K, 55% free 3068K/6727K, external 1625K/2137K, paused 90ms
08-09 10:15:50.824: DEBUG/AudioHardware(75): AudioHardware pcm capture is going to standby.
08-09 10:15:50.835: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() routing=0
08-09 10:15:50.867: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() input_source=1;routing=262144
08-09 10:15:50.867: DEBUG/AudioHardware(75): AudioHardware pcm capture is exiting standby.
08-09 10:15:50.878: DEBUG/AudioHardware(75): closePcmOut_l() mPcmOpenCnt: 1
08-09 10:15:50.878: DEBUG/AudioHardware(75): openPcmOut_l() mPcmOpenCnt: 0
08-09 10:15:50.996: WARN/AudioFlinger(75): write blocked for 119 msecs, 146 delayed writes, thread 0xcb08
08-09 10:15:52.691: DEBUG/AudioHardware(75): AudioHardware pcm capture is going to standby.
08-09 10:15:52.695: DEBUG/AudioHardware(75): AudioStreamInALSA::setParameters() routing=0
08-09 10:16:01.175: DEBUG/dalvikvm(13376): GC_CONCURRENT freed 493K, 59% free 2781K/6663K, external 1625K/2137K, paused 17ms+3ms
08-09 10:16:02.609: WARN/KeyCharacterMap(13376): Can’t open keycharmap file
08-09 10:16:02.609: WARN/KeyCharacterMap(13376): Error loading keycharmap file ‘/system/usr/keychars/herring-keypad.kcm.bin’. hw.keyboards.0.devname=’herring-keypad’
08-09 10:16:02.613: WARN/KeyCharacterMap(13376): Using default keymap: /system/usr/keychars/qwerty.kcm.bin
08-09 10:16:31.031: DEBUG/dalvikvm(13376): GC_CONCURRENT freed 414K, 58% free 2809K/6663K, external 1625K/2137K, paused 14ms+2ms
08-09 10:16:37.519: INFO/WindowManager(114): Setting rotation to 3, animFlags=0
08-09 10:16:37.535: INFO/ActivityManager(114): Config changed: { scale=1.0 imsi=272/2 loc=en_GB touch=3 keys=1/1/2 nav=1/1 orien=2 layout=34 uiMode=17 seq=236}

[/code:2lus92b4]

Any thoughts? I am using a Samsung Nexus S with Android 2.3.4 currently installed.

  • You must to post comments
0
0

> 08-09 09:54:26.503: DEBUG/dalvikvm(13376): No JNI_OnLoad found in /data/data/org.fmod.recording/lib/libfmodex.so 0x40513970, skipping init
This is fine.

Could you link with the logging version of FMOD, it should give an indication if something is going wrong internally.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.