Commits

Anonymous committed 4f12cda

cleaned up imports.
added error logging to sound system.

  • Participants
  • Parent commits 7b9f580
  • Branches dev-1
  • Tags VER_VT9

Comments (0)

Files changed (8)

File trunk/Slick/src/org/newdawn/slick/openal/AudioImpl.java

 		int channels = AL10.alGetBufferi(buffer, AL10.AL_CHANNELS);
 		int freq = AL10.alGetBufferi(buffer, AL10.AL_FREQUENCY);
 		
+		if ((0 == bytes) || (0 == bits) || (0 == channels)  || (0 == freq)) {
+			throw new RuntimeException("AlBuffer not initialised: bytes=" + bytes + " bits=" + bits + " chnls=" + channels + " freq=" + freq);
+		}
 		int samples = bytes / (bits / 8);
 		length = (samples / (float) freq) / channels;
 	}

File trunk/Slick/src/org/newdawn/slick/openal/OggDecoder.java

 
 		OggInputStream oggInput = new OggInputStream(input);
 		
-		boolean done = false;
+//		boolean done = false;
 		while (!oggInput.atEnd()) {
 			dataout.write(oggInput.read());
 		}

File trunk/Slick/src/org/newdawn/slick/openal/SoundStore.java

 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.HashMap;
+import java.util.Map;
 
 import org.lwjgl.BufferUtils;
 import org.lwjgl.Sys;
 	/** The number of sound sources enabled - default 8 */
 	private int sourceCount;
 	/** The map of references to IDs of previously loaded sounds */
-	private HashMap loaded = new HashMap();
+	private Map<String, Integer> loaded = new HashMap<String, Integer>();
 	/** The ID of the buffer containing the music currently being played */
 	private int currentMusic = -1;
 	/** The OpenGL AL sound sources in use */
 	private IntBuffer sources;
 	/** The next source to be used for sound effects */
-	private int nextSource;
+//	private int nextSource;
 	/** True if the sound system has been initialise */
 	private boolean inited = false;
 	/** The MODSound to be updated */
 		int buffer = -1;
 		
 		if (loaded.get(ref) != null) {
-			buffer = ((Integer) loaded.get(ref)).intValue();
+			buffer = (loaded.get(ref)).intValue();
 		} else {
 			try {
 				IntBuffer buf = BufferUtils.createIntBuffer(1);
 		int buffer = -1;
 		
 		if (loaded.get(ref) != null) {
-			buffer = ((Integer) loaded.get(ref)).intValue();
+			buffer = (loaded.get(ref)).intValue();
 		} else {
 			try {
 				IntBuffer buf = BufferUtils.createIntBuffer(1);
 		int buffer = -1;
 		
 		if (loaded.get(ref) != null) {
-			buffer = ((Integer) loaded.get(ref)).intValue();
+			buffer = (loaded.get(ref)).intValue();
 		} else {
 			try {
 				IntBuffer buf = BufferUtils.createIntBuffer(1);
 				OggData ogg = decoder.getData(in);
 				
 				AL10.alGenBuffers(buf);
+				logAlErrorIfAny();
 				AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, ogg.data, ogg.rate);
-				
+//				logAlErrorIfAny();
+				int err = AL10.alGetError();
+				if (AL10.AL_NO_ERROR != err) {
+					logAlError(err);
+					AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO8 : AL10.AL_FORMAT_MONO8, ogg.data, ogg.rate);
+					logAlErrorIfAny();
+				}
 				loaded.put(ref,new Integer(buf.get(0)));
 				                     
 				buffer = buf.get(0);
 	public int getSourceCount() {
 		return sourceCount;
 	}
+	
+	protected void logAlErrorIfAny() {
+		int e = AL10.alGetError();
+		if (AL10.AL_NO_ERROR != e) {
+			logAlError(e);
+		}
+	}
+	
+	protected void logAlError(int e) {
+		log("AL error: " + Integer.toString(e, 16) + "h/" + e + "d: " + AL10.alGetString(e));
+	}
+	
+	protected void log(String s) {
+		System.out.println("SoundTest: " + s);
+	}
+	
 }

File trunk/Slick/src/org/newdawn/slick/state/StateBasedGame.java

 
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.newdawn.slick.Game;
 import org.newdawn.slick.GameContainer;
  */
 public abstract class StateBasedGame implements Game, InputListener, Pauseable {
 	/** The list of states making up this game */
-	private HashMap states = new HashMap();
+	private Map<Integer, GameState> states = new HashMap<Integer, GameState>();
 	/** The current state */
 	private GameState currentState;
 	/** The next state we're moving into */
 	 * @param state The state to be added
 	 */
 	public void addState(GameState state) {
-		states.put(new Integer(state.getID()), state);
+		states.put(state.getID(), state);
 		
 		if (currentState.getID() == -1) {
 			currentState = state;
 	 * @return The state requested or null if no state with the specified ID exists
 	 */
 	public GameState getState(int id) {
-		return (GameState) states.get(new Integer(id));
+		return states.get(id);
 	}
 
 	/**
 		this.container = container;
 		initStatesList(container);
 		
-		Iterator gameStates = states.values().iterator();
+		Iterator<GameState> gameStates = states.values().iterator();
 		
 		while (gameStates.hasNext()) {
-			GameState state = (GameState) gameStates.next();
+			GameState state = gameStates.next();
 		
 			state.init(container, this);
 		}

File trunk/Slick/src/org/newdawn/slick/tests/SoundTest.java

 	 * @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer)
 	 */
 	public void init(GameContainer container) throws SlickException {
-		SoundStore.get().setMaxSources(32);
+//		SoundStore.get().setMaxSources(32);
 		
 		myContainer = container;
 		//start music volume half way, for fun..

File trunk/Slick/src/org/newdawn/slick/tests/StateBasedPauseTest.java

 import org.newdawn.slick.tests.states.TestState1;
 import org.newdawn.slick.tests.states.TestState2;
 import org.newdawn.slick.tests.states.TestState3;
-import org.newdawn.slick.util.Log;
 
 /**
  * A test for pausing states

File trunk/Slick/src/org/newdawn/slick/tests/TestBox.java

 import org.newdawn.slick.Input;
 import org.newdawn.slick.SlickException;
 import org.newdawn.slick.opengl.SlickCallable;
-import org.newdawn.slick.opengl.TextureImpl;
 import org.newdawn.slick.util.Log;
 
 /**

File trunk/Slick/src/org/newdawn/slick/tests/TransparentColorTest.java

 package org.newdawn.slick.tests;
 
-import java.nio.IntBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.LWJGLException;
-import org.lwjgl.input.Cursor;
-import org.lwjgl.input.Mouse;
 import org.newdawn.slick.AppGameContainer;
 import org.newdawn.slick.BasicGame;
 import org.newdawn.slick.Color;
 import org.newdawn.slick.Graphics;
 import org.newdawn.slick.Image;
 import org.newdawn.slick.SlickException;
-import org.newdawn.slick.geom.Rectangle;
 
 /**
  * A test for transparent colour specification
 		try {
 			Color c =image.getColor(mx, my);
 			System.out.println(c.getRed()+" "+c.getBlue()+" "+c.getGreen());
-		} catch (Exception e) {}
+		} catch (Exception e) {
+		}
 	}
 
 	/**