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 9118943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:16:33+00:00 2026-06-17T05:16:33+00:00

I have this method: public double sineWave(double t) { return amplitude==0?0:Math.sin(t * frequency *

  • 0

I have this method:

public double sineWave(double t) 
{
   return amplitude==0?0:Math.sin(t * frequency * Math.PI*2 + phase) * amplitude;
}

It is called by another method in another class to generate a sample of a simple sine wave, which is then added in a buffer to send to the sound card. t is the time. For some reason, the more the application calls this method, the slower it gets. It just makes no sense, after 15 seconds it’s slow enough to use a full core of my CPU and make the audio stutter.

I’m 100% sure it’s this piece of code, because if I replace it with a return 0, the time it takes to run it (measured with System.nanotime()) is constant.

Why is this happening? Is there something I can do to fix this?

  • 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-06-17T05:16:35+00:00Added an answer on June 17, 2026 at 5:16 am

    From the information here – while it is not clear how big your buffer is, you are incrementing t with each iteration. Assuming your frequency is quite high, you are increasing the Sin() argument with each iteration.
    Have checks to see if the argument is constantly increasing to a very high value.
    A quick and dirty test shows that Sin performance goes down –

    public class SinTest {
      public static void main(String args[]) {
        long angle = Long.parseLong(args[0]);
        long startTime = System.nanoTime();
        for(long l=0L; l<=1000000L; l++) {
          Math.sin(angle);
        }
        long estimatedTime = System.nanoTime() - startTime;
        System.out.println(estimatedTime);
      }
    }
    
    $ java SinTest 100000
    29181000
    $ java SinTest 10000000
    138598000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this method: public def getXScaleFactor(panelWidth: Int): Double = { return (panelWidth /
I need some help on simplifying my method I have this method public double
I have this two objects class RNB { public RNB(double roomRate, double roomDays) {
I have this method: public void testJSNI2(){ String x = test; } I can
I have this method: public CampaignCreative GetCampaignCreativeById(int id) { using (var db = GetContext())
In code-behind of an ASP.NET page I have this method: public string TestFunc() {
I have this method call: public DataTemplate Create(Type type, string propertyName) { string str
I have this recursive method: public Hund getMor(int id) { Hund barn = getHund(id);
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;
I have this method in cs page: public String getToolTip(Object productId, Object imgBtnId) {

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.