我正在使用TarsosDsp,但我不知道我的问题是否与库有关。如果有人能帮我解决这个问题,我会很高兴。这是我的代码:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MyActivity";
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
handler = new Handler();
}
protected void run(View view) {
new AndroidFFMPEGLocator(this);
new Thread(new Runnable() {
@Override
public void run() {
handler.post(new Runnable() {
@Override
public void run() {
File externalStorage = Environment.getExternalStorageDirectory();
File sourceFile = new File(externalStorage.getAbsolutePath(), "/440.wav");
final int bufferSize = 4096;
final int fftSize = bufferSize / 2;
final int sampleRate = 44100;
AudioDispatcher audioDispatcher;
audioDispatcher = AudioDispatcherFactory.fromPipe(sourceFile.getAbsolutePath(), sampleRate, bufferSize, 0);
audioDispatcher.addAudioProcessor(new AudioProcessor() {
FFT fft = new FFT(bufferSize);
final float[] amplitudes = new float[fftSize];
@Override
public boolean process(AudioEvent audioEvent) {
float[] audioBuffer = audioEvent.getFloatBuffer();
fft.forwardTransform(audioBuffer);
fft.modulus(audioBuffer, amplitudes);
for (int i = 0; i < amplitudes.length; i++) {
Log.println(Log.DEBUG, TAG, String.format("Amplitude at %3d Hz: %8.3f", (int) fft.binToHz(i, sampleRate), amplitudes[i]));
}
return true;
}
@Override
public void processingFinished() {
Toast.makeText(getApplicationContext(), "salam", Toast.LENGTH_SHORT).show();
}
});
audioDispatcher.run();
}
});
}
}).start();
}
}
问题是日志行
Log.println(Log.DEBUG, TAG, String.format("Amplitude at %3d Hz: %8.3f", (int) fft.binToHz(i, sampleRate), amplitudes[i]));
不打印任何东西。有什么帮助吗?这是我的日志:
10-25 20:48:22.423 19019-19019/com.example.me W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
10-25 20:48:22.693 19019-19019/com.example.me D/Atlas: Validating map...
10-25 20:48:22.753 19019-19062/com.example.me I/Adreno-EGL: <qeglDrvAPI_eglInitialize:410>: EGL 1.4 QUALCOMM build: AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.02.006.020 - CR771817 ()
OpenGL ES Shader Compiler Version: E031.25.03.06
Build Date: 03/04/15 Wed
Local Branch:
Remote Branch: refs/tags/AU_LINUX_ANDROID_LA.AF.1.1_RB1.05.00.02.006.020
Local Patches: NONE
Reconstruct Branch: NOTHING
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: Processor : ARMv7 Processor rev 0 (v7l)
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor : 0
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line:
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor : 1
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line:
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor : 2
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line:
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: processor : 3
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: BogoMIPS : 13.52
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line:
10-25 20:48:30.231 19019-19019/com.example.me D/AndroidFFMPEGLocator: CPUINFO line: Features : swp half thumb fastmult vfp edsp thumbee neon vfpv3 tls vfpv4
10-25 20:48:30.231 19019-19019/com.example.me I/AndroidFFMPEGLocator: Detected Native CPU Architecture: ARMEABI_V7A_NEON
10-25 20:48:30.231 19019-19019/com.example.me I/AndroidFFMPEGLocator: Ffmpeg binary location: /data/data/com.example.me/cache/ffmpeg is executable? true size: 15417252 bytes
10-25 20:48:30.251 19019-19019/com.example.me I/System: exec(ffmpeg -version @ be.tarsos.dsp.io.PipeDecoder.isAvailable:-1)
10-25 20:48:30.281 19019-19019/com.example.me I/System: exec(avconv -version @ be.tarsos.dsp.io.PipeDecoder.isAvailable:-1)
10-25 20:48:30.311 19019-19019/com.example.me I/System.out: Running on Android!
10-25 20:48:30.311 19019-19019/com.example.me I/PipeDecoder: Starting piped decoding process for /storage/emulated/0/440.wav
10-25 20:48:30.322 19019-19019/com.example.me I/System: exec(/system/bin/sh -c "/data/data/com.example.me/cache/ffmpeg" -i "/storage/emulated/0/440.wav" -vn -ar 44100 -ac 1 -sample_fmt s16 -f s16le pipe:1 @ be.tarsos.dsp.io.PipeDecoder.getDecodedStream:-1)
10-25 20:48:30.382 19019-19386/com.example.me I/PipeDecoder: Finished piped decoding process
PS 看起来进程功能没有运行。虽然 processingFinished 运行。
更新:这是处理程序的问题,我不知道为什么,但是当我将 run(View view) 中的代码移动到 onTouchEvent 时,它工作正常。