⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 obuffer.java

📁 java处理声音文件
💻 JAVA
字号:
/* 
 * 12/12/99  Added appendSamples() method for efficiency. MDM.
 * 15/02/99 ,Java Conversion by E.B ,ebsp@iname.com, JavaLayer
 *----------------------------------------------------------------------------- 
 * obuffer.h
 *
 *    Declarations for output buffer, includes operating system
 *   implementation of the virtual Obuffer. Optional routines
 *   enabling seeks and stops added by Jeff Tsay. 
 *   
 *
 *  @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:56
 *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
 *  @(#) Berlin University of Technology
 *
 *  Idea and first implementation for u-law output with fast downsampling by
 *  Jim Boucher (jboucher@flash.bu.edu)
 *
 *  LinuxObuffer class written by
 *  Louis P. Kruger (lpkruger@phoenix.princeton.edu)
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------------
 */
package javazoom.jl.decoder;

/**
 * Base Class for audio output.
 */
public abstract class Obuffer
{
  public static final int	OBUFFERSIZE = 2 * 1152;	// max. 2 * 1152 samples per frame
  public static final int   MAXCHANNELS = 2;        // max. number of channels

  /**
   * Takes a 16 Bit PCM sample.
   */
  public abstract void append(int channel, short value);

  /**
   * Accepts 32 new PCM samples. 
   */
	public void appendSamples(int channel, float[] f)
	{
	    short s;
	    for (int i=0; i<32;)
	    {
		  	s = clip(f[i++]);
			append(channel, s); 
	    }
	}

  /**
   * Clip Sample to 16 Bits
   */
  private final short clip(float sample)
  {
	return ((sample > 32767.0f) ? 32767 :
           ((sample < -32768.0f) ? -32768 :
			  (short) sample));
  }
  
  /**
   * Write the samples to the file or directly to the audio hardware.
   */
  public abstract void write_buffer(int val);
  public abstract void close();

  /**
   * Clears all data in the buffer (for seeking).
   */
  public abstract void clear_buffer();

  /**
   * Notify the buffer that the user has stopped the stream.
   */
  public abstract void set_stop_flag();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -