33package com.jogamp.audio.windows.waveout;
38 private final byte[] data;
39 private final boolean needsByteSwap;
41 private final int bytesPerSample;
42 private int numSamples;
43 private boolean playing;
44 private boolean empty;
47 SoundBuffer(
final int size,
final int bytesPerSample,
final boolean needsByteSwap) {
48 this.bytesPerSample = bytesPerSample;
49 this.needsByteSwap = needsByteSwap;
50 data =
new byte[size * bytesPerSample];
58 void playing(
final boolean playing) {
59 this.playing = playing;
66 void empty(
final boolean empty) {
70 void fill(
final InputStream input)
throws IOException {
73 throw new IllegalStateException(
"Can not fill a buffer that is playing");
78 final int num = input.read(data);
81 numSamples = numBytes / bytesPerSample;
83 if ((numBytes % bytesPerSample) != 0) {
84 System.out.println(
"WARNING: needed integral multiple of " + bytesPerSample +
85 " bytes, but read " + numBytes +
" bytes");
99 float getSample(
final int sample) {
100 final int startByte = sample * bytesPerSample;
104 for (
int i = startByte + bytesPerSample - 1; i >= startByte; i--) {
106 res |= (data[i] & 0xff);
109 final int endByte = startByte + bytesPerSample - 1;
110 for (
int i = startByte; i <= endByte; i++) {
112 res |= (data[i] & 0xff);
116 if (bytesPerSample == 2) {
118 }
else if (bytesPerSample == 1) {