Senin, 14 Maret 2011

Creating Tone With Java

Actually this is my little research to make a simple multimedia apps. I start to make an application that make a tone based on the frequency and the duration. A lot of thanks for Princeton to provide this class It's very usefull to make this application work well.
This a method for create the tone.
private double[] tone(double hz, double duration) {
int N = (int) (StdAudio.SAMPLE_RATE * duration);
double[] a = new double[N+1];
for (int i = 0; i <= N; i++) { a[i] = Math.sin(2 * Math.PI * i * hz / StdAudio.SAMPLE_RATE); } return a; }

After make that method, we just call the variable that using the tone method, and play it with play method in StdAudio class. The example for implementation is below:
double[] a = tone(frek, dur);;

The capture of application

For more source you can download here ( Sorry for using this link, because there is no tools for uploading a file in my blog ). I use netbeans for develop it.