开发者

Is ToneGenerator sound smooth?

Does anyone have the same problem?

On Android's Phone app, whenever a number is pressed, the tone is always smooth.

But, when I used very similar code as the Phone app, the tone I get regularly isn't smooth...there are gaps. Is there a way to resolve this?

Some of my theories are that the emulator causes these breaks in sound as there are time lags in processing. The Phone app on the emulator is also more "compiled"/native than my code. Etc. Don't know what is the reason for these tones not being continuous.

Here's the code (literally the same as Phone app):

...
playTone(ToneGenerator.TONE_DTMF_1,150);
...


void playTone(int tone) {
    // if local tone playback is disabled, just return.
    if (!mDTMFToneEnabled) {
        return;
    }

    // Also do nothing if the phone is in silent mode.
    // We need to re-check the ringer mode for *every* playTone()
    // call, rather than keeping a local flag that's updated in
    // onResume(), since it's possible to toggle silent mode without
    // leaving the current activity (via the ENDCALL-longpress menu.)
    AudioManager audioManager = (AudioManager) getSystemService(开发者_开发技巧Context.AUDIO_SERVICE);
    int ringerMode = audioManager.getRingerMode();
    if ((ringerMode == AudioManager.RINGER_MODE_SILENT)
            || (ringerMode == AudioManager.RINGER_MODE_VIBRATE)) {
        return;
    }

    synchronized (mToneGeneratorLock) {
        if (mToneGenerator == null) {
            Log.w("test", "playTone: mToneGenerator == null, tone: " + tone);
            return;
        }

        // Start the new tone (will stop any playing tone)
        mToneGenerator.startTone(tone, TONE_LENGTH_MS);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