Solved

Can I use Java to generate sound?

Posted on 2001-06-13
6
601 Views
Last Modified: 2010-07-27
Hi, dear experts,

Is it possible to use Java to generate my own sound and
send the sound to either speaker or earphone?  I want to
generate sound of different frequencies and play them.


Thank you.
Yours sincerely
Zicai
0
Comment
Question by:zicai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:exorcist
ID: 6185266
take a look at the JMF (Java Media Framework).
0
 
LVL 3

Expert Comment

by:dnoelpp
ID: 6185366
Most simple solution (only play):

AudioClip clip = Applet.newAudioClip(url);
clip.play();

For generating sounds use JMF, as exorcist said. It is really a neat framework. Last year I mimicked a very slow modem (110 bit/sec) via loudspeaker and microphone and did fourier analysis on the recorded sounds. Worked great!
0
 
LVL 1

Accepted Solution

by:
rkumar115 earned 100 total points
ID: 6186699
Java 1.3 provides the Java sound API's which can be used for capturing, processing and playing back audio and MIDI(Musical Instrument Digital Interface) data.

The java Sound web page provides the following information--------

The java Sound API supports the following features:

Audio file formats: AIFF, AU and WAV

Music file formats: MIDI Type 0, MIDI Type 1, and Rich Music Format (RMF)

Sound formats: 8- and 16-bit audio data, in mono and stereo, with sample rates from 8 kHz to 48 kHz  .

Linear, a-law, and mu-law encoded data in any of the supported audio file formats

MIDI wavetable synthesis and sequencing in software, and access to hardware MIDI devices

An all-software mixer that can mix and render up to 64 total channels of digital audio and synthesized MIDI music

he above list describes the reference implementation, not the API itself. The API permits flexible configuration of the audio and MIDI system,including ways for applications to ask the system exactly what resources are installed and available.


There are other java platform APIs that have sound related elements .The JMF(Java Media Framework) is the higher layer API that is currently available as a standard extension to the Java Platform.JMF provides a simpler
solution for basic media-player application programs, and it enables synchronization between different media types, such as audio and video.On the other hand, programs that focus on sound can benefit from the Java Sound API, especially if they require more advanced features, such as
the ability to carefully control buffered audio playback or directly manipulate a MIDI synthesizer. Other Java APIs with sound aspectsinclude Java 3D and APIs for telephony and speech. An implementationof any of these APIs might use an implementation of the Java Sound API internally, but is not required to do so.


The java sound API includes support for both digital video and MIDI data. The functionality for digital video is provided in the package javax.video.sampled
and the functionality for the MIDI is provided in the package javax.sound.midi .


You can get more information in the API programmers guide which is available at the following site
http://java.sun.com/j2se/1.3/docs/guide/sound/


Since java 1.3 provide MIDI you will be able to create the musical sounds and MIDI synthesizers are capable of creating different types of sound.

Hope the above solves your problem
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Author Comment

by:zicai
ID: 6190354
Hi,rkumar115

Do you have some simple samples that can generate sound
and play them? Could you please explain some more on how
to use the MIDI synthesizers?


Thank you very much!
Yours sincerely
Zicai
0
 
LVL 1

Expert Comment

by:rkumar115
ID: 6217936
With JDK1.3.1 Kit you will get the Sound Demo. There is Source code available for that demo. Usually software guys copy these source code in there programs. Rather than I copy a portion of it and give it to you , Its preferable you go through the Source Code Yourself.
You can download the JDK1.3.1 from the javasoft site. It is free.

Best of luck

0
 
LVL 2

Author Comment

by:zicai
ID: 7246076
Hi, rkumar115, thank you very much!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question