Move files in anticipation of move to modular system

This commit is contained in:
2016-07-03 12:28:35 +01:00
parent 72e82b41fe
commit 3cca0d9ba0
331 changed files with 5552 additions and 5587 deletions

View File

@@ -0,0 +1,7 @@
dependencies {
compile 'com.github.boukefalos:jlibmimis:0.1'
compile 'com.github.boukefalos:jlibitunes:0.3'
compile 'com.github.boukefalos:jlibwiiuse:0.12'
compile 'com.github.boukefalos:jlibintellitype:1.3.9'
compile 'com.github.boukefalos:jlibxinput:1.0'
}

View File

@@ -0,0 +1,15 @@
package jna;
import com.sun.jna.Library;
import com.sun.jna.Native;
public class HelloTest {
public interface HelloLibrary extends Library {
public void helloFromC();
}
public static void main(String[] args) {
HelloLibrary ctest = (HelloLibrary) Native.loadLibrary("ctest", HelloLibrary.class);
ctest.helloFromC();
}
}

View File

@@ -0,0 +1,314 @@
/*
* JIntellitype ----------------- Copyright 2005-2006 Emil A. Lefkof III
*
* I always give it my best shot to make a program useful and solid, but remeber
* that there is absolutely no warranty for using this program as stated in the
* following terms:
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package jni;
import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EtchedBorder;
import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.IntellitypeListener;
import com.melloware.jintellitype.JIntellitype;
/**
* Swing based test application to test all the functions of the JIntellitype library.
* <p>
* Copyright (c) 2006 Melloware, Inc. <http://www.melloware.com>
* @author Emil A. Lefkof III <elefkof@ksmpartners.com>
* @version 1.0
*/
public class TestIntellitype extends JFrame implements HotkeyListener, IntellitypeListener {
private static TestIntellitype mainFrame;
private static final int WINDOWS_A = 88;
private static final int ALT_SHIFT_B = 89;
private static final int CTRL_SHIFT_C = 90;
private static final int PRINT_SCREEN = 91;
private static final int F11 = 92;
private static final int F12 = 93;
private static final int SEMICOLON = 94;
private static final int TICK = 95;
private final JButton btnRegisterHotKey = new JButton();
private final JButton btnUnregisterHotKey = new JButton();
private final JPanel bottomPanel = new JPanel();
private final JPanel mainPanel = new JPanel();
private final JPanel topPanel = new JPanel();
private final JScrollPane scrollPane = new JScrollPane();
private final JTextArea textArea = new JTextArea();
/**
* Creates new form.
*/
public TestIntellitype() {
initComponents();
}
/**
* Main method to launch this application.
* <p>
* @param args any command line arguments
*/
public static void main(String[] args) {
System.out.println(new File(".").getAbsolutePath());
// first check to see if an instance of this application is already
// running, use the name of the window title of this JFrame for checking
if (JIntellitype.checkInstanceAlreadyRunning("JIntellitype Test Application")) {
System.exit(1);
}
// next check to make sure JIntellitype DLL can be found and we are on
// a Windows operating System
if (!JIntellitype.isJIntellitypeSupported()) {
System.exit(1);
}
mainFrame = new TestIntellitype();
mainFrame.setTitle("JIntellitype Test Application");
center(mainFrame);
mainFrame.setVisible(true);
mainFrame.initJIntellitype();
}
/*
* (non-Javadoc)
* @see com.melloware.jintellitype.HotkeyListener#onHotKey(int)
*/
public void onHotKey(int aIdentifier) {
output("WM_HOTKEY message received " + Integer.toString(aIdentifier));
}
/*
* (non-Javadoc)
* @see com.melloware.jintellitype.IntellitypeListener#onIntellitype(int)
*/
public void onIntellitype(int aCommand) {
switch (aCommand) {
case JIntellitype.APPCOMMAND_BROWSER_BACKWARD:
output("BROWSER_BACKWARD message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_FAVOURITES:
output("BROWSER_FAVOURITES message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_FORWARD:
output("BROWSER_FORWARD message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_HOME:
output("BROWSER_HOME message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_REFRESH:
output("BROWSER_REFRESH message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_SEARCH:
output("BROWSER_SEARCH message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_BROWSER_STOP:
output("BROWSER_STOP message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_LAUNCH_APP1:
output("LAUNCH_APP1 message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_LAUNCH_APP2:
output("LAUNCH_APP2 message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_LAUNCH_MAIL:
output("LAUNCH_MAIL message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK:
output("MEDIA_NEXTTRACK message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE:
output("MEDIA_PLAY_PAUSE message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK:
output("MEDIA_PREVIOUSTRACK message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_MEDIA_STOP:
output("MEDIA_STOP message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_VOLUME_DOWN:
output("VOLUME_DOWN message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_VOLUME_UP:
output("VOLUME_UP message received " + Integer.toString(aCommand));
break;
case JIntellitype.APPCOMMAND_VOLUME_MUTE:
output("VOLUME_MUTE message received " + Integer.toString(aCommand));
break;
default:
output("Undefined INTELLITYPE message caught " + Integer.toString(aCommand));
break;
}
}
/**
* Centers window on desktop.
* <p>
* @param aFrame the Frame to center
*/
private static void center(JFrame aFrame) {
final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
final Point centerPoint = ge.getCenterPoint();
final Rectangle bounds = ge.getMaximumWindowBounds();
final int w = Math.min(aFrame.getWidth(), bounds.width);
final int h = Math.min(aFrame.getHeight(), bounds.height);
final int x = centerPoint.x - (w / 2);
final int y = centerPoint.y - (h / 2);
aFrame.setBounds(x, y, w, h);
if ((w == bounds.width) && (h == bounds.height)) {
aFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
}
aFrame.validate();
}
/**
* Method to register a hotkey using the RegisterHotKey Windows API call.
* <p>
* @param aEvent the ActionEvent fired.
*/
private void btnRegisterHotKey_actionPerformed(ActionEvent aEvent) {
// assign the WINDOWS+A key to the unique id 88 for identification
JIntellitype.getInstance().registerHotKey(WINDOWS_A, JIntellitype.MOD_WIN, 'A');
JIntellitype.getInstance().registerHotKey(ALT_SHIFT_B, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, 'B');
JIntellitype.getInstance().registerSwingHotKey(CTRL_SHIFT_C, Event.CTRL_MASK + Event.SHIFT_MASK, 'C');
// use a 0 for the modifier if you just want a single keystroke to be a
// hotkey
JIntellitype.getInstance().registerHotKey(PRINT_SCREEN, 0, 44);
JIntellitype.getInstance().registerHotKey(F11, "F11");
JIntellitype.getInstance().registerHotKey(F12, JIntellitype.MOD_ALT, 123);
JIntellitype.getInstance().registerHotKey(SEMICOLON, 0, 186);
JIntellitype.getInstance().registerHotKey(TICK, 0, 192);
// clear the text area
textArea.setText("");
output("RegisterHotKey WINDOWS+A was assigned uniqueID 88");
output("RegisterHotKey ALT+SHIFT+B was assigned uniqueID 89");
output("RegisterHotKey CTRL+SHIFT+C was assigned uniqueID 90");
output("RegisterHotKey PRINT_SCREEN was assigned uniqueID 91");
output("RegisterHotKey F9 was assigned uniqueID 92");
output("RegisterHotKey F12 was assigned uniqueID 93");
output("RegisterHotKey SEMICOLON was assigned uniqueID 94");
output("Press WINDOWS+A or ALT+SHIFT+B or CTRL+SHIFT+C in another application and you will see the debug output in the textarea.");
}
/**
* Method to unregister a hotkey using the UnregisterHotKey Windows API call.
* <p>
* @param aEvent the ActionEvent fired.
*/
private void btnUnregisterHotKey_actionPerformed(ActionEvent aEvent) {
JIntellitype.getInstance().unregisterHotKey(WINDOWS_A);
JIntellitype.getInstance().unregisterHotKey(ALT_SHIFT_B);
JIntellitype.getInstance().unregisterHotKey(CTRL_SHIFT_C);
JIntellitype.getInstance().unregisterHotKey(PRINT_SCREEN);
JIntellitype.getInstance().unregisterHotKey(F11);
JIntellitype.getInstance().unregisterHotKey(F12);
JIntellitype.getInstance().unregisterHotKey(SEMICOLON);
output("UnregisterHotKey WINDOWS+A");
output("UnregisterHotKey ALT+SHIFT+B");
output("UnregisterHotKey CTRL+SHIFT+C");
output("UnregisterHotKey PRINT_SCREEN");
output("UnregisterHotKey F9");
output("UnregisterHotKey F12");
output("UnregisterHotKey SEMICOLON");
output("Press WINDOWS+A or ALT+SHIFT+B in another application and you will NOT see the debug output in the textarea.");
}
/**
* This method is called from within the constructor to initialize the form.
*/
private void initComponents() {
mainPanel.setLayout(new BorderLayout());
topPanel.setBorder(new EtchedBorder(1));
bottomPanel.setLayout(new BorderLayout());
bottomPanel.setBorder(new EtchedBorder(1));
btnRegisterHotKey.setText("RegisterHotKey");
btnRegisterHotKey.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnRegisterHotKey_actionPerformed(e);
}
});
btnUnregisterHotKey.setText("UnregisterHotKey");
btnUnregisterHotKey.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
btnUnregisterHotKey_actionPerformed(e);
}
});
topPanel.add(btnRegisterHotKey);
topPanel.add(btnUnregisterHotKey);
scrollPane.getViewport().add(textArea);
bottomPanel.add(scrollPane, BorderLayout.CENTER);
mainPanel.add(topPanel, BorderLayout.NORTH);
mainPanel.add(bottomPanel, BorderLayout.CENTER);
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
// don't forget to clean up any resources before close
JIntellitype.getInstance().cleanUp();
System.exit(0);
}
});
this.getContentPane().add(mainPanel);
this.pack();
this.setSize(800, 600);
}
/**
* Initialize the JInitellitype library making sure the DLL is located.
*/
public void initJIntellitype() {
try {
// initialize JIntellitype with the frame so all windows commands can
// be attached to this window
JIntellitype.getInstance().addHotKeyListener(this);
JIntellitype.getInstance().addIntellitypeListener(this);
output("JIntellitype initialized");
} catch (RuntimeException ex) {
output("Either you are not on Windows, or there is a problem with the JIntellitype library!");
}
}
/**
* Send the output to the log and the text area.
* <p>
* @param text the text to output
*/
private void output(String text) {
textArea.append(text);
textArea.append("\n");
}
}

View File

@@ -0,0 +1,10 @@
package jni;
import mimis.util.Native;
import mimis.value.Registry;
public class TestNative {
public static void main(String[] args) {
System.out.println(Native.getValue(Registry.CURRENT_USER, "Software\\LIRC", "password"));
}
}

View File

@@ -0,0 +1,9 @@
package jni;
import wiiusej.WiiUseApiManager;
public class TestWiiuse {
public static void main(String[] args) {
WiiUseApiManager.getWiimotes(0, false);
}
}

View File

@@ -0,0 +1,9 @@
package jni;
import de.hardcode.jxinput.JXInputManager;
public class TestXinput {
public static void main(String[] args) {
System.out.println(JXInputManager.getNumberOfDevices());
}
}

View File

@@ -0,0 +1,11 @@
package jni;
import com.dt.iTunesController.iTunes;
public class TestiTunes {
public static void main(String[] args) {
iTunes iTunes = new iTunes();
iTunes.connect();
iTunes.playPause();
}
}

View File

@@ -0,0 +1,29 @@
package test;
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 i) {
return soundData[i];
}
public int numReports() {
return soundData.length;
}
public int getSampleRate() {
return sampleRate;
}
public int getSampleSize() {
return sampleSize;
}
}

View File

@@ -0,0 +1,27 @@
package test;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
public class CustomAppender extends AppenderSkeleton {
protected int bla = 9999;
public void setBla(int bla) {
this.bla = bla;
}
public int getBla() {
return bla;
}
public boolean requiresLayout() {
return true;
}
public void close() {}
protected void append(LoggingEvent loggingEvent) {
System.out.print(layout.format(loggingEvent));
}
}

View File

@@ -0,0 +1,180 @@
package test;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import javax.swing.JFrame;
import javax.swing.JPanel;
import mimis.device.lirc.LircButton;
import mimis.device.lirc.LircButtonListener;
import mimis.device.lirc.LircService;
import mimis.device.lirc.remote.PhiliphsRCLE011Button;
import mimis.device.wiimote.WiimoteDevice;
import mimis.device.wiimote.WiimoteService;
import mimis.exception.device.DeviceNotFoundException;
import wiiusej.Wiimote;
import wiiusej.wiiusejevents.physicalevents.IREvent;
public class Ir extends WiimoteDevice implements LircButtonListener {
protected Graph graph;
protected Point tl, tr, br, bl, raw, point;
protected Line t, r, b, l;
public Ir() {
tl = tr = br = bl = new Point(0, 0);
graph = new Graph();
/*try {
while (true) {
graph.draw(new Point(Math.random(), Math.random()));
Thread.sleep(100);
}
} catch (InterruptedException e) {
e.printStackTrace();
}*/
LircService lircService = new LircService();
lircService.put(PhiliphsRCLE011Button.NAME,
PhiliphsRCLE011Button.values());
lircService.add(this);
lircService.start();
WiimoteService wiimoteService = new WiimoteService();
try {
Wiimote wiimote = wiimoteService.getDevice(this);
wiimote.activateIRTRacking();
Thread.sleep(10000000);
} catch (DeviceNotFoundException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void add(LircButton lircButton) {
if (lircButton instanceof PhiliphsRCLE011Button) {
boolean t = false, r = false, b = false, l = false;
switch ((PhiliphsRCLE011Button) lircButton) {
case RED:
tl = raw;
l = bl != null;
t = tr != null;
break;
case GREEN:
tr = raw;
t = tl != null;
r = br != null;
break;
case YELLOW:
br = raw;
r = tr != null;
b = bl != null;
break;
case BLUE:
bl = raw;
b = br != null;
l = tl != null;
break;
}
if (t) {
this.t = new Line(tl, tr);
}
if (r) {
this.r = new Line(tr, br);
}
if (b) {
this.b = new Line(br, bl);
}
if (l) {
this.l = new Line(bl, tl);
}
}
}
public void onIrEvent(IREvent event) {
// log.debug(event);
raw = new Point(event.getAx(), event.getAy());
logger.debug(String.format("%d %d", raw.x, raw.y));
if (t != null && r != null && b != null && l != null) {
double w = r.getX(raw.y) - l.getX(raw.y);
double h = t.getY(raw.x) - b.getY(raw.x);
point = new Point((w - l.getX(raw.y)) / w, (h - b.getY(raw.x)) / h);
graph.draw(point);
}
}
public static void main(String[] args) {
new Ir();
}
protected class Point {
public double x, y;
public Point(double x, double y) {
this.x = x;
this.y = y;
}
}
protected class Line {
protected double a, b;
public Line(Point p1, Point p2) {
a = (p2.y - p1.y) / (p2.x - p1.x);
b = p2.y - a * p2.x;
}
public double getY(double x) {
return a * x + b;
}
public double getX(double y) {
return (y - b) / a;
}
}
public class Graph extends JPanel {
protected static final long serialVersionUID = 1L;
final int PAD = 20;
final double X = 1;
final double Y = 2;
JFrame f;
Graphics2D g2;
double w, h;
public Graph() {
f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(this);
f.setSize(400, 400);
f.setLocation(200, 200);
f.setVisible(true);
g2 = (Graphics2D) f.getGraphics();
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
w = getWidth();
h = getHeight();
axes();
}
protected void draw(Point point) {
g2.clearRect(0, 0, 400, 400);
axes();
double xInc = (double) (w - 2 * PAD) / X;
double scale = (double) (h - 2 * PAD) / Y;
// Mark data points.
g2.setPaint(Color.blue);
double x = PAD + point.x * xInc;
double y = h - PAD - scale * point.y;
g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4));
}
protected void axes() {
// Draw ordinate.
g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD));
// Draw abcissa.
g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD));
}
}
}

