# HG changeset patch # User Matti Hamalainen # Date 1297997922 -7200 # Node ID 736de7b28701df5da599a2f8b22452a579ba5883 # Parent 3dc5ae9f1c8091f07600811ba5ad96bb7ce536e8 Non-working sound code ... diff -r 3dc5ae9f1c80 -r 736de7b28701 Makefile --- 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 diff -r 3dc5ae9f1c80 -r 736de7b28701 game/Sound.java --- 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 - */ -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; + } + +} diff -r 3dc5ae9f1c80 -r 736de7b28701 game/SoundElement.java --- 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; } }