summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/audio
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
committerSven Gothel <[email protected]>2014-07-03 16:21:36 +0200
commit556d92b63555a085b25e32b1cd55afce24edd07a (patch)
tree6be2b02c62a77d5aba81ffbe34c46960608be163 /src/jogl/classes/com/jogamp/audio
parenta90f4a51dffec3247278e3c683ed4462b1dd9ab5 (diff)
Code Clean-Up based on our Recommended Settings (jogamp-scripting c47bc86ae2ee268a1f38c5580d11f93d7f8d6e74)
- Change non static accesses to static members using declaring type - Change indirect accesses to static members to direct accesses (accesses through subtypes) - Add final modifier to private fields - Add final modifier to method parameters - Add final modifier to local variables - Remove unnecessary casts - Remove unnecessary '$NON-NLS$' tags - Remove trailing white spaces on all lines
Diffstat (limited to 'src/jogl/classes/com/jogamp/audio')
-rw-r--r--src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java6
-rw-r--r--src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java72
-rw-r--r--src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java24
-rw-r--r--src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java20
-rw-r--r--src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java58
5 files changed, 90 insertions, 90 deletions
diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java
index 83f5e4ebd..fef9d61dd 100644
--- a/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java
+++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Audio.java
@@ -36,7 +36,7 @@ import java.io.*;
public class Audio {
private static Audio instance = null;
- private Mixer mixer;
+ private final Mixer mixer;
public synchronized static Audio getInstance() {
if (instance == null) {
@@ -53,9 +53,9 @@ public class Audio {
return mixer;
}
- public Track newTrack(File file) throws IOException
+ public Track newTrack(final File file) throws IOException
{
- Track res = new Track(file);
+ final Track res = new Track(file);
mixer.add(res);
return res;
}
diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java
index b36fd2637..a84da723f 100644
--- a/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java
+++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Mixer.java
@@ -48,12 +48,12 @@ public class Mixer {
private volatile boolean shutdownDone;
// Windows Event object
- private long event;
+ private final long event;
private volatile ArrayList<Track> tracks = new ArrayList<Track>();
- private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0);
- private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0);
+ private final Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0);
+ private final Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0);
private float falloffFactor = 1.0f;
@@ -64,7 +64,7 @@ public class Mixer {
private Mixer() {
event = CreateEvent();
new FillerThread().start();
- MixerThread m = new MixerThread();
+ final MixerThread m = new MixerThread();
m.setPriority(Thread.MAX_PRIORITY - 1);
m.start();
}
@@ -73,14 +73,14 @@ public class Mixer {
return mixer;
}
- synchronized void add(Track track) {
- ArrayList<Track> newTracks = new ArrayList<Track>(tracks);
+ synchronized void add(final Track track) {
+ final ArrayList<Track> newTracks = new ArrayList<Track>(tracks);
newTracks.add(track);
tracks = newTracks;
}
- synchronized void remove(Track track) {
- ArrayList<Track> newTracks = new ArrayList<Track>(tracks);
+ synchronized void remove(final Track track) {
+ final ArrayList<Track> newTracks = new ArrayList<Track>(tracks);
newTracks.remove(track);
tracks = newTracks;
}
@@ -88,14 +88,14 @@ public class Mixer {
// NOTE: due to a bug on the APX device, we only have mono sounds,
// so we currently only pay attention to the position of the left
// speaker
- public void setLeftSpeakerPosition(float x, float y, float z) {
+ public void setLeftSpeakerPosition(final float x, final float y, final float z) {
leftSpeakerPosition.set(x, y, z);
}
// NOTE: due to a bug on the APX device, we only have mono sounds,
// so we currently only pay attention to the position of the left
// speaker
- public void setRightSpeakerPosition(float x, float y, float z) {
+ public void setRightSpeakerPosition(final float x, final float y, final float z) {
rightSpeakerPosition.set(x, y, z);
}
@@ -109,7 +109,7 @@ public class Mixer {
falloffFactor + r^2
</PRE>
*/
- public void setFalloffFactor(float factor) {
+ public void setFalloffFactor(final float factor) {
falloffFactor = factor;
}
@@ -119,7 +119,7 @@ public class Mixer {
SetEvent(event);
try {
shutdownLock.wait();
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
}
}
}
@@ -132,13 +132,13 @@ public class Mixer {
@Override
public void run() {
while (!shutdown) {
- List<Track> curTracks = tracks;
+ final List<Track> curTracks = tracks;
- for (Iterator<Track> iter = curTracks.iterator(); iter.hasNext(); ) {
- Track track = iter.next();
+ for (final Iterator<Track> iter = curTracks.iterator(); iter.hasNext(); ) {
+ final Track track = iter.next();
try {
track.fill();
- } catch (IOException e) {
+ } catch (final IOException e) {
e.printStackTrace();
remove(track);
}
@@ -147,7 +147,7 @@ public class Mixer {
try {
// Run ten times per second
Thread.sleep(100);
- } catch (InterruptedException e) {
+ } catch (final InterruptedException e) {
e.printStackTrace();
}
}
@@ -158,7 +158,7 @@ public class Mixer {
// Temporary mixing buffer
// Interleaved left and right channels
float[] mixingBuffer;
- private Vec3f temp = new Vec3f();
+ private final Vec3f temp = new Vec3f();
MixerThread() {
super("Mixer Thread");
@@ -171,7 +171,7 @@ public class Mixer {
public void run() {
while (!shutdown) {
// Get the next buffer
- long mixerBuffer = getNextMixerBuffer();
+ final long mixerBuffer = getNextMixerBuffer();
if (mixerBuffer != 0) {
ByteBuffer buf = getMixerBufferData(mixerBuffer);
@@ -203,27 +203,27 @@ public class Mixer {
// This assertion should be in place if we have stereo
if ((mixingBuffer.length % 2) != 0) {
- String msg = "FATAL ERROR: odd number of samples in the mixing buffer";
+ final String msg = "FATAL ERROR: odd number of samples in the mixing buffer";
System.out.println(msg);
throw new InternalError(msg);
}
// Run down all of the registered tracks mixing them in
- List<Track> curTracks = tracks;
+ final List<Track> curTracks = tracks;
- for (Iterator<Track> iter = curTracks.iterator(); iter.hasNext(); ) {
- Track track = iter.next();
+ for (final Iterator<Track> iter = curTracks.iterator(); iter.hasNext(); ) {
+ final Track track = iter.next();
// Consider only playing tracks
if (track.isPlaying()) {
// First recompute its gain
- Vec3f pos = track.getPosition();
- float leftGain = gain(pos, leftSpeakerPosition);
- float rightGain = gain(pos, rightSpeakerPosition);
+ final Vec3f pos = track.getPosition();
+ final float leftGain = gain(pos, leftSpeakerPosition);
+ final float rightGain = gain(pos, rightSpeakerPosition);
// Now mix it in
int i = 0;
while (i < mixingBuffer.length) {
if (track.hasNextSample()) {
- float sample = track.nextSample();
+ final float sample = track.nextSample();
mixingBuffer[i++] = sample * leftGain;
mixingBuffer[i++] = sample * rightGain;
} else {
@@ -240,7 +240,7 @@ public class Mixer {
// Now that we have our data, send it down to the card
int outPos = 0;
for (int i = 0; i < mixingBuffer.length; i++) {
- short val = (short) mixingBuffer[i];
+ final short val = (short) mixingBuffer[i];
buf.put(outPos++, (byte) val);
buf.put(outPos++, (byte) (val >> 8));
}
@@ -279,9 +279,9 @@ public class Mixer {
// falloffFactor
// -------------------
// falloffFactor + r^2
- private float gain(Vec3f pos, Vec3f speakerPos) {
+ private float gain(final Vec3f pos, final Vec3f speakerPos) {
temp.sub(pos, speakerPos);
- float dotp = temp.dot(temp);
+ final float dotp = temp.dot(temp);
return (falloffFactor / (falloffFactor + dotp));
}
}
@@ -321,8 +321,8 @@ public class Mixer {
private static Constructor directByteBufferConstructor;
private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer
- private static ByteBuffer newDirectByteBuffer(long address, long capacity) {
- Long key = new Long(address);
+ private static ByteBuffer newDirectByteBuffer(final long address, final long capacity) {
+ final Long key = new Long(address);
ByteBuffer buf = (ByteBuffer) createdBuffers.get(key);
if (buf == null) {
buf = newDirectByteBufferImpl(address, capacity);
@@ -332,17 +332,17 @@ public class Mixer {
}
return buf;
}
- private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) {
+ private static ByteBuffer newDirectByteBufferImpl(final long address, final long capacity) {
if (directByteBufferClass == null) {
try {
directByteBufferClass = Class.forName("java.nio.DirectByteBuffer");
- byte[] tmp = new byte[0];
+ final byte[] tmp = new byte[0];
directByteBufferConstructor =
directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE,
tmp.getClass(),
Integer.TYPE });
directByteBufferConstructor.setAccessible(true);
- } catch (Exception e) {
+ } catch (final Exception e) {
e.printStackTrace();
}
}
@@ -355,7 +355,7 @@ public class Mixer {
null,
new Integer((int) address)
});
- } catch (Exception e) {
+ } catch (final Exception e) {
e.printStackTrace();
}
}
diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java
index 01346553c..18698f5ea 100644
--- a/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java
+++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/SoundBuffer.java
@@ -35,16 +35,16 @@ package com.jogamp.audio.windows.waveout;
import java.io.*;
class SoundBuffer {
- private byte[] data;
- private boolean needsByteSwap;
+ private final byte[] data;
+ private final boolean needsByteSwap;
private int numBytes;
- private int bytesPerSample;
+ private final int bytesPerSample;
private int numSamples;
private boolean playing;
private boolean empty;
// Note: needsByteSwap argument makes assumptions about the format
- SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) {
+ SoundBuffer(final int size, final int bytesPerSample, final boolean needsByteSwap) {
this.bytesPerSample = bytesPerSample;
this.needsByteSwap = needsByteSwap;
data = new byte[size * bytesPerSample];
@@ -55,7 +55,7 @@ class SoundBuffer {
return playing;
}
- void playing(boolean playing) {
+ void playing(final boolean playing) {
this.playing = playing;
}
@@ -63,11 +63,11 @@ class SoundBuffer {
return empty;
}
- void empty(boolean empty) {
+ void empty(final boolean empty) {
this.empty = empty;
}
- void fill(InputStream input) throws IOException {
+ void fill(final InputStream input) throws IOException {
synchronized(this) {
if (playing) {
throw new IllegalStateException("Can not fill a buffer that is playing");
@@ -75,7 +75,7 @@ class SoundBuffer {
}
empty(true);
- int num = input.read(data);
+ final int num = input.read(data);
if (num > 0) {
numBytes = num;
numSamples = numBytes / bytesPerSample;
@@ -96,8 +96,8 @@ class SoundBuffer {
// This is called by the mixer and must be extremely fast
// FIXME: may want to reconsider use of floating point at this point
// FIXME: assumes all sounds are of the same format to avoid normalization
- float getSample(int sample) {
- int startByte = sample * bytesPerSample;
+ float getSample(final int sample) {
+ final int startByte = sample * bytesPerSample;
// FIXME: assumes no more than 4 bytes per sample
int res = 0;
if (needsByteSwap) {
@@ -106,7 +106,7 @@ class SoundBuffer {
res |= (data[i] & 0xff);
}
} else {
- int endByte = startByte + bytesPerSample - 1;
+ final int endByte = startByte + bytesPerSample - 1;
for (int i = startByte; i <= endByte; i++) {
res <<= 8;
res |= (data[i] & 0xff);
@@ -119,6 +119,6 @@ class SoundBuffer {
res = (byte) res;
}
- return (float) res;
+ return res;
}
}
diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java
index 98a787478..5e55786ac 100644
--- a/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java
+++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Track.java
@@ -56,7 +56,7 @@ public class Track {
// If we're playing the file, this is its input stream
private InputStream input;
// Keep around the file name
- private File file;
+ private final File file;
// Whether we're playing this sound
private boolean playing;
// Whether we're looping this sound
@@ -64,7 +64,7 @@ public class Track {
// The position of this sound; defaults to being at the origin
private volatile Vec3f position = new Vec3f();
- Track(File file) throws IOException {
+ Track(final File file) throws IOException {
if (!file.getName().endsWith(".rawsound")) {
throw new IOException("Unsupported file format (currently supports only raw sounds)");
}
@@ -96,7 +96,7 @@ public class Track {
openInput();
// Fill it immediately
fill();
- } catch (IOException e) {
+ } catch (final IOException e) {
e.printStackTrace();
return;
}
@@ -109,7 +109,7 @@ public class Track {
return playing;
}
- public synchronized void setLooping(boolean looping) {
+ public synchronized void setLooping(final boolean looping) {
this.looping = looping;
}
@@ -117,7 +117,7 @@ public class Track {
return looping;
}
- public void setPosition(float x, float y, float z) {
+ public void setPosition(final float x, final float y, final float z) {
position = new Vec3f(x, y, z);
}
@@ -125,7 +125,7 @@ public class Track {
if (input == null) {
return;
}
- SoundBuffer curBuffer = fillingBuffer;
+ final SoundBuffer curBuffer = fillingBuffer;
if (!curBuffer.empty()) {
return;
}
@@ -152,7 +152,7 @@ public class Track {
private float leftGain;
private float rightGain;
- void setLeftGain(float leftGain) {
+ void setLeftGain(final float leftGain) {
this.leftGain = leftGain;
}
@@ -160,7 +160,7 @@ public class Track {
return leftGain;
}
- void setRightGain(float rightGain) {
+ void setRightGain(final float rightGain) {
this.rightGain = rightGain;
}
@@ -180,7 +180,7 @@ public class Track {
// This is called by the mixer and must be extremely fast
float nextSample() {
- float res = activeBuffer.getSample(samplePosition++);
+ final float res = activeBuffer.getSample(samplePosition++);
++samplesRead;
if (!hasNextSample()) {
swapBuffers();
@@ -193,7 +193,7 @@ public class Track {
}
synchronized void swapBuffers() {
- SoundBuffer tmp = activeBuffer;
+ final SoundBuffer tmp = activeBuffer;
activeBuffer = fillingBuffer;
fillingBuffer = tmp;
fillingBuffer.empty(true);
diff --git a/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java
index 79fb80169..831b25c91 100644
--- a/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java
+++ b/src/jogl/classes/com/jogamp/audio/windows/waveout/Vec3f.java
@@ -48,11 +48,11 @@ class Vec3f {
public Vec3f() {}
- public Vec3f(Vec3f arg) {
+ public Vec3f(final Vec3f arg) {
set(arg);
}
- public Vec3f(float x, float y, float z) {
+ public Vec3f(final float x, final float y, final float z) {
set(x, y, z);
}
@@ -60,18 +60,18 @@ class Vec3f {
return new Vec3f(this);
}
- public void set(Vec3f arg) {
+ public void set(final Vec3f arg) {
set(arg.x, arg.y, arg.z);
}
- public void set(float x, float y, float z) {
+ public void set(final float x, final float y, final float z) {
this.x = x;
this.y = y;
this.z = z;
}
/** Sets the ith component, 0 <= i < 3 */
- public void set(int i, float val) {
+ public void set(final int i, final float val) {
switch (i) {
case 0: x = val; break;
case 1: y = val; break;
@@ -81,7 +81,7 @@ class Vec3f {
}
/** Gets the ith component, 0 <= i < 3 */
- public float get(int i) {
+ public float get(final int i) {
switch (i) {
case 0: return x;
case 1: return y;
@@ -94,11 +94,11 @@ class Vec3f {
public float y() { return y; }
public float z() { return z; }
- public void setX(float x) { this.x = x; }
- public void setY(float y) { this.y = y; }
- public void setZ(float z) { this.z = z; }
+ public void setX(final float x) { this.x = x; }
+ public void setY(final float y) { this.y = y; }
+ public void setZ(final float z) { this.z = z; }
- public float dot(Vec3f arg) {
+ public float dot(final Vec3f arg) {
return x * arg.x + y * arg.y + z * arg.z;
}
@@ -111,87 +111,87 @@ class Vec3f {
}
public void normalize() {
- float len = length();
+ final float len = length();
if (len == 0.0f) return;
scale(1.0f / len);
}
/** Returns this * val; creates new vector */
- public Vec3f times(float val) {
- Vec3f tmp = new Vec3f(this);
+ public Vec3f times(final float val) {
+ final Vec3f tmp = new Vec3f(this);
tmp.scale(val);
return tmp;
}
/** this = this * val */
- public void scale(float val) {
+ public void scale(final float val) {
x *= val;
y *= val;
z *= val;
}
/** Returns this + arg; creates new vector */
- public Vec3f plus(Vec3f arg) {
- Vec3f tmp = new Vec3f();
+ public Vec3f plus(final Vec3f arg) {
+ final Vec3f tmp = new Vec3f();
tmp.add(this, arg);
return tmp;
}
/** this = this + b */
- public void add(Vec3f b) {
+ public void add(final Vec3f b) {
add(this, b);
}
/** this = a + b */
- public void add(Vec3f a, Vec3f b) {
+ public void add(final Vec3f a, final Vec3f b) {
x = a.x + b.x;
y = a.y + b.y;
z = a.z + b.z;
}
/** Returns this + s * arg; creates new vector */
- public Vec3f addScaled(float s, Vec3f arg) {
- Vec3f tmp = new Vec3f();
+ public Vec3f addScaled(final float s, final Vec3f arg) {
+ final Vec3f tmp = new Vec3f();
tmp.addScaled(this, s, arg);
return tmp;
}
/** this = a + s * b */
- public void addScaled(Vec3f a, float s, Vec3f b) {
+ public void addScaled(final Vec3f a, final float s, final Vec3f b) {
x = a.x + s * b.x;
y = a.y + s * b.y;
z = a.z + s * b.z;
}
/** Returns this - arg; creates new vector */
- public Vec3f minus(Vec3f arg) {
- Vec3f tmp = new Vec3f();
+ public Vec3f minus(final Vec3f arg) {
+ final Vec3f tmp = new Vec3f();
tmp.sub(this, arg);
return tmp;
}
/** this = this - b */
- public void sub(Vec3f b) {
+ public void sub(final Vec3f b) {
sub(this, b);
}
/** this = a - b */
- public void sub(Vec3f a, Vec3f b) {
+ public void sub(final Vec3f a, final Vec3f b) {
x = a.x - b.x;
y = a.y - b.y;
z = a.z - b.z;
}
/** Returns this cross arg; creates new vector */
- public Vec3f cross(Vec3f arg) {
- Vec3f tmp = new Vec3f();
+ public Vec3f cross(final Vec3f arg) {
+ final Vec3f tmp = new Vec3f();
tmp.cross(this, arg);
return tmp;
}
/** this = a cross b. NOTE: "this" must be a different vector than
both a and b. */
- public void cross(Vec3f a, Vec3f b) {
+ public void cross(final Vec3f a, final Vec3f b) {
x = a.y * b.z - a.z * b.y;
y = a.z * b.x - a.x * b.z;
z = a.x * b.y - a.y * b.x;
@@ -200,7 +200,7 @@ class Vec3f {
/** Sets each component of this vector to the product of the
component with the corresponding component of the argument
vector. */
- public void componentMul(Vec3f arg) {
+ public void componentMul(final Vec3f arg) {
x *= arg.x;
y *= arg.y;
z *= arg.z;