33package com.jogamp.audio.windows.waveout;
40 private static final int BUFFER_SIZE = 32768;
42 static final int BYTES_PER_SAMPLE = 2;
44 static final boolean NEEDS_BYTE_SWAP =
true;
47 private SoundBuffer activeBuffer;
49 private int samplePosition;
51 private int totalSamples;
53 private int samplesRead;
55 private SoundBuffer fillingBuffer;
57 private InputStream input;
59 private final File file;
61 private boolean playing;
63 private boolean looping;
65 private volatile Vec3f position =
new Vec3f();
67 Track(
final File file)
throws IOException {
68 if (!file.getName().endsWith(
".rawsound")) {
69 throw new IOException(
"Unsupported file format (currently supports only raw sounds)");
76 activeBuffer =
new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP);
77 fillingBuffer =
new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP);
84 private void openInput()
throws IOException {
85 input =
new BufferedInputStream(
new FileInputStream(file));
86 totalSamples = (int) file.length() / BYTES_PER_SAMPLE;
93 public synchronized void play() {
99 }
catch (
final IOException e) {
113 this.looping = looping;
120 public void setPosition(
final float x,
final float y,
final float z) {
121 position =
new Vec3f(x, y, z);
124 synchronized void fill() throws IOException {
128 final SoundBuffer curBuffer = fillingBuffer;
129 if (!curBuffer.empty()) {
132 curBuffer.fill(input);
133 if (curBuffer.empty()) {
135 InputStream tmp =
null;
152 private float leftGain;
153 private float rightGain;
155 void setLeftGain(
final float leftGain) {
156 this.leftGain = leftGain;
159 float getLeftGain() {
163 void setRightGain(
final float rightGain) {
164 this.rightGain = rightGain;
167 float getRightGain() {
171 Vec3f getPosition() {
177 boolean hasNextSample() {
178 return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples());
183 final float res = activeBuffer.getSample(samplePosition++);
185 if (!hasNextSample()) {
195 synchronized void swapBuffers() {
196 final SoundBuffer tmp = activeBuffer;
197 activeBuffer = fillingBuffer;
199 fillingBuffer.empty(
true);
204 return (samplesRead == totalSamples) && !looping;
synchronized void setLooping(final boolean looping)
synchronized boolean isLooping()
synchronized boolean isPlaying()
void setPosition(final float x, final float y, final float z)