1

I have been trying to generate a tone (444 hz, 1000 hz, etc) and then play it in Android. My first searches gave me this stack overflow question. While this works great given a duration, I would prefer to make the duration infinite (loop-able).

First I used only use integer values for the tone, because this would mean that I could use 1 second and it should loop properly. However there are still some frequencies that don't loop right.

Second I thought I could only calculate 1 period of the sine wave, and then loop that. However I found out that is not a viable approach

How can I, given any frequency, generate a tone that I can loop?

Community
  • 1
  • 1
Flynn
  • 5,903
  • 7
  • 38
  • 55

1 Answers1

0

You can create a thread that will run your tone every period of time(for example 2sec.):

private Runnable startSoundRunnable = new Runnable() {
  @Override
  public void run() {
    while (true) {
      try {
        toneGenerator.startTone(ToneGenerator.TONE_CDMA_ALERT_AUTOREDIAL_LITE, 2000);
        sleep(2000);
      } catch (Exception ex) {}
    }
  }
};

// Run thread
new Thread(startSoundRunnable).start();
olllejik
  • 1,404
  • 1
  • 10
  • 13