<commit_before>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package edu.cmu.sphinx.frontend;

import edu.cmu.sphinx.util.SphinxProperties;

import java.io.IOException;
import java.util.Vector;
import java.util.Arrays;


/**
 * Slices up an Audio into a number of overlapping
 * windows, and applies a Windowing function to each of them.
 * The number of resulting windows depends on the window
 * size and the window shift (commonly known as frame size and frame
 * shift in speech world). The Window will be applied to each such
 * window. Since the <code>read()</code> method will return a window,
 * and multiple windows are created for each Audio, this
 * is a 1-to-many processor.
 *
 * <p>A window (which is an Audio object) is returned each time
 * <code>Windower.getAudio()</code> is called.
 *
 * <p> The applied Window, <i>W</i> of length <i>N</i> (usually the
 * window size) is given by the following:
 * <pre>
 * W(n) = (1-a) - (a * cos((2*Math.PI*n)/(N - 1))) </pre> where:
 * <br><b>a</b> is commonly known as the "alpha" value, it defaults to 0.46,
 * the value for the HammingWindow, which is commonly used.
 *
 * <p>The Sphinx property that affects this processor is: <pre>
 * edu.cmu.sphinx.frontend.windower.alpha
 * </pre>
 *
 * @see Audio
 */
public class Windower extends DataProcessor implements AudioSource {


    /**
     * The name of the SphinxProperty for the alpha value of the Window,
     * which has a default value of 0.46 (double), which is the value for the
     * HammingWindow.
     */
    private static final String PROP_ALPHA =
    FrontEnd.PROP_PREFIX + "windower.alpha";


    private AudioSource predecessor;     // the previous processor
    private double[] hammingWindow;      // Hamming window
    private int windowSize;              // size of each window
    private int windowShift;             // the window size
    private Vector outputQueue;          // cache for output windows
    private DoubleBuffer overflowBuffer; // cache for overlapped audio regions
    private Utterance currentUtterance;  // the current Utterance


    /**
     * Constructs a default Windower with the specified context.
     *<commit_msg>Made minor documentation changes to frontend/Windower.java.<commit_after>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */

package edu.cmu.sphinx.frontend;

import edu.cmu.sphinx.util.SphinxProperties;

import java.io.IOException;
import java.util.Vector;
import java.util.Arrays;


/**
 * Slices up an Audio into a number of overlapping
 * windows, and applies a Windowing function to each of them.
 * The number of resulting windows depends on the window
 * size and the window shift (commonly known as frame size and frame
 * shift in speech world). The Window will be applied to each such
 * window. Since the <code>getAudio()</code> method will return a window,
 * and multiple windows are created for each Audio, this
 * is a 1-to-many processor.
 *
 * <p>A window (which is an Audio object) is returned each time
 * <code>Windower.getAudio()</code> is called.
 *
 * <p> The applied Window, <i>W</i> of length <i>N</i> (usually the
 * window size) is given by the following:
 * <pre>
 * W(n) = (1-a) - (a * cos((2*Math.PI*n)/(N - 1))) </pre> where:
 * <br><b>a</b> is commonly known as the "alpha" value, it defaults to 0.46,
 * the value for the HammingWindow, which is commonly used.
 *
 * <p>The Sphinx property that affects this processor is: <pre>
 * edu.cmu.sphinx.frontend.windower.alpha
 * </pre>
 *
 * @see Audio
 */
public class Windower extends DataProcessor implements AudioSource {


    /**
     * The name of the SphinxProperty for the alpha value of the Window,
     * which has a default value of 0.46 (double), which is the value for the
     * HammingWindow.
     */
    private static final String PROP_ALPHA =
	FrontEnd.PROP_PREFIX + "windower.alpha";


    private AudioSource predecessor;     // the previous processor
    private double[] hammingWindow;      // Hamming window
    private int windowSize;              // size of each window
    private int windowShift;             // the window size
    private Vector outputQueue;          // cache for output windows
    private DoubleBuffer overflowBuffer; // cache for overlapped audio regions
    private Utterance currentUtterance;  // the current Utterance


    /**
     * Constructs a default Windower with the specified context.
     *
{'fraction_non_alphanumeric': 0.09037212049616067, 'fraction_numerical': 0.010238235873203386, 'mean_word_length': 3.205298013245033, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6422737', 'n_tokens_mistral': 1517, 'n_tokens_neox': 1410, 'n_words': 603}