-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
580 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<excludeFolder url="file://$MODULE_DIR$/.idea" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
</component> | ||
</module> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
Main-Class: tarehart.alter.AlterForm | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="tarehart.alter.AlterForm"> | ||
<grid id="27dc6" binding="rootPanel" layout-manager="GridLayoutManager" row-count="5" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="10" bottom="10" right="10"/> | ||
<constraints> | ||
<xy x="20" y="20" width="446" height="247"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="c0da9" class="javax.swing.JSlider" binding="slider1" default-binding="true"> | ||
<constraints> | ||
<grid row="1" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<paintTicks value="true"/> | ||
</properties> | ||
</component> | ||
<component id="683f1" class="javax.swing.JSpinner" binding="spinner1" default-binding="true"> | ||
<constraints> | ||
<grid row="3" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="50" height="-1"/> | ||
</grid> | ||
</constraints> | ||
<properties> | ||
<enabled value="true"/> | ||
</properties> | ||
</component> | ||
<component id="1b34a" class="javax.swing.JProgressBar" binding="progressBar1" default-binding="true"> | ||
<constraints> | ||
<grid row="2" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="148" height="30"/> | ||
</grid> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="dddcb" class="javax.swing.JButton" binding="button1" default-binding="true"> | ||
<constraints> | ||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="152" height="24"/> | ||
</grid> | ||
</constraints> | ||
<properties> | ||
<text value="Begin Key Select"/> | ||
</properties> | ||
</component> | ||
<component id="9436c" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="3" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Pressing?"/> | ||
</properties> | ||
</component> | ||
<grid id="14553" binding="statusLight" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="3" column="4" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"> | ||
<preferred-size width="30" height="-1"/> | ||
</grid> | ||
</constraints> | ||
<properties> | ||
<background color="-10788278"/> | ||
</properties> | ||
<border type="none"/> | ||
<children/> | ||
</grid> | ||
<component id="628a8" class="javax.swing.JComboBox" binding="comboBox1" default-binding="true"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="4" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="67c68" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Microphone"/> | ||
</properties> | ||
</component> | ||
<component id="cd5c2" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Loudness threshold"/> | ||
</properties> | ||
</component> | ||
<component id="9bf1f" class="javax.swing.JLabel"> | ||
<constraints> | ||
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Loudness"/> | ||
</properties> | ||
</component> | ||
<grid id="29754" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="5" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="4" column="0" row-span="1" col-span="5" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="c4795" class="javax.swing.JTextPane" binding="thisAppWillTakeTextPane" default-binding="true"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="6" anchor="0" fill="3" indent="0" use-parent-layout="false"> | ||
<preferred-size width="150" height="50"/> | ||
</grid> | ||
</constraints> | ||
<properties> | ||
<background color="-1"/> | ||
<editable value="false"/> | ||
<enabled value="true"/> | ||
<font swing-font="Label.font"/> | ||
<text value="This app will take care of push-to-talk for you. By default, it holds down the left Alt key (code 18) when you speak. If you want to use a different key, click "Begin Key Select" and press your key to fill in the new code. Tested with Battlefield 4 Beta."/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
package tarehart.alter; | ||
|
||
import javax.sound.sampled.LineUnavailableException; | ||
import javax.sound.sampled.Mixer; | ||
import javax.swing.*; | ||
import javax.swing.event.ChangeEvent; | ||
import javax.swing.event.ChangeListener; | ||
import java.awt.*; | ||
import java.awt.event.*; | ||
import java.net.URL; | ||
import java.util.List; | ||
|
||
|
||
public class AlterForm { | ||
|
||
public static final int MAX_VOLUME = 50; | ||
public static final int GRACE_PERIOD = 1000; // 1000 milliseconds = 1 second | ||
private TalkingJudge judge; | ||
private KeyPresser presser; | ||
private MicrophoneAnalyzer microphoneAnalyzer; | ||
|
||
public AlterForm() throws AWTException { | ||
|
||
microphoneAnalyzer = new MicrophoneAnalyzer(); | ||
setupMicrophones(); | ||
|
||
presser = new KeyPresser(); | ||
judge = new TalkingJudge(presser, GRACE_PERIOD); | ||
presser.setKey(KeyEvent.VK_ALT); | ||
spinner1.setValue(KeyEvent.VK_ALT); | ||
|
||
setupKeyBinder(); | ||
|
||
progressBar1.setMaximum(MAX_VOLUME); | ||
slider1.setMaximum(MAX_VOLUME); | ||
|
||
slider1.setValue(3); | ||
|
||
microphoneAnalyzer.addListener(new AmplitudeUpdateListener() { | ||
@Override | ||
public void amplitudeUpdated(float newAmplitude) { | ||
int level = (int) newAmplitude; | ||
progressBar1.setValue(level); | ||
if (level >= slider1.getValue()) { | ||
judge.gainSound(); | ||
statusLight.setBackground(Color.green); | ||
} else { | ||
judge.loseSound(); | ||
} | ||
|
||
if (!judge.hearsTalking()) { | ||
statusLight.setBackground(Color.darkGray); | ||
} | ||
} | ||
}); | ||
|
||
|
||
spinner1.addChangeListener(new ChangeListener() { | ||
@Override | ||
public void stateChanged(ChangeEvent e) { | ||
presser.setKey((Integer) spinner1.getValue()); | ||
} | ||
}); | ||
|
||
} | ||
|
||
private void setupKeyBinder() { | ||
button1.addActionListener(new ActionListener() { | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
KeyGrabber.grabNextKey(spinner1); | ||
} | ||
}); | ||
} | ||
|
||
private void setupMicrophones() { | ||
|
||
comboBox1.setRenderer(new ListCellRenderer() { | ||
@Override | ||
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { | ||
DefaultListCellRenderer renderer = new DefaultListCellRenderer(); | ||
Mixer.Info mixer = (Mixer.Info) value; | ||
return renderer.getListCellRendererComponent(list, mixer.getName(), index, isSelected, cellHasFocus); | ||
} | ||
}); | ||
|
||
List<Mixer.Info> mixers = AudioSystemHelper.ListAudioInputDevices(); | ||
for (Mixer.Info mixer: mixers) { | ||
comboBox1.addItem(mixer); | ||
} | ||
|
||
try { | ||
microphoneAnalyzer.setMixer((Mixer.Info) comboBox1.getItemAt(0)); | ||
} catch (LineUnavailableException e) { | ||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | ||
} | ||
|
||
comboBox1.addItemListener(new ItemListener() { | ||
@Override | ||
public void itemStateChanged(ItemEvent e) { | ||
if (e.getStateChange() == ItemEvent.SELECTED) { | ||
Mixer.Info mixer = (Mixer.Info) e.getItem(); | ||
try { | ||
microphoneAnalyzer.setMixer(mixer); | ||
} catch (LineUnavailableException e1) { | ||
e1.printStackTrace(); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
public static void main(String[] args) { | ||
|
||
try { | ||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); | ||
} catch (Exception e) { | ||
// Essen | ||
} | ||
JFrame frame = new JFrame("Alt'er"); | ||
URL url = ClassLoader.getSystemResource("tarehart/alter/resources/alter.png"); | ||
Image img = Toolkit.getDefaultToolkit().createImage(url); | ||
frame.setIconImage(img); | ||
|
||
try { | ||
AlterForm m = new AlterForm(); | ||
frame.setContentPane(m.rootPanel); | ||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | ||
frame.pack(); | ||
frame.setLocationRelativeTo(null); | ||
frame.setVisible(true); | ||
} catch (AWTException e) { | ||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. | ||
} | ||
|
||
|
||
} | ||
|
||
private JProgressBar progressBar1; | ||
private JSlider slider1; | ||
private JPanel rootPanel; | ||
private JButton button1; | ||
private JSpinner spinner1; | ||
private JPanel statusLight; | ||
private JComboBox comboBox1; | ||
private JTextPane thisAppWillTakeTextPane; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tarehart.alter; | ||
|
||
public interface AmplitudeUpdateListener { | ||
|
||
public void amplitudeUpdated(float newAmplitude); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package tarehart.alter; | ||
|
||
import javax.sound.sampled.AudioSystem; | ||
import javax.sound.sampled.Line; | ||
import javax.sound.sampled.Mixer; | ||
import javax.sound.sampled.TargetDataLine; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* Some code borrowed from this tutorial: | ||
* http://www.technogumbo.com/tutorials/Java-Microphone-Selection-And-Level-Monitoring/Java-Microphone-Selection-And-Level-Monitoring.php | ||
*/ | ||
public class AudioSystemHelper { | ||
|
||
public static final Line.Info targetDLInfo = new Line.Info(TargetDataLine.class); | ||
|
||
public static List<Mixer.Info> ListAudioInputDevices() { | ||
List<Mixer.Info> returnList = new ArrayList<Mixer.Info>(); | ||
Mixer.Info[] mixerInfo; | ||
|
||
mixerInfo = AudioSystem.getMixerInfo(); | ||
|
||
for(int i = 0; i < mixerInfo.length; i++) { | ||
Mixer currentMixer = AudioSystem.getMixer(mixerInfo[i]); | ||
|
||
if( currentMixer.isLineSupported(targetDLInfo) ) { | ||
returnList.add( mixerInfo[i] ); | ||
} | ||
} | ||
|
||
return returnList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package tarehart.alter; | ||
|
||
import javax.swing.*; | ||
import java.awt.event.KeyEvent; | ||
import java.awt.event.KeyListener; | ||
|
||
public class KeyGrabber { | ||
|
||
public static void grabNextKey(final JSpinner listenMe) { | ||
|
||
listenMe.grabFocus(); | ||
|
||
listenMe.addKeyListener(new KeyListener() { | ||
@Override | ||
public void keyTyped(KeyEvent e) { } | ||
|
||
@Override | ||
public void keyPressed(KeyEvent e) { | ||
int keyCode = e.getKeyCode(); | ||
listenMe.setValue(keyCode); | ||
listenMe.removeKeyListener(this); | ||
} | ||
|
||
@Override | ||
public void keyReleased(KeyEvent e) { } | ||
}); | ||
} | ||
|
||
} |
Oops, something went wrong.