Android Audiorecord对象的TARSOSDSP在LibGDX项目中不初始化



我正在尝试(重新)使用原始的tarsosdsp project的叉子来创建我对我编码的声音调谐器,从而使其可与Android一起使用。这次,我正在使用Jorensix为Android Project使用更新的TARSOSDSP,据我所知,我没有从上一个代码中更改结构上重要的内容,但是当我尝试运行应用程序时,我会收到以下错误:

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

i是从构造函数中调用的方法Intuner()中的调谐器:

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>

任何帮助将不胜感激。

已解决。

即使我在我的Android清单文件中宣布了录音record_audio,但我也没有意识到这是危险的许可,因此必须在运行时获得允许,因为我将目标定位为Android 6.0及更高。

相关内容

  • 没有找到相关文章

最新更新