我正在尝试使用ndk录制音频并将音频转换为频率格式。我把这个链接用来录制音频。( https://audioprograming.wordpress.com/2012/03/03/android-audio-streaming-with-opensl-es-and-the-ndk/)。我可以录制音频但是应用程序崩溃。我得到了这个致命信号7(SIGBUS)在0x3f8921d5(代码= 1),线程31131(ndktest)错误。请帮助我,谢谢。
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
记录器代码
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));
}