View File

@@ -0,0 +1,214 @@
package test;
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 javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.UnsupportedAudioFileException;
import wiiusej.Wiimote;
import mimis.device.wiimote.WiimoteDevice;
import mimis.device.wiimote.WiimoteService;
//Sample Rate - equation is y = -280x + 7280, where x is the actual sample rate. ex: sample rate of 4200 = 0x0B
//Freq (y=real, x=wii) y=-1070*ln(x)+4442.6 of 2788.1*e^(-0.041*x)
public class Sound {
public static final byte PCM = 0x40; // signed 8-bit PCM
public static final byte ADPCM = 0x00; // Yamaha 4-bit ADPCM
public static final byte BLOCK_SIZE = 20;
public static final int yamaha_indexscale[] = {
230, 230, 230, 230, 307, 409, 512, 614,
230, 230, 230, 230, 307, 409, 512, 614};
public static final int yamaha_difflookup[] = {
1, 3, 5, 7, 9, 11, 13, 15,
-1, -3, -5, -7, -9, -11, -13, 15};
public Object object = new Object();
public static void main(String[] args) {
/*File file = new File("sound.wav");
try {
AudioInputStream inputStream = AudioSystem.getAudioInputStream(file);
AudioFormat au = inputStream.getFormat();
System.out.println(au.getSampleRate());// Hz
System.out.println(au.getSampleSizeInBits());// bits
} catch (Exception e) {
e.printStackTrace();
}*/
new Sound().start();
}
public void start() {
File file = new File("1kSine16 (3130).wav");
play(file);
System.exit(0);//if (true) return;
WiimoteService wiimoteService = new WiimoteService();
try {
WiimoteDevice wiimoteDevice = new WiimoteDevice();
Wiimote wiimote = wiimoteService.getDevice(wiimoteDevice);
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat audioFormat = audioInputStream.getFormat();
// BufferedSound bufferedSound = bufferSound(inputStream);
System.out.println(audioInputStream.getFormat().getSampleRate());
System.out.println(audioInputStream.getFormat().getFrameRate());
//System.out.println(bufferedSound.getSampleRate());
//byte rate = (byte) (48000 / bufferedSound.getSampleRate());
//wiimote.setSpeakerRate((byte) rate, (byte) 0x00);
wiimote.setSpeakerFormat(PCM);
//wiimote.setSpeakerRate((byte) 0, rate);
wiimote.setSpeakerRate((byte) 0x00, (byte) (48000 / audioFormat.getSampleRate())); // pcm
//wiimote.setSpeakerRate((byte) 0xd0, (byte) 0x07); // adpcm
wiimote.setSpeakerVolume(1);
wiimote.activateSpeaker();
/* File file = new File("volbeat_pcm_u8_32_1500.raw");
FileInputStream fin = new FileInputStream(file);
byte[] block = new byte[20];
while (fin.read(block) != -1) {
wiimote.streamSpeakerData(block);
}*/
//playBufferedSound(wiimote, bufferedSound, step);
playSound(wiimote, audioInputStream);
synchronized (object) {
object.wait();
}
wiimoteService.exit();
} catch (Exception e) {
e.printStackTrace();
}
}
public void playSound(final Wiimote wiimote, final AudioInputStream audioInputStream) {
Timer timer = new Timer();
TimerTask timerTask = new TimerTask() {
public void run() {
try {
byte[] buffer = new byte[20];
if (audioInputStream.read(buffer) != -1) {
buffer[0] = -2;
System.out.format("%2x\n", buffer[0]);
wiimote.streamSpeakerData(buffer);
} else {
cancel();
synchronized (object) {
object.notifyAll();
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
};
AudioFormat audioFormat = audioInputStream.getFormat();
double sampleSizeInBytes = audioFormat.getSampleSizeInBits() / 8D;
double samplesPerBlock = BLOCK_SIZE / sampleSizeInBytes;
int step = (int) Math.round(1000 * samplesPerBlock / (float) audioFormat.getSampleRate());
System.out.println("step: " + step);
timer.scheduleAtFixedRate(timerTask, 0, step);
}
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 % 10 == 0) {
wiimote.setSpeakerVolume(Math.random());
wiimote.setSpeakerConfig();
}*/
if (++i > bufferedSound.numReports()) {
cancel();
object.notifyAll();
}
}
};
timer.scheduleAtFixedRate(timerTask, 0, step);
}
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];
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);
for (j = 0; j < BLOCK_SIZE; ++j) {
if ((i * BLOCK_SIZE + j) > size) {
break;
}
//sound[i][j] = block[j];
sound[i][j] = (byte) ((j % 2 == 0) ? 0x33 : 0xcc);
//sound[i][j] = (byte) (Math.random() * 0xff);
}
}
audioInputStream.close();
return new BufferedSound(sound, (int) audioFormat.getSampleRate(), audioFormat.getSampleSizeInBits());
}
public void play(File file) {
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file);
AudioFormat audioFormat = audioInputStream.getFormat();
System.out.println(audioFormat.getEncoding());
System.out.println(audioFormat.getSampleRate());
System.out.println(audioFormat.getFrameRate());
AudioFormat newFormat = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
3130, 8, 1, 1, 3130, false);
AudioInputStream newAudioInputStream = new AudioInputStream(
audioInputStream,
newFormat,
audioInputStream.getFrameLength() * audioFormat.getFrameSize());
play(newAudioInputStream);
} catch (UnsupportedAudioFileException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void play(AudioInputStream audioInputStream) {
try {
AudioFormat audioFormat = audioInputStream.getFormat();
DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
SourceDataLine sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo);
sourceDataLine.open(audioFormat);
sourceDataLine.start();
int i;
byte[] buffer = new byte[128];
while ((i = audioInputStream.read(buffer, 0, buffer.length)) != -1) {
sourceDataLine.write(buffer, 0, i);
}
sourceDataLine.drain();
sourceDataLine.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
}