1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*
* 11/19/04 1.0 moved to LGPL.
*
* 12/12/99 Initial Version based on FileObuffer. mdm@techie.com.
*
* FileObuffer:
* 15/02/99 Java Conversion by E.B ,javalayer@javazoom.net
*
*-----------------------------------------------------------------------
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library 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 Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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;
/**
* The <code>SampleBuffer</code> class implements an output buffer
* that provides storage for a fixed size block of samples.
*/
public class SampleBuffer extends Obuffer
{
private short[] buffer;
private int[] bufferp;
private int channels;
private int frequency;
/**
* Constructor
*/
public SampleBuffer(int sample_frequency, int number_of_channels)
{
buffer = new short[OBUFFERSIZE];
bufferp = new int[MAXCHANNELS];
channels = number_of_channels;
frequency = sample_frequency;
for (int i = 0; i < number_of_channels; ++i)
bufferp[i] = (short)i;
}
public int getChannelCount()
{
return this.channels;
}
public int getSampleFrequency()
{
return this.frequency;
}
public short[] getBuffer()
{
return this.buffer;
}
public int getBufferLength()
{
return bufferp[0];
}
/**
* Takes a 16 Bit PCM sample.
*/
public void append(int channel, short value)
{
buffer[bufferp[channel]] = value;
bufferp[channel] += channels;
}
public void appendSamples(int channel, float[] f)
{
int pos = bufferp[channel];
short s;
float fs;
for (int i=0; i<32;)
{
fs = f[i++];
fs = (fs>32767.0f ? 32767.0f
: (fs < -32767.0f ? -32767.0f : fs));
s = (short)fs;
buffer[pos] = s;
pos += channels;
}
bufferp[channel] = pos;
}
/**
* Write the samples to the file (Random Acces).
*/
public void write_buffer(int val)
{
//for (int i = 0; i < channels; ++i)
// bufferp[i] = (short)i;
}
public void close()
{}
/**
*
*/
public void clear_buffer()
{
for (int i = 0; i < channels; ++i)
bufferp[i] = (short)i;
}
/**
*
*/
public void set_stop_flag()
{}
}
|