0

我正在尝试(重新)创建一个我前段时间使用原始 TarsosDSP 项目的分支编写的声学调谐器,使其可用于 Android。这一次,我正在使用 JorenSix 更新的 TarsosDSP for Android 项目,据我所知,我的代码中没有任何结构上重要的内容与之前的代码相比没有更改,但是当我尝试运行应用程序时收到以下错误:

E/AudioRecord: AudioFlinger could not create record track, status: -1
E/AudioRecord-JNI: Error creating AudioRecord instance: initialization check failed with status -1.
E/android.media.AudioRecord: Error code -20 when initializing native AudioRecord object.
D/libEGL: eglTerminate EGLDisplay = 0x7f90cf2e28
E/AndroidRuntime: FATAL EXCEPTION: GLThread 2218
              Process: com.fraserjohnstone.tuner, PID: 19923
              java.lang.IllegalStateException: startRecording() called on an uninitialized AudioRecord.
                  at android.media.AudioRecord.startRecording(AudioRecord.java:943)
                  at be.tarsos.dsp.io.android.AudioDispatcherFactory.fromDefaultMicrophone(Unknown Source)
                  at com.fraserjohnstone.tuner.screens.TunerScreen.initTuner(TunerScreen.java:238)
                  at com.fraserjohnstone.tuner.screens.TunerScreen.show(TunerScreen.java:123)
                  at com.badlogic.gdx.Game.setScreen(Game.java:61)
                  at com.fraserjohnstone.tuner.screens.SplashScreen.goToTunerScreen(SplashScreen.java:148)
                  at com.fraserjohnstone.tuner.screens.SplashScreen.render(SplashScreen.java:131)
                  at com.badlogic.gdx.Game.render(Game.java:46)
                  at com.fraserjohnstone.tuner.Tuner.render(Tuner.java:73)
                  at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:459)
                  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1649)
                  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1354)
E/AndroidGraphics: waiting for pause synchronization took too long; assuming deadlock and killing

我在从构造函数调用的方法 initTuner() 中初始化调谐器:

private void initTuner(){
    if(dispatcher == null){
                //set initial tuner values
                algo = PitchEstimationAlgorithm.FFT_YIN;
                currentHertz = 440.00;              
                sampleRate = 44100;                 
                bufferSize = 2048;             
                sampleOverlap = 1536;             
                offsetInCents = 0;                  
                sharpOrFlat = "";                   
                targetNote = "A";                   
                targetRotation = 0;                 

                dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(sampleRate, bufferSize, sampleOverlap);

                PitchDetectionHandler printPitch = new PitchDetectionHandler() {
                    @Override
                    public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
                        double pitch = pitchDetectionResult.getPitch();
                        if(pitch != -1 && !audioEvent.isSilence(silenceThreshold)){
                            audioDetected = true;
                            currentHertz = pitch;
                        }
                        else{
                            audioDetected = false;
                            offsetInCents = 0.00;
                        }
                    }
                };
                AudioProcessor audioProcessor = new PitchProcessor(algo, sampleRate, bufferSize, printPitch);
                dispatcher.addAudioProcessor(audioProcessor);

        new Thread(dispatcher,"Audio Dispatcher").start();
    }
}

还有我的android清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fraserjohnstone.tuner"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="24" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/GdxTheme" >
    <activity
        android:name="com.fraserjohnstone.tuner.AndroidLauncher"
        android:label="@string/app_name" 
        android:screenOrientation="portrait"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

任何帮助,将不胜感激。

4

1 回答 1

1

解决了。

即使我在我的 android 清单文件中声明了 RECORD_AUDIO 权限,我也没有意识到这是一个危险的权限,因此必须在运行时获得权限,因为我的目标是 Android 6.0 及更高版本。

于 2017-02-22T14:38:20.573 回答