JorenSix / TarsosDSP

A Real-Time Audio Processing Framework in Java
http://0110.be/tag/TarsosDSP
GNU General Public License v3.0
1.94k stars 471 forks source link

Sinewave output not working on Android #119

Open rednebmas opened 7 years ago

rednebmas commented 7 years ago

When I run the following code, the output sounds garbled, even though it should be a simple sine wave. This occurs on both the simulator and a device. Am I missing something basic, or this a bug? Or a configuration issue?

I also tried running the generator on a new thread and that did not work either.

/**
 * In MainActivity
 */

this.pitchGenerator = new PitchGenerator();
this.pitchGenerator.play(440);

/**
 * In PitchGenerator.java
 */

import be.tarsos.dsp.io.TarsosDSPAudioFormat;
import be.tarsos.dsp.AudioGenerator;
import be.tarsos.dsp.io.android.AndroidAudioPlayer;
import be.tarsos.dsp.synthesis.SineGenerator;

public class PitchGenerator  {
    private AudioGenerator generator;

    public PitchGenerator() {}

    public void play(double freq) {
        AudioGenerator generator = new AudioGenerator(512,0);
        generator.addAudioProcessor(new SineGenerator(0.3, freq));
        generator.addAudioProcessor(new AndroidAudioPlayer( new TarsosDSPAudioFormat(44100, 16, 1, true, false)));
        generator.run();
    }
}
brudzio commented 7 years ago

Hi @rednebmas did you manage to resolve the issue? I'm facing same problem, tried to play with buffer length, overlap etc. but nothing works for me.

buganini commented 5 years ago

Inside SineGenerator.java change buffer[i] += (float) (gain * Math.sin(twoPiF * time + phase)); to buffer[i] = (float) (gain * Math.sin(twoPiF * time + phase));