/* $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" 
 */

// DelaySoundFilter.java

//
// Description:
//	A simple delay sound filter
//	  
// Author:
//	Peter Pilgrim Wed Jun 23 00:01:03 BST 1999
//	  
// RCS HEADER
// 
// $Author$
// $Date$
// $Source$
// $Revision$    $State$    $Locker$
//
// ================================================================================
// History
//	  $Log$
// 
// 

package xenon.soundkit;

/**
 * Reverse the sound buffer clip making the sound go backwards 
 *
 *
 * @author Peter Pilgrim Wed Jun 23 00:03:41 BST 1999
 * @version $Id$
 */
public class ReverseClipFilter extends SoundFilter {
    
    /**
     * Construct a clip reverse with a null parent filter
     */
    public ReverseClipFilter()
    {
	this( null );
    }
    
    /**
     * Construct a clip reverse with a parent filter
     * @param parent the parent sound filter
     */
    public ReverseClipFilter( SoundFilter parent )
    {
	super( parent );
    }
    
    /**
     * filters the sound linear data by added a delayed element
     *
     * @param se the sound engine
     * @param data_buffer the sound filter data buffer
     */
    public void filterLinearData( 
	SoundEngine se, 
	SoundFilterDataBuffer data_buffer )
    {
	// System.out.println("ReverseClipFilter()" );
	
	if ( parent != null ) 
	    parent.filterLinearData( se, data_buffer );

	int    clip_length   = data_buffer.getClipLength();
	int    filter_length = data_buffer.filter_buffer.length;
	int [] filter_buffer = data_buffer.filter_buffer;

	// System.out.println( "length:"+filter_length+" clip_length:"+clip_length+" buffer:"+filter_buffer );
	
	for (int k, j=0; j<clip_length/2; ++j) {
	    k = clip_length-j-1;
	    // if ( j % clip_length/20 == 0 ) System.out.println( "j:"+j+" "+filter_buffer[j]+"  k:"+k+" "+filter_buffer[k] );
	    int tmp = filter_buffer[j];
	    filter_buffer[j] = filter_buffer[k];
	    filter_buffer[k] = tmp;
	    // if ( j % clip_length/20 == 0 ) System.out.println( "j:"+j+" "+filter_buffer[j]+"  k:"+k+" "+filter_buffer[k] );
	}
    }
}

// fini
