package com.mindprod.sound;
import sun.audio.AudioPlayer;
import java.io.ByteArrayInputStream;
import static java.lang.System.*;
/**
* 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.
* @since 1997-12-05
*/
public final class Sound
{
private static final int FIRST_COPYRIGHT_YEAR = 1998;
/**
* @noinspection UnusedDeclaration
*/
private static final String EMBEDDED_COPYRIGHT =
"Copyright: (c) 1998-2017 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. ) ) );
}
out.println( "Creating U_Law" );
U_Law ulaw = new U_Law( " Whoop, whoop, whoop", pcm_linear );
byte[] newb = ulaw.toBytes();
out.println( "Playing U_Law" );
ByteArrayInputStream bis = new ByteArrayInputStream( newb );
AudioPlayer.player.start( bis );
Thread.sleep( length * 1000 );
}
catch ( Exception e )
{
e.printStackTrace( System.err );
err.println();
}
}
}