This commit is contained in:
BIN
java/WiiUseJ.dll
BIN
java/WiiUseJ.dll
Binary file not shown.
BIN
java/mimis.dll
BIN
java/mimis.dll
Binary file not shown.
Binary file not shown.
@@ -26,7 +26,7 @@ public class WiimoteDiscovery extends Worker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean execute(String parameters) {
|
public boolean execute(String parameters) {
|
||||||
String command = "native/wiiscan.exe -l none " + parameters;
|
String command = "wiiscan.exe -l none " + parameters;
|
||||||
try {
|
try {
|
||||||
process = Runtime.getRuntime().exec(command);
|
process = Runtime.getRuntime().exec(command);
|
||||||
Scanner scanner = new Scanner(process.getInputStream());
|
Scanner scanner = new Scanner(process.getInputStream());
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class WiimoteService extends WiiUseApiManager implements WiimoteListener
|
|||||||
protected Wiimote[] wiimoteArray;
|
protected Wiimote[] wiimoteArray;
|
||||||
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
|
protected HashMap<Integer, WiimoteDevice> wiimoteDeviceMap;
|
||||||
|
|
||||||
WiimoteService() {
|
public WiimoteService() {
|
||||||
wiimoteList = new ArrayList<Integer>();
|
wiimoteList = new ArrayList<Integer>();
|
||||||
wiimoteArray = new Wiimote[0];
|
wiimoteArray = new Wiimote[0];
|
||||||
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
|
wiimoteDeviceMap = new HashMap<Integer, WiimoteDevice>();
|
||||||
|
|||||||
29
java/src/mimis/util/BufferedSound.java
Normal file
29
java/src/mimis/util/BufferedSound.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ public class Native {
|
|||||||
public void start() {
|
public void start() {
|
||||||
int handle = getHandle("Winamp v1.x");
|
int handle = getHandle("Winamp v1.x");
|
||||||
System.out.println(handle);
|
System.out.println(handle);
|
||||||
sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
//sendMessage(handle, Windows.WM_CLOSE, 0, 0);
|
||||||
/*
|
/*
|
||||||
while (true) {//Winamp v1.x
|
while (true) {//Winamp v1.x
|
||||||
System.out.println(isRunning("winamp.exe"));
|
System.out.println(isRunning("winamp.exe"));
|
||||||
|
|||||||
99
java/src/mimis/util/Sound.java
Normal file
99
java/src/mimis/util/Sound.java
Normal file
@@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
25
java/src/mimis/util/Type.java
Normal file
25
java/src/mimis/util/Type.java
Normal file
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -347,4 +347,20 @@ public class WiiUseApi {
|
|||||||
* the object where we store all the new events.
|
* the object where we store all the new events.
|
||||||
*/
|
*/
|
||||||
native void specialPoll(EventsGatherer gath);
|
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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -660,4 +660,52 @@ public class WiiUseApiManager extends Thread {
|
|||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
shutdown();
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -501,4 +501,51 @@ public class Wiimote implements WiiUseApiListener {
|
|||||||
deactivateRumble();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
BIN
java/wiiuse.dll
BIN
java/wiiuse.dll
Binary file not shown.
Reference in New Issue
Block a user