54 |
private short[] data; |
private short[] data; |
55 |
private short[][] bankData; |
private short[][] bankData; |
56 |
|
|
57 |
|
/** |
58 |
|
* Creates a new data buffer with a single data bank containing the |
59 |
|
* specified number of <code>short</code> elements. |
60 |
|
* |
61 |
|
* @param size the number of elements in the data bank. |
62 |
|
*/ |
63 |
public DataBufferUShort(int size) |
public DataBufferUShort(int size) |
64 |
{ |
{ |
65 |
super(TYPE_USHORT, size); |
super(TYPE_USHORT, size); |
66 |
data = new short[size]; |
data = new short[size]; |
67 |
} |
} |
68 |
|
|
69 |
|
/** |
70 |
|
* Creates a new data buffer with the specified number of data banks, |
71 |
|
* each containing the specified number of <code>short</code> elements. |
72 |
|
* |
73 |
|
* @param size the number of elements in the data bank. |
74 |
|
* @param numBanks the number of data banks. |
75 |
|
*/ |
76 |
public DataBufferUShort(int size, int numBanks) |
public DataBufferUShort(int size, int numBanks) |
77 |
{ |
{ |
78 |
super(TYPE_USHORT, size, numBanks); |
super(TYPE_USHORT, size, numBanks); |
80 |
data = bankData[0]; |
data = bankData[0]; |
81 |
} |
} |
82 |
|
|
83 |
|
/** |
84 |
|
* Creates a new data buffer backed by the specified data bank. |
85 |
|
* |
86 |
|
* @param dataArray the data bank. |
87 |
|
* @param size the number of elements in the data bank. |
88 |
|
*/ |
89 |
public DataBufferUShort(short[] dataArray, int size) |
public DataBufferUShort(short[] dataArray, int size) |
90 |
{ |
{ |
91 |
super(TYPE_USHORT, size); |
super(TYPE_USHORT, size); |
92 |
data = dataArray; |
data = dataArray; |
93 |
} |
} |
94 |
|
|
95 |
|
/** |
96 |
|
* Creates a new data buffer backed by the specified data bank, with |
97 |
|
* the specified offset to the first element. |
98 |
|
* |
99 |
|
* @param dataArray the data bank. |
100 |
|
* @param size the number of elements in the data bank. |
101 |
|
* @param offset the offset to the first element in the array. |
102 |
|
*/ |
103 |
public DataBufferUShort(short[] dataArray, int size, int offset) |
public DataBufferUShort(short[] dataArray, int size, int offset) |
104 |
{ |
{ |
105 |
super(TYPE_USHORT, size, 1, offset); |
super(TYPE_USHORT, size, 1, offset); |
106 |
data = dataArray; |
data = dataArray; |
107 |
} |
} |
108 |
|
|
109 |
|
/** |
110 |
|
* Creates a new data buffer backed by the specified data banks. |
111 |
|
* |
112 |
|
* @param dataArray the data banks. |
113 |
|
* @param size the number of elements in the data bank. |
114 |
|
* |
115 |
|
* @throws NullPointerException if <code>dataArray</code> is |
116 |
|
* <code>null</code>. |
117 |
|
*/ |
118 |
public DataBufferUShort(short[][] dataArray, int size) |
public DataBufferUShort(short[][] dataArray, int size) |
119 |
{ |
{ |
120 |
super(TYPE_USHORT, size, dataArray.length); |
super(TYPE_USHORT, size, dataArray.length); |
122 |
data = bankData[0]; |
data = bankData[0]; |
123 |
} |
} |
124 |
|
|
125 |
|
/** |
126 |
|
* Creates a new data buffer backed by the specified data banks, with |
127 |
|
* the specified offsets to the first element in each bank. |
128 |
|
* |
129 |
|
* @param dataArray the data banks. |
130 |
|
* @param size the number of elements in the data bank. |
131 |
|
* @param offsets the offsets to the first element in each data bank. |
132 |
|
* |
133 |
|
* @throws NullPointerException if <code>dataArray</code> is |
134 |
|
* <code>null</code>. |
135 |
|
*/ |
136 |
public DataBufferUShort(short[][] dataArray, int size, int[] offsets) |
public DataBufferUShort(short[][] dataArray, int size, int[] offsets) |
137 |
{ |
{ |
138 |
super(TYPE_USHORT, size, dataArray.length, offsets); |
super(TYPE_USHORT, size, dataArray.length, offsets); |
140 |
data = bankData[0]; |
data = bankData[0]; |
141 |
} |
} |
142 |
|
|
143 |
|
/** |
144 |
|
* Returns the first data bank. |
145 |
|
* |
146 |
|
* @return The first data bank. |
147 |
|
*/ |
148 |
public short[] getData() |
public short[] getData() |
149 |
{ |
{ |
150 |
return data; |
return data; |
151 |
} |
} |
152 |
|
|
153 |
|
/** |
154 |
|
* Returns a data bank. |
155 |
|
* |
156 |
|
* @param bank the bank index. |
157 |
|
* @return A data bank. |
158 |
|
*/ |
159 |
public short[] getData(int bank) |
public short[] getData(int bank) |
160 |
{ |
{ |
161 |
return bankData[bank]; |
return bankData[bank]; |
162 |
} |
} |
163 |
|
|
164 |
|
/** |
165 |
|
* Returns the array underlying this <code>DataBuffer</code>. |
166 |
|
* |
167 |
|
* @return The data banks. |
168 |
|
*/ |
169 |
public short[][] getBankData() |
public short[][] getBankData() |
170 |
{ |
{ |
171 |
return bankData; |
return bankData; |
172 |
} |
} |
173 |
|
|
174 |
|
/** |
175 |
|
* Returns an element from the first data bank. The offset (specified in |
176 |
|
* the constructor) is added to <code>i</code> before accessing the |
177 |
|
* underlying data array. |
178 |
|
* |
179 |
|
* @param i the element index. |
180 |
|
* @return The element. |
181 |
|
*/ |
182 |
public int getElem(int i) |
public int getElem(int i) |
183 |
{ |
{ |
184 |
return data[i+offset] & 0xffff; // get unsigned short as int |
return data[i+offset] & 0xffff; // get unsigned short as int |
185 |
} |
} |
186 |
|
|
187 |
|
/** |
188 |
|
* Returns an element from a particular data bank. The offset (specified in |
189 |
|
* the constructor) is added to <code>i</code> before accessing the |
190 |
|
* underlying data array. |
191 |
|
* |
192 |
|
* @param bank the bank index. |
193 |
|
* @param i the element index. |
194 |
|
* @return The element. |
195 |
|
*/ |
196 |
public int getElem(int bank, int i) |
public int getElem(int bank, int i) |
197 |
{ |
{ |
198 |
// get unsigned short as int |
// get unsigned short as int |
199 |
return bankData[bank][i+offsets[bank]] & 0xffff; |
return bankData[bank][i+offsets[bank]] & 0xffff; |
200 |
} |
} |
201 |
|
|
202 |
|
/** |
203 |
|
* Sets an element in the first data bank. The offset (specified in the |
204 |
|
* constructor) is added to <code>i</code> before updating the underlying |
205 |
|
* data array. |
206 |
|
* |
207 |
|
* @param i the element index. |
208 |
|
* @param val the new element value. |
209 |
|
*/ |
210 |
public void setElem(int i, int val) |
public void setElem(int i, int val) |
211 |
{ |
{ |
212 |
data[i+offset] = (short) val; |
data[i+offset] = (short) val; |
213 |
} |
} |
214 |
|
|
215 |
|
/** |
216 |
|
* Sets an element in a particular data bank. The offset (specified in the |
217 |
|
* constructor) is added to <code>i</code> before updating the underlying |
218 |
|
* data array. |
219 |
|
* |
220 |
|
* @param bank the data bank index. |
221 |
|
* @param i the element index. |
222 |
|
* @param val the new element value. |
223 |
|
*/ |
224 |
public void setElem(int bank, int i, int val) |
public void setElem(int bank, int i, int val) |
225 |
{ |
{ |
226 |
bankData[bank][i+offsets[bank]] = (short) val; |
bankData[bank][i+offsets[bank]] = (short) val; |