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

  • Home
  • SEARCH
  • 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 97617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:02:21+00:00 2026-05-11T00:02:21+00:00

I’m looking for Java code that can be used to generate sound at runtime

  • 0

I’m looking for Java code that can be used to generate sound at runtime – NOT playback of existing sound files.

For example, what’s the best code for generating a sawtooth waveform at 440 Hz for a duration of 2 milliseconds? Source code appreciated!

I remember my Commodore 128 had a simple Sound command that took as parameters voice, frequency, waveform, and duration to define a sound. That worked great in a lot of simple cases (quick and dirty games, experiments with sound, etc).

I am looking specifically for sound-effect like sounds, not music or MIDI (which the JFugue library covers quite well).

  • 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. 2026-05-11T00:02:21+00:00Added an answer on May 11, 2026 at 12:02 am

    You can easily generate sampled sound data in Java and play it back without using native code. If you’re talking MIDI things may get tricky, but I’ve not dabbled in that area.

    To generate sampled sound data, you have to thing of the process backwards. We’re going to act like the A-to-D and sample a continuous sound function over time. Your sound card does the same thing for audio through a mic or line in.

    First, choose a sample rate (NOT the freq of the tone we’re generating). Let’s go with 44100 hz since that’s likely the sound card playback rate (thus no sample rate conversion, that’s not easy unless hardware does it).

    // in hz, number of samples in one second sampleRate = 44100  // this is the time BETWEEN Samples samplePeriod = 1.0 / sampleRate  // 2ms duration = 0.002; durationInSamples = Math.ceil(duration * sampleRate);  time = 0; for(int i = 0; i < durationInSamples; i++) {   // sample a sine wave at 440 hertz at each time tick   // substitute a function that generates a sawtooth as a function of time / freq   // rawOutput[i] = function_of_time(other_relevant_info, time);   rawOutput[i] = Math.sin(2 * Math.PI * 440 * time);   time += samplePeriod; }  // now you can playback the rawOutput // streaming this may be trickier 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 160k
  • Answers 160k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The way I understand this problem is that you have… May 12, 2026 at 11:33 am
  • Editorial Team
    Editorial Team added an answer You could use the Batch operation from MoreLINQ: Person[] array… May 12, 2026 at 11:33 am
  • Editorial Team
    Editorial Team added an answer If you're interested in any white space (including tabs etc),… May 12, 2026 at 11:33 am

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.