diff --git a/java/WiiUseJ.dll b/java/WiiUseJ.dll deleted file mode 100644 index a34e1b5..0000000 Binary files a/java/WiiUseJ.dll and /dev/null differ diff --git a/java/mimis.dll b/java/mimis.dll index 969f488..790db42 100644 Binary files a/java/mimis.dll and b/java/mimis.dll differ diff --git a/java/msvcr100.dll b/java/msvcr100.dll deleted file mode 100644 index 1055773..0000000 Binary files a/java/msvcr100.dll and /dev/null differ diff --git a/java/src/mimis/device/wiimote/WiimoteDiscovery.java b/java/src/mimis/device/wiimote/WiimoteDiscovery.java index e6412ce..5bd8995 100644 --- a/java/src/mimis/device/wiimote/WiimoteDiscovery.java +++ b/java/src/mimis/device/wiimote/WiimoteDiscovery.java @@ -26,7 +26,7 @@ public class WiimoteDiscovery extends Worker { } public boolean execute(String parameters) { - String command = "native/wiiscan.exe -l none " + parameters; + String command = "wiiscan.exe -l none " + parameters; try { process = Runtime.getRuntime().exec(command); Scanner scanner = new Scanner(process.getInputStream()); diff --git a/java/src/mimis/device/wiimote/WiimoteService.java b/java/src/mimis/device/wiimote/WiimoteService.java index 9288b7e..43e7dc0 100644 --- a/java/src/mimis/device/wiimote/WiimoteService.java +++ b/java/src/mimis/device/wiimote/WiimoteService.java @@ -34,7 +34,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener protected Wiimote[] wiimoteArray; protected HashMap wiimoteDeviceMap; - WiimoteService() { + public WiimoteService() { wiimoteList = new ArrayList(); wiimoteArray = new Wiimote[0]; wiimoteDeviceMap = new HashMap(); diff --git a/java/src/mimis/util/BufferedSound.java b/java/src/mimis/util/BufferedSound.java new file mode 100644 index 0000000..3cbab1f --- /dev/null +++ b/java/src/mimis/util/BufferedSound.java @@ -0,0 +1,29 @@ +package mimis.util; + +public class BufferedSound { + private byte[][] soundData; + private int sampleRate; + private int sampleSize; + + public BufferedSound(byte[][] soundData, int sampleRate, int sampleSize) { + this.soundData = soundData; + this.sampleRate = sampleRate; + this.sampleSize = sampleSize; + } + + public byte[] getReport(int paramInt) { + return soundData[paramInt]; + } + + public int numReports() { + return soundData.length; + } + + public int getSampleRate() { + return sampleRate; + } + + public int getSampleSize() { + return sampleSize; + } +} diff --git a/java/src/mimis/util/Native.java b/java/src/mimis/util/Native.java index 6f1bbfd..ff50145 100644 --- a/java/src/mimis/util/Native.java +++ b/java/src/mimis/util/Native.java @@ -11,7 +11,7 @@ public class Native { public void start() { int handle = getHandle("Winamp v1.x"); System.out.println(handle); - sendMessage(handle, Windows.WM_CLOSE, 0, 0); + //sendMessage(handle, Windows.WM_CLOSE, 0, 0); /* while (true) {//Winamp v1.x System.out.println(isRunning("winamp.exe")); diff --git a/java/src/mimis/util/Sound.java b/java/src/mimis/util/Sound.java new file mode 100644 index 0000000..9e22935 --- /dev/null +++ b/java/src/mimis/util/Sound.java @@ -0,0 +1,99 @@ +package mimis.util; + +import java.io.File; +import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; + +import javax.sound.sampled.AudioFormat; +import javax.sound.sampled.AudioInputStream; +import javax.sound.sampled.AudioSystem; + +import wiiusej.Wiimote; +import mimis.device.wiimote.WiimoteDevice; +import mimis.device.wiimote.WiimoteService; + +public class Sound { + public static final byte PCM = 64; + public static final byte ADPCM = 0; + public static final byte BLOCK_SIZE = 20; + + public Object object = new Object(); + + public static void main(String[] args) { + new Sound().start(); + } + + public void start() { + WiimoteService wiimoteService = new WiimoteService(); + try { + WiimoteDevice wiimoteDevice = new WiimoteDevice(); + Wiimote wiimote = wiimoteService.getDevice(wiimoteDevice); + + File file = new File("sound2.wav"); + + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file); + BufferedSound bufferedSound = bufferSound(audioInputStream); + + wiimote.activateSpeaker(); + + wiimote.setSpeakerConfig(ADPCM, bufferedSound.getSampleRate(), 0.1); + + + AudioFormat audioFormat = audioInputStream.getFormat(); + double sampleSizeInBytes = audioFormat.getSampleSizeInBits() / 8D; + double samplesPerBlock = BLOCK_SIZE / sampleSizeInBytes; + int step = (int) Math.round(1000 * samplesPerBlock / audioFormat.getSampleRate()); + + playBufferedSound(wiimote, bufferedSound, step); + + object.wait(); + wiimoteService.exit(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void playBufferedSound(final Wiimote wiimote, final BufferedSound bufferedSound, int step) { + Timer timer = new Timer(); + TimerTask timerTask = new TimerTask() { + int i = 0; + public void run() { + wiimote.streamSpeakerData(bufferedSound.getReport(i)); + if (++i > bufferedSound.numReports()) { + cancel(); + } + } + }; + timer.scheduleAtFixedRate(timerTask, 0, step); + object.notifyAll(); + } + + public BufferedSound bufferSound(AudioInputStream audioInputStream) throws IOException { + AudioFormat audioFormat = audioInputStream.getFormat(); + int size = (int) (audioInputStream.getFrameLength() * audioFormat.getFrameSize()); + byte[][] sound = new byte[size / BLOCK_SIZE + 1][BLOCK_SIZE + 1]; + for (int i = 0; i < sound.length; ++i) { + byte[] block = new byte[BLOCK_SIZE]; + int j = 0; + do { + int read = audioInputStream.read(block, j, BLOCK_SIZE - j); + if (read == -1) { + break; + } + j += read; + } while (j < BLOCK_SIZE); + int length = BLOCK_SIZE; + for (j = 0; j < BLOCK_SIZE; ++j) { + if ((i * 20 + j) > size) { + length = j; + break; + } + sound[i][j + 1] = (byte) (Math.random() * 0xff) ;//block[j]; + } + sound[i][0] = (byte) (length << 3); // Todo: add later + } + audioInputStream.close(); + return new BufferedSound(sound, (int) audioFormat.getSampleRate(), audioFormat.getSampleSizeInBits()); + } +} diff --git a/java/src/mimis/util/Type.java b/java/src/mimis/util/Type.java new file mode 100644 index 0000000..c57ee99 --- /dev/null +++ b/java/src/mimis/util/Type.java @@ -0,0 +1,25 @@ +package mimis.util; + +public class Type { + public static final int BITS_PER_BYTE = 8; + + public static byte[] intToBytes(int paramInt) { + return intToBytes(paramInt, true); + } + + public static byte[] intToBytes(int paramInt, boolean paramBoolean) { + byte[] arrayOfByte = new byte[4]; + int i; + if (paramBoolean) { + for (i = 0; i < arrayOfByte.length; i++) { + arrayOfByte[(arrayOfByte.length - i - 1)] = (byte) (paramInt >> i + * BITS_PER_BYTE & 0xFF); + } + } else { + for (i = 0; i < arrayOfByte.length; i++) { + arrayOfByte[i] = (byte) (paramInt >> i * BITS_PER_BYTE & 0xFF); + } + } + return arrayOfByte; + } +} diff --git a/java/src/wiiusej/WiiUseApi.java b/java/src/wiiusej/WiiUseApi.java index 1dd5606..61f1e5c 100644 --- a/java/src/wiiusej/WiiUseApi.java +++ b/java/src/wiiusej/WiiUseApi.java @@ -347,4 +347,20 @@ public class WiiUseApi { * the object where we store all the new events. */ native void specialPoll(EventsGatherer gath); + + + /** + * Speaker + */ + native void enableSpeaker(int id); + native void disableSpeaker(int id); + native void muteSpeaker(int id); + native void unmuteSpeaker(int id); + native void activateSpeaker(int id); + native void deactivateSpeaker(int id); + native void setSpeakerFormat(int id, byte format); + native void setSpeakerRate(int id, int rate); + native void setSpeakerVolume(int id, double volume); + native void setSpeakerConfig(int id, byte format, int rate, double volume); + native void streamSpeakerData(int id, byte[] block); } diff --git a/java/src/wiiusej/WiiUseApiManager.java b/java/src/wiiusej/WiiUseApiManager.java index 40894ac..bbefe2e 100644 --- a/java/src/wiiusej/WiiUseApiManager.java +++ b/java/src/wiiusej/WiiUseApiManager.java @@ -660,4 +660,52 @@ public class WiiUseApiManager extends Thread { protected void finalize() throws Throwable { shutdown(); } + + /** + * Speaker + */ + public void enableSpeaker(int id) { + wiiuse.enableSpeaker(id); + } + + public void disableSpeaker(int id) { + wiiuse.disableSpeaker(id); + } + + public void muteSpeaker(int id) { + wiiuse.muteSpeaker(id); + } + + public void unmuteSpeaker(int id) { + wiiuse.unmuteSpeaker(id); + } + + public void activateSpeaker(int id) { + wiiuse.activateSpeaker(id); + } + + public void deactivateSpeaker(int id) { + wiiuse.deactivateSpeaker(id); + } + + public void setSpeakerFormat(int id, byte format) { + wiiuse.setSpeakerFormat(id, format); + } + + public void setSpeakerRate(int id, int rate) { + wiiuse.setSpeakerRate(id, rate); + } + + public void setSpeakerVolume(int id, double volume) { + wiiuse.setSpeakerVolume(id, volume); + } + + public void setSpeakerConfig(int id, byte format, int rate, double volume) { + wiiuse.setSpeakerConfig(id, format, rate, volume); + } + + public void streamSpeakerData(int id, byte[] block) { + wiiuse.streamSpeakerData(id, block); + + } } diff --git a/java/src/wiiusej/Wiimote.java b/java/src/wiiusej/Wiimote.java index 9709f00..6999d18 100644 --- a/java/src/wiiusej/Wiimote.java +++ b/java/src/wiiusej/Wiimote.java @@ -501,4 +501,51 @@ public class Wiimote implements WiiUseApiListener { deactivateRumble(); } } + + /** + * Speaker + */ + public void enableSpeaker() { + manager.enableSpeaker(id); + } + + public void disableSpeaker() { + manager.disableSpeaker(id); + } + + public void muteSpeaker() { + manager.muteSpeaker(id); + } + + public void unmuteSpeaker() { + manager.unmuteSpeaker(id); + } + + public void activateSpeaker() { + manager.activateSpeaker(id); + } + + public void deactivateSpeaker() { + manager.deactivateSpeaker(id); + } + + public void setSpeakerFormat(byte format) { + manager.setSpeakerFormat(format, format); + } + + public void setSpeakerRate(int rate) { + manager.setSpeakerRate(id, rate); + } + + public void setSpeakerVolume(double volume) { + manager.setSpeakerVolume(id, volume); + } + + public void setSpeakerConfig(byte format, int rate, double volume) { + manager.setSpeakerConfig(id, format, rate, volume); + } + + public void streamSpeakerData(byte[] block) { + manager.streamSpeakerData(id, block); + } } diff --git a/java/wiiuse.dll b/java/wiiuse.dll index 260aeb0..a9c5291 100644 Binary files a/java/wiiuse.dll and b/java/wiiuse.dll differ