0

I am trying to record audio using ndk and converting audio into frequency format. I refered this link to record audio.( https://audioprograming.wordpress.com/2012/03/03/android-audio-streaming-with-opensl-es-and-the-ndk/ ).I can record audio but application crashing.i got this Fatal signal 7 (SIGBUS) at 0x3f8921d5 (code=1), thread 31131 (ndktest) error.Please help me and Thank you.

Android.mk

LOCAL_PATH :=$(call my-dir)
include $(CLEAR_VARS)

LOCAL_MODULE := ndktest
LOCAL_C_INCLUDES := $(LOCAL_PATH)
LOCAL_CFLAGS := -O3
LOCAL_CPPFLAGS :=$(LOCAL_CFLAGS)
###

LOCAL_SRC_FILES := java_interface_wrap.cpp opensl_example.c opensl_io.c 
RealDoubleFFT.c
LOCAL_LDLIBS := -llog -lOpenSLES
include $(BUILD_SHARED_LIBRARY)

Application.mk

APP_STL := gnustl_static
APP_CPPFLAGS += -fexceptions -frtti
APP_ABI := armeabi-v7a

Recorder Code

double *bufferdDouble;
double *re;
double *im;
double *magnitude;
int fftlen = 512;

void start_process(JNIEnv *env) {

    short inbuffer[VECSAMPS_MONO]
    RealDoubleFFT(env, fftlen);//fft calculation
    bufferdDouble = (double*) malloc(512 * sizeof(double));  
    re = (double*) malloc( 512 * sizeof(double));
    im = (double*) malloc( 512 * sizeof(double));
    magnitude = (double*) malloc( 256 * sizeof(double));
    p = android_OpenAudioDevice(SR, 1, 2, BUFFERFRAMES);//
   if (p == NULL) {
        LOGE("%s", "P is null");
        return;
    }
    on = 1;      
   while (on) {

      samps = android_AudioIn(p, inbuffer, VECSAMPS_MONO);
      if (samps > 0) {
          audio_conversion(inbuffer);
      }

    }  
    android_CloseAudioDevice(p);

}

void audio_conversion(short bufferByte[]) {

    for (int i = 0; i < 256; i++) {
        bufferdDouble[i] = (double) bufferByte[i] / 32768.0; 
    }
   ft(jenv, bufferdDouble);//fft calculation
   for (int i = 0; i < (fftlen / 2) - 1; i++) {
        re[i] = bufferdDouble[i * 2];
        im[i] = bufferdDouble[(i * 2) + 1];
        magnitude[i] = sqrt((re[i] * re[i]) + (im[i] * im[i]));
   }
   double max_magnitude = -1;
   int max_index = -1;
   for (int i = 0; i < (fftlen / 2) - 1; i++) {
       if (magnitude[i] > max_magnitude) {
            max_magnitude = magnitude[i];
            max_index = i;
       }
    }
  int freq = max_index * 44100 / fftlen;
  LOGE("freq = %d", freq);  

 memset(bufferdDouble, 0, 512 * sizeof(double));
 memset(re, 0,512 * sizeof(double));
 memset(im, 0,512 * sizeof(double));
 memset(magnitude, 0, 256 * sizeof(double));
}
Siddharthan
  • 61
  • 2
  • 9
  • So where does the crash occur exactly? – Michael Sep 13 '17 at 08:44
  • i do not know exactly .i'm getting like E/NDKTEST123: freq = 18776 E/NDKTEST123: freq = 18518 E/NDKTEST123: freq = 18432 E/NDKTEST123: freq = 18863 E/NDKTEST123: freq = 18776 E/NDKTEST123: freq = 18346 E/NDKTEST123: freq = 18604 E/NDKTEST123: freq = 18776 A/libc: Fatal signal 7 (SIGBUS) at 0x3f8921d5 (code=1), thread 31131 – Siddharthan Sep 13 '17 at 09:03
  • Build with debug info, and then use the `ndk-stack` tool or `addr2line` to map the addresses in the stacktrace to source code lines. – Michael Sep 13 '17 at 09:06
  • @Michael thanks for the reply. i thought we cannot debug c code.i will check – Siddharthan Sep 13 '17 at 10:38
  • I mean build the library with `APP_OPTIM := debug` or whatever, then trigger the crash and run the resulting stacktrace through `ndk-stack` or `addr2line`. – Michael Sep 13 '17 at 10:40
  • @Michael I do not know how to do that.if you do not mine can you send link for get crash report. – Siddharthan Sep 13 '17 at 12:41
  • Catch the logs with `adb logcat` while reproducing the issue. The logs should contain the stacktrace. If they don't, you're out of luck and you'll have to find some other way of pinpointing the crash. – Michael Sep 13 '17 at 12:56
  • @Michael finally i got error report.but how to get error line? – Siddharthan Sep 19 '17 at 08:07
  • signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xa6aea963 Stack frame I/DEBUG ( 149): #00 pc 00073b7c /system/lib/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+12) Stack frame I/DEBUG ( 149): #01 pc 00106fc0 /system/lib/libandroid_runtime.so (JNIAudioPortCallback::sendEvent(int)+96) Stack frame I/DEBUG ( 149): #02 pc 00107033 /system/lib/libandroid_runtime.so (JNIAudioPortCallback::onAudioPortListUpdate()+35) – Siddharthan Sep 19 '17 at 08:10
  • You can try running the stacktrace through the `ndk-stack` tool that comes with the NDK. But you can already see from the info you've got that the crash occurs in `_JNIEnv::CallStaticVoidMethod` which was called from `JNIAudioPortCallback::sendEvent`. So you should start looking for mistakes in the code along that path. – Michael Sep 19 '17 at 08:20
  • @michael thanks for reply – Siddharthan Sep 19 '17 at 13:37

0 Answers0