我使用 Tarsos DSP 来确定声音的频率,即从麦克风输入的声音。它在大多数设备上都能完美运行,但其中一些设备会出错。
错误:
java.lang.RuntimeException:
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2695)
at android.app.ActivityThread.handleLaunchActivity (ActivityThread.java:2769)
at android.app.ActivityThread.access$900 (ActivityThread.java:177)
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1430)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:135)
at android.app.ActivityThread.main (ActivityThread.java:5910)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1405)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1200)
Caused by: java.lang.NullPointerException:
at com.example.denissobolevsky.mmm.MainActivity.onCreate (MainActivity.java:1546)
at android.app.Activity.performCreate (Activity.java:6178)
at android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2648)
代码(第 1545-1547 行):
AudioProcessor p = new PitchProcessor(PitchProcessor.PitchEstimationAlgorithm.FFT_YIN, 22050, 1024, pdh);
dispatcher.addAudioProcessor(p);
new Thread(dispatcher, "Audio Dispatcher").start();
调度员是:
AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 1024, 0);