0

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.

Hassan Pezeshk
  • 343
  • 5
  • 16
  • Are you sure that the array `amplitudes` has actual entries to loop over? You should try to print a log message outside of the loop or put a break point inside the loop to make sure the code is actually executing. – Bobbake4 Oct 25 '16 at 17:13
  • try something like this Log.d("Debug","Debug error to log"); if this should work then you should check the content of string.format – Babajide Apata Oct 25 '16 at 17:15
  • @Bobbake4 tried that still nothing – Hassan Pezeshk Oct 25 '16 at 17:23
  • @BabajideApata this doesn't work – Hassan Pezeshk Oct 25 '16 at 17:23
  • @user3484400 What do you mean still does nothing? Did you check to make sure that line is actually executing? Are you positive `amplitudes` contains a few entries? – Bobbake4 Oct 25 '16 at 17:33
  • @Bobbake4 I can't check the amplitudes because of it's scope (I can't get logs there!!!), and logs outside the loop doesn't work either. – Hassan Pezeshk Oct 25 '16 at 17:39
  • Do You call `run()` method from `onCreate()` or other place of code? – Andrii Omelchenko Oct 25 '16 at 17:42
  • @user3484400 You can run the application in debug mode and put a break point on a bunch of lines to step through the execution and find where things are going wrong. – Bobbake4 Oct 25 '16 at 17:45
  • @Bobbake4 Hey i am facing same issue AddAudioprocessor process not excuting and also getting this in logs:CANNOT LINK EXECUTABLE "/data/user/0/com.service.ps.musicplayerpoc/cache/ffmpeg": /data/data/com.service.ps.musicplayerpoc/cache/ffmpeg: has text relocations. Plzz help struggling with this from last 2 days. Thankx in advance – Avinash Jain May 31 '18 at 10:45

3 Answers3

0

Turn off the instant run feature of Android Studio, uninstall the app, clean the project and then run the app. This helped me once, may be for you. Best of luck.

Dushyant Suthar
  • 673
  • 2
  • 9
  • 27
0

May be You forgot to call protected void run(View view) method?

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
0

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

Hassan Pezeshk
  • 343
  • 5
  • 16