i have some code that will make sound, a sine wave, actually, but i want to be able to actually play more than one sound at once, how can i modify this code to make it work. i found this on the internet somewhere, and it was hard to find.
import javax.sound.sampled.* ;
public class test {
public static void main ( String [ ] args ) {
int seconds = 1 ;
int sampleRate = 8000 ;
double frequency = 200.0 ;
double RAD = 2.0 * Math.PI ;
try {
AudioFormat af = new AudioFormat ( ( float ) sampleRate , 8 , 1 ,
true , true ) ;
DataLine.Info info = new DataLine.Info ( SourceDataLine.class , af ) ;
SourceDataLine source = ( SourceDataLine ) AudioSystem
.getLine ( info ) ;
source.open ( af ) ;
source.start ( ) ;
byte [ ] buf = new byte [ sampleRate * seconds ] ;
for ( int i = 0 ; i < buf.length ; i ++ ) {
buf [ i ] = ( byte ) ( Math.sin ( RAD * frequency / sampleRate
* i ) * 127.0 ) ;
System.out.println ( buf [ i ] ) ;
}
source.write ( buf , 0 , buf.length ) ;
source.drain ( ) ;
source.stop ( ) ;
source.close ( ) ;
} catch ( Exception e ) {
System.out.println ( e ) ;
}
System.exit ( 0 ) ;
}
}