Path: blob/main/src/lwjgl/java/javazoom/jl/decoder/Obuffer.java
8650 views
/*1* 11/19/04 1.0 moved to LGPL.2* 12/12/99 Added appendSamples() method for efficiency. MDM.3* 15/02/99 ,Java Conversion by E.B ,[email protected], JavaLayer4*5* Declarations for output buffer, includes operating system6* implementation of the virtual Obuffer. Optional routines7* enabling seeks and stops added by Jeff Tsay.8*9* @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:5610* @(#) Copyright (C) 1993, 1994 Tobias Bading ([email protected])11* @(#) Berlin University of Technology12*13* Idea and first implementation for u-law output with fast downsampling by14* Jim Boucher ([email protected])15*16* LinuxObuffer class written by17* Louis P. Kruger ([email protected])18*-----------------------------------------------------------------------19* This program is free software; you can redistribute it and/or modify20* it under the terms of the GNU Library General Public License as published21* by the Free Software Foundation; either version 2 of the License, or22* (at your option) any later version.23*24* This program is distributed in the hope that it will be useful,25* but WITHOUT ANY WARRANTY; without even the implied warranty of26* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the27* GNU Library General Public License for more details.28*29* You should have received a copy of the GNU Library General Public30* License along with this program; if not, write to the Free Software31* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.32*----------------------------------------------------------------------33*/34package javazoom.jl.decoder;3536/**37* Base Class for audio output.38*/39public abstract class Obuffer40{41public static final int OBUFFERSIZE = 2 * 1152; // max. 2 * 1152 samples per frame42public static final int MAXCHANNELS = 2; // max. number of channels4344/**45* Takes a 16 Bit PCM sample.46*/47public abstract void append(int channel, short value);4849/**50* Accepts 32 new PCM samples.51*/52public void appendSamples(int channel, float[] f)53{54short s;55for (int i=0; i<32;)56{57s = clip(f[i++]);58append(channel, s);59}60}6162/**63* Clip Sample to 16 Bits64*/65private final short clip(float sample)66{67return ((sample > 32767.0f) ? 32767 :68((sample < -32768.0f) ? -32768 :69(short) sample));70}7172/**73* Write the samples to the file or directly to the audio hardware.74*/75public abstract void write_buffer(int val);76public abstract void close();7778/**79* Clears all data in the buffer (for seeking).80*/81public abstract void clear_buffer();8283/**84* Notify the buffer that the user has stopped the stream.85*/86public abstract void set_stop_flag();87}888990