MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / floatsFromFile

Method floatsFromFile

src/main/java/trace/sound/Sound.java:181–216  ·  view source on GitHub ↗
(String filename)

Source from the content-addressed store, hash-verified

179 }
180 }
181 return (data.data.limit() / sz) / ((double) s);
182
183 }
184
185 static public FloatBuffer floatsFromFile(String filename)
186 throws FileNotFoundException {
187
188 WaveData data = WaveData.create(new BufferedInputStream(
189 new FileInputStream(filename)));
190
191 System.out.println(" format :" + data.format + " " + data.samplerate
192 + " " + data.data + " " + data.data.capacity());
193 try {
194 switch (data.format) {
195 case AL10.AL_FORMAT_MONO16: {
196 FloatBuffer f = FloatBuffer.allocate(data.data.capacity() / 2);
197 System.out.println(" mono 16");
198 ShortBuffer s = data.data.asShortBuffer();
199 for (int i = 0; i < s.capacity(); i++) {
200 f.put(s.get(i) / (float) Short.MAX_VALUE);
201 }
202 return f;
203 }
204 case AL10.AL_FORMAT_STEREO16: {
205 FloatBuffer f = FloatBuffer.allocate(data.data.capacity() / 4);
206 System.out.println(" stereo 16, taking left channel");
207 ShortBuffer s = data.data.asShortBuffer();
208 for (int i = 0; i < s.capacity() / 2; i++) {
209 f.put(s.get(i * 2) / (float) Short.MAX_VALUE);
210 }
211 return f;
212 }
213 default:
214 break;
215 }
216 } finally {
217 data.dispose();
218 }
219 return null;

Callers

nothing calls this directly

Calls 5

getMethod · 0.65
createMethod · 0.45
printlnMethod · 0.45
allocateMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected