836ff889891d01e9e1b223e4c8be4bdc277bdd5d
[IRC.git] / Robust / src / Tests / ssJava / mp3decoder / Obuffer.java
1 /* 
2  * 11/19/04  1.0 moved to LGPL.
3  * 12/12/99  Added appendSamples() method for efficiency. MDM.
4  * 15/02/99 ,Java Conversion by E.B ,ebsp@iname.com, JavaLayer
5  *
6  *   Declarations for output buffer, includes operating system
7  *   implementation of the virtual Obuffer. Optional routines
8  *   enabling seeks and stops added by Jeff Tsay. 
9  *
10  *  @(#) obuffer.h 1.8, last edit: 6/15/94 16:51:56
11  *  @(#) Copyright (C) 1993, 1994 Tobias Bading (bading@cs.tu-berlin.de)
12  *  @(#) Berlin University of Technology
13  *
14  *  Idea and first implementation for u-law output with fast downsampling by
15  *  Jim Boucher (jboucher@flash.bu.edu)
16  *
17  *  LinuxObuffer class written by
18  *  Louis P. Kruger (lpkruger@phoenix.princeton.edu)
19  *-----------------------------------------------------------------------
20  *   This program is free software; you can redistribute it and/or modify
21  *   it under the terms of the GNU Library General Public License as published
22  *   by the Free Software Foundation; either version 2 of the License, or
23  *   (at your option) any later version.
24  *
25  *   This program is distributed in the hope that it will be useful,
26  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
27  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
28  *   GNU Library General Public License for more details.
29  *
30  *   You should have received a copy of the GNU Library General Public
31  *   License along with this program; if not, write to the Free Software
32  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33  *----------------------------------------------------------------------
34  */
35
36 /**
37  * Base Class for audio output.
38  */
39 @LATTICE("")
40 @METHODDEFAULT("D<IN,D<C,C*,THISLOC=D")
41 public abstract class Obuffer
42 {
43  public static final int     OBUFFERSIZE = 2 * 1152;  // max. 2 * 1152 samples per frame
44  public static final int   MAXCHANNELS = 2;        // max. number of channels
45
46   /**
47    * Takes a 16 Bit PCM sample.
48    */
49   public abstract void append(int channel, short value);
50
51   /**
52    * Accepts 32 new PCM samples. 
53    */
54   public void appendSamples(@LOC("IN") int channel, @LOC("IN") float[] f)
55   {
56     @LOC("DELTA(DELTA(D))") short s;
57     for (@LOC("C") int i=0; i<32;)
58     {
59       s = clip(f[i++]); // flow from "IN" to "D"
60       append(channel, s);  
61     }
62   }
63
64   /**
65    * Clip Sample to 16 Bits
66    */
67   @RETURNLOC("D")
68   private final short clip(@LOC("IN") float sample)
69   {
70     
71     @LOC("D") short s=(short)sample;
72     
73     if(sample > 32767.0f){
74       s=(short)32767;
75     }else if(sample < -32768.0f){
76       s=(short)-32768;
77     }
78     
79     return s;
80
81 //    return ((sample > 32767.0f) ?   (short) 32767 :
82 //      ((sample < -32768.0f) ?  (short)  -32768 :
83 //        (short) sample));
84   }
85
86   /**
87    * Write the samples to the file or directly to the audio hardware.
88    */
89   public abstract void write_buffer(int val);
90   public abstract void close();
91
92   /**
93    * Clears all data in the buffer (for seeking).
94    */
95   public abstract void clear_buffer();
96
97   /**
98    * Notify the buffer that the user has stopped the stream.
99    */
100   public abstract void set_stop_flag();
101 }