Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6145013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:44:02+00:00 2026-05-23T18:44:02+00:00

I want to do some FSK Modulation over the audio port. So the problem

  • 0

I want to do some FSK Modulation over the audio port. So the problem is that my sinus wave isn’t very good. It is disturb by even parts. I used the code original from http://marblemice.blogspot.com/2010/04/generate-and-play-tone-in-android.html with the further modification from Playing an arbitrary tone with Android and https://market.android.com/details?id=re.serialout&feature=search_result .
So where is the failure? What do I wrong?

private static int bitRate=300;
private static int sampleRate=48000;
private static int freq1=600;

public static void loopOnes(){
    playque.add(UARTHigh);
    athread.interrupt();
}

    private static byte[] UARTHigh() {
    int numSamples=sampleRate/bitRate;
    double sample[]=new double[numSamples];
    byte[] buffer=new byte[numSamples*2];
    for(int i=0; i<numSamples;++i){
        sample[i]=Math.sin(2*Math.PI*i*freq1/sampleRate);
    }
    int idx = 0;
    for (final double dVal : sample) {
        // scale to maximum amplitude
        final short val = (short) ((dVal * 32767));
        // in 16 bit wav PCM, first byte is the low order byte
        buffer[idx++] = (byte) (val & 0x00ff);
        buffer[idx++] = (byte) ((val & 0xff00) >>> 8);
    }
    return buffer;
}

private static void playSound(){
    active = true;
    while(active)
    {
        try {Thread.sleep(Long.MAX_VALUE);} catch (InterruptedException e) {
            while (playque.isEmpty() == false)
            {
                if (atrk != null)
                {
                    if (generatedSnd != null)
                    {   
                        // Das letzte Sample erst fertig abspielen lassen
                        // systemClock.sleep(xx) xx könnte angepasst werden
                        while (atrk.getPlaybackHeadPosition() < (generatedSnd.length))
                            SystemClock.sleep(50);  // let existing sample finish first: this can probably be set to a smarter number using the information above
                    }
                    atrk.release();
                }
                UpdateParameters(); // might as well do it at every iteration, it's cheap
                generatedSnd = playque.poll();

                length = generatedSnd.length;
                if (minbufsize<length)
                    minbufsize=length;
                atrk = new AudioTrack(AudioManager.STREAM_MUSIC,
                        sampleRate, AudioFormat.CHANNEL_CONFIGURATION_MONO,
                        AudioFormat.ENCODING_PCM_16BIT, minbufsize,
                        AudioTrack.MODE_STATIC);

                atrk.setStereoVolume(1,1);
                atrk.write(generatedSnd, 0, length); 
                atrk.play();    
            }
            // Playque is Empty =>send StopBit!
            // Set Loop Points
            int setLoopError=atrk.setLoopPoints(0, length, -1);
            atrk.play();
        }
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:44:03+00:00Added an answer on May 23, 2026 at 6:44 pm

    So the answer is to change from MODE_STATIC to MODE_STREAM and don’t use Looping Points. In a new thread with low priority a busy loop writes the tracks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want some tags to be added to an article. The problem is that
I have some playing cards that flip over when you tap them. I want
I want some tutorials or some help from that i can get idea of
I just want some simple links where if it's hovered over, instead of having
In C++ if we do not want some statements to compile into code that
I want some application to look like widget inside my Python application. That's all.
I just want some kind of simple text overlay that shows for a few
My app contained download button and whenever that button is pressed, I want some
Let's say I have a menu that contains everything. But, I want some elements
I want some API's and some Document So that i can convert any file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.