changeset 38:736de7b28701

Non-working sound code ...
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Feb 2011 04:58:42 +0200
parents 3dc5ae9f1c80
children e682b623aea9
files Makefile game/Sound.java game/SoundElement.java
diffstat 3 files changed, 36 insertions(+), 127 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Fri Feb 18 04:58:30 2011 +0200
+++ b/Makefile	Fri Feb 18 04:58:42 2011 +0200
@@ -6,7 +6,8 @@
 CLASSES=game/Piece.class game/PieceType.class \
 	game/Engine.class game/Interpolate.class \
 	game/ResourceLoader.class game/Sound.class \
-	game/SoundElement.class
+	game/SoundElement.class \
+	game/SoundManager.class
 
 # Utils
 JAVAC=javac -g
--- a/game/Sound.java	Fri Feb 18 04:58:30 2011 +0200
+++ b/game/Sound.java	Fri Feb 18 04:58:42 2011 +0200
@@ -1,36 +1,17 @@
-/*
- * Ristipolku Game Engine
- * (C) Copyright 2011 Matti 'ccr' Hämäläinen <ccr@tnsp.org>
- */
-package game;
-
-
-public enum Sound
-{
-    // Music loops
-    MUSIC_GAME1	   ("gamemusic.wav",  true),
-
-    // Sound effects
-    PIECE_PLACED   ("placed.wav",     false);
-
-
-
-    private final String name;
-    private final boolean streaming;
-
-    Sound(String name, boolean streaming)
-    {
-        this.name = name;
-        this.streaming = streaming;
-    }
-
-    public String getName()
-    {
-        return this.name;
-    }
-    
-    public boolean isStreaming()
-    {
-        return streaming;
-    }
-}
+package game;
+
+public class Sound {
+
+    private byte[] samples;
+
+    public Sound(byte[] samples)
+    {
+        this.samples = samples;
+    }
+
+    public byte[] getSamples()
+    {
+        return samples;
+    }
+
+}
--- a/game/SoundElement.java	Fri Feb 18 04:58:30 2011 +0200
+++ b/game/SoundElement.java	Fri Feb 18 04:58:42 2011 +0200
@@ -4,106 +4,33 @@
  */
 package game;
 
-import java.util.*;
-import java.io.*;
-import game.*;
-import javax.sound.sampled.*;
-
-
-class SoundElement implements Runnable
-{
-    private final String name;
-
-    private AudioInputStream stream;
-    private AudioFormat format;
-    private SourceDataLine line;
-    private Thread playThread;
-    private int loopCount;
-    private boolean playing, streaming;
-    private int volume = 100;
 
-    byte[] buffer;
-    int length;
-    
-    
-    SoundElement(String filename, boolean streaming) throws IOException
-    {
-        this.name = filename;
-        this.streaming = streaming;
+public enum SoundElement
+{
+    // Music loops
+    MUSIC_GAME1	   ("gamemusic.wav",  true),
 
-/*
-        ResourceLoader res = new ResourceLoader(name);
-        if (res == null || res.getStream() == null)
-        {
-            throw new IOException("Could not load audio resource '"+name+"'.\n");
-        }
-
+    // SoundElement effects
+    PIECE_PLACED   ("placed.wav",     false);
 
-        try {
-            stream = AudioSystem.getAudioInputStream(res.getStream());
-            format = stream.getFormat();
-        }
-        catch (UnsupportedAudioFileException e) {
-            throw new IOException("Unsupported audio file format for '"+name+"'.\n");
-        }
-        catch (IOException e)
-        {
-            throw new IOException("Could not load audio resource '"+name+"'.\n");
-        }
 
 
-        if (streaming) {
-            System.out.print("Loading '"+name+"' as a clip\n");
-            try {
-                clip = AudioSystem.getClip();
-                clip.open(stream);
-            }
-            catch (LineUnavailableException e)
-            {
-                throw new IOException("Line unavailable for '"+name+"'.\n");
-            }
-            finally {
-                stream.close();
-            }
-        }
-        else
-        {
-            clip = null;
-            System.out.print("Loading '"+name+"' as stream\n");
-            
-            try {
-                SourceDataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
-                System.out.print("info: "+stream.getFrameLength() + ", " + format.getFrameSize() + "\n");
-                line = (SourceDataLine) AudioSystem.getLine(info);
-                line.open(format);
-            }
-            catch (LineUnavailableException e) {
-                throw new IOException("Line unavailable for '"+name+"'.\n");
-            }
-        }
-*/
+    private final String name;
+    private final boolean streaming;
+
+    SoundElement(String name, boolean streaming)
+    {
+        this.name = name;
+        this.streaming = streaming;
     }
 
-    public void play()
+    public String getName()
     {
-        System.out.print("Sound("+name+").play()\n");
-    }
-    
-    public void loop(int n)
-    {
-        System.out.print("Sound("+name+").loop("+n+")\n");
+        return this.name;
     }
     
-    public void stop()
-    {
-    }
-    
-    public boolean isPlaying()
+    public boolean isStreaming()
     {
-        return false;
-    }
-
-    public void run()
-    {
+        return streaming;
     }
 }