package com.mindprod.sound;
import sun.audio.AudioPlayer;
import java.io.ByteArrayInputStream;
/**
* Sound.java Generate a sound created mathematically.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.4 2007-05-22 add PAD and icon, more IntelliJ inspect tidying.
*/
public final class Sound
{
/**
* @noinspection UnusedDeclaration
*/
private static final String EMBEDDED_COPYRIGHT =
"copyright (c) 1998-2009 Roedy Green, Canadian Mind Products, http://mindprod.com";
/**
* @noinspection UnusedDeclaration
*/
private static final String RELEASE_DATE = "2007-05-24";
/**
* @noinspection UnusedDeclaration
*/
private static final String VERSION_STRING = "1.4";
public static void main( String[] args )
{
try
{
int length = 4;
short[] pcm_linear = new short[8000 * length];
for ( int i = 0; i < pcm_linear.length; i++ )
{
pcm_linear[ i ] =
( short ) ( 16000 * Math.sin( i * ( 120. * 2 * Math.PI
/ 8000. ) ) );
}
System.out.println( "Creating U_Law" );
U_Law ulaw = new U_Law( " Whoop, whoop, whoop", pcm_linear );
byte[] newb = ulaw.toBytes();
System.out.println( "Playing U_Law" );
ByteArrayInputStream bis = new ByteArrayInputStream( newb );
AudioPlayer.player.start( bis );
Thread.sleep( length * 1000 );
}
catch ( Exception e )
{
e.printStackTrace();
}
}
}