/* $Id$
 *
 * Copyright (c) 1999 Xenonsoft Limited. All Rights Reserved.
 *
 * This software is protected by copyright. You are hereby notified from
 * now by reading this message. This software is also the confidential 
 * and proprietary information of Xenonsoft Limited.  ("Confidential
 * Information"). 
 *
 * This software is distributed under the Xenonsoft Public end user 
 * License ("XPeL"), where the machine-readable source code is provided 
 * under the "Open Source" model.
 * For more information, please read the file "LICENSE-XPL.txt" 
 */

// TestSound.java

//
// Description:
//	  Test Sound
//	  
// Author:
//	  Peter Pilgrim
//	  
// RCS HEADER 
// 
// $Author$
// $Date$
// $Source$
// $Revision$    $State$    $Locker$
//
// ================================================================================
// History
//	  $Log$
// 
// 
//

package xenon.soundkit;

import java.io.*;

public class TestSound {

    public static void main ( String [] args )
    {
	System.out.println("=========================================");
	System.out.println("  TEST ENHANCED BBC SOUND INT JAVA ");
	System.out.println("=========================================\n");
	
	PPMCAudioPlayer pp = PPMCAudioPlayer.getInstance();

	InputStream is1 = AudioClipWave.class.getResourceAsStream("audio/ouch.au");
	System.out.println( "is1 = "+is1 );
	InputStream is2 = AudioClipWave.class.getResourceAsStream("audio/yeep.au");
	System.out.println( "is2 = "+is2 );
	
	try {
	    Envelope  env10 = new Envelope( 
		1,  2,2, -2,4, 8,1,     1, 5 ,25, 0, 26, -1, 16, -1, 128 );
	    SoundEngine se10 = new SoundEngine(
		8000, 3.0, 
		100, 261, 40, 
		new AudioClipWave( is1 ), 
		env10 );
	    se10.setFilter( new DelaySoundFilter(25) );
	    se10.makeWave();
	    System.out.println( "play audio wave clip 1 ... ");
	    pp.play( 0, se10.getSoundData() );
	    
	    try { Thread.sleep( 1000 ); } catch ( InterruptedException e ) { ; }

	    SoundEngine se11 = new SoundEngine(
		8000, 3.0, 
		100, 261, 25, 
		new AudioClipWave( is2 ), 
		new Envelope() );

	    se11.setFilter( new DelaySoundFilter(23) );
	    se11.makeWave();
	    System.out.println( "play audio wave clip 2 ... ");	
	    pp.play( 0, se11.getSoundData() );

	    try { Thread.sleep( 1500 ); } catch ( InterruptedException e ) { ; }
	    // System.out.println("**** DEATH 69 ****"); System.exit(69);
	}
	catch (IOException ioe) {
	    System.err.println( ioe.getMessage() );
	}
	

	Envelope  env1 = new Envelope( 
	    1,  2,2, -2,4, 8,1,     1, 5 ,25, 0, 26, -1, 16, -1, 128 );
	SoundEngine se1 = new SoundEngine(
	    8000, 5.0, 
	    100, 525, 80, 
	    StaticWave.SINE_WAVE, 
	    env1 /* new Envelope() */ );
	
	// se1.setFlags( se1.getFlags() | SoundEngine.FM_DELTA_RANDOM_FLAG | SoundEngine.NOISE_MIX_GATE_FLAG );
	// se1.setFilter( new DelaySoundFilter(180) );
	se1.setFilter( new DelaySoundFilter(25) );
	se1.makeWave();
	pp.play( 0, se1.getSoundData() );

	try { Thread.sleep( 3000 ); } catch ( InterruptedException e ) { ; }
	

	Envelope  env2 = new Envelope( 
	    1,  2,2, -2,4, 8,1,     1, 13 ,13, -1, 10, 0, 0, -1, 128 );
	
	SoundEngine se2 = new SoundEngine( 
	    8000, 1.75, 
	    100, 450, 96,
	    StaticWave.SQUARE_WAVE, env2 );
	
	se2.makeWave();
	pp.play( 0, se2.getSoundData() );
	
	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }

	Envelope  env3 = new Envelope( 
	    1,  4,4, -2,4, 8,4,     1, 13 ,14, -1, 10, 0, 0, -1, 128 );
	
	SoundEngine se3 = new SoundEngine( 
	    8000, 1.75, 
	    321, 96, 100, 
	    StaticWave.PERIODIC_WHITE_NOISE_WAVE, env3 );
	
	se3.setFlags( se3.getFlags() | SoundEngine.NOISE_MIX_GATE_FLAG  );
	se1.setFilter( new ReverseClipFilter() );
	se3.makeWave();
	pp.play( 1, se3.getSoundData() );
	
	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }

	Envelope  env4 = new Envelope( 
	    1,  4,4, -2,4, 8,4,     1, 13 ,14, -1, 10, 0, 0, -10, 128 );
	
	SoundEngine se4 = new SoundEngine( 
	    8000, 1.75, 
	    100, 747, 96,
	    StaticWave.SQUARE_WAVE, env4 );
	
	se4.makeWave();
	pp.play( 2, se4.getSoundData() );
	
	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }


	Envelope  env5 = new Envelope( 
	    1,  1,1, -1,2, 2,3,     1, 13 ,14, -1, 10, 0, 0, -10, 128 );
	
	SoundEngine se5 = new SoundEngine( 
	    8000, 1.75, 
	    100, 747, 96, 
	    StaticWave.TRIANGLE_WAVE, env5 );
	
	se3.setFlags( se3.getFlags() | SoundEngine.HOLD_PITCH_MODULATION );
	se5.makeWave();
	pp.play( 3, se5.getSoundData() );
			
	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }

	Envelope env6 = new Envelope( 
	    1, 1,1, 1,1, 2,1,
	    1, 128,1, 0,128, 0,128, -1,128 );
	SoundEngine se6 = new SoundEngine( 
	    8000, 8.0, 127, 590, 100,
	    StaticWave.SINE_WAVE, env6 );
	se6.setFlags( SoundEngine.NOISE_GATE_FLAG );
	se6.makeWave();
	pp.play( 8, se6.getSoundData() );

	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }

	SoundEngine se7 = new SoundEngine( 
	    8000, 1.75, 
	    321, 96, 100, 
	    new WhiteNoiseWave(), env3 );
	
	pp.play( 2, se7.getSoundData() );

	try { Thread.sleep( 2000 ); } catch ( InterruptedException e ) { ; }

	System.out.println("********** THE END!!! **********");	
	pp.play( 0, se1.getSoundData() );
	pp.play( 1, se2.getSoundData() );
	pp.play( 2, se3.getSoundData() );
	pp.play( 3, se4.getSoundData() );
	pp.play( 4, se5.getSoundData() );

	try { Thread.sleep( 5000 ); } catch ( InterruptedException e ) { ; }

	System.exit(0);
    }
    
}

// fini
