Path: blob/main/src/lwjgl/java/javazoom/jl/decoder/SampleBuffer.java
8650 views
/*1* 11/19/04 1.0 moved to LGPL.2*3* 12/12/99 Initial Version based on FileObuffer. [email protected].4*5* FileObuffer:6* 15/02/99 Java Conversion by E.B ,[email protected]7*8*-----------------------------------------------------------------------9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU Library General Public License as published11* by the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU Library General Public License for more details.18*19* You should have received a copy of the GNU Library General Public20* License along with this program; if not, write to the Free Software21* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*----------------------------------------------------------------------23*/2425package javazoom.jl.decoder;2627/**28* The <code>SampleBuffer</code> class implements an output buffer29* that provides storage for a fixed size block of samples.30*/31public class SampleBuffer extends Obuffer32{33private short[] buffer;34private int[] bufferp;35private int channels;36private int frequency;3738/**39* Constructor40*/41public SampleBuffer(int sample_frequency, int number_of_channels)42{43buffer = new short[OBUFFERSIZE];44bufferp = new int[MAXCHANNELS];45channels = number_of_channels;46frequency = sample_frequency;4748for (int i = 0; i < number_of_channels; ++i)49bufferp[i] = (short)i;5051}5253public int getChannelCount()54{55return this.channels;56}5758public int getSampleFrequency()59{60return this.frequency;61}6263public short[] getBuffer()64{65return this.buffer;66}6768public int getBufferLength()69{70return bufferp[0];71}7273/**74* Takes a 16 Bit PCM sample.75*/76public void append(int channel, short value)77{78buffer[bufferp[channel]] = value;79bufferp[channel] += channels;80}8182public void appendSamples(int channel, float[] f)83{84int pos = bufferp[channel];8586short s;87float fs;88for (int i=0; i<32;)89{90fs = f[i++];91fs = (fs>32767.0f ? 32767.0f92: (fs < -32767.0f ? -32767.0f : fs));9394s = (short)fs;95buffer[pos] = s;96pos += channels;97}9899bufferp[channel] = pos;100}101102103/**104* Write the samples to the file (Random Access).105*/106public void write_buffer(int val)107{108109//for (int i = 0; i < channels; ++i)110// bufferp[i] = (short)i;111112}113114public void close()115{}116117/**118*119*/120public void clear_buffer()121{122for (int i = 0; i < channels; ++i)123bufferp[i] = (short)i;124}125126/**127*128*/129public void set_stop_flag()130{}131}132133134