androidtarsosdsp

Android log doesn't print


I'm using TarsosDsp and I don't know if my problem is with the library or not. I'd be happy if anyone could help me figure that out. Here's my code:

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();
}

}

The problem is that the log line on

Log.println(Log.DEBUG, TAG, String.format("Amplitude at %3d Hz: %8.3f", (int) fft.binToHz(i, sampleRate), amplitudes[i]));

doesn't print anything. Any help? Here's my log:

    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

P.S. It looks like the process function isn't running. the processingFinished runs though.

Update: It was a problem with handler, I don't know why but when I moved the code inside run(View view) to onTouchEvent it worked fine.


Solution

  • It turns out android studio (java) works in a weird way when it comes to logging on threads other than main thread.