javasound

How to keep track of audio playback position?

一曲冷凌霜 提交于 2019-12-04 21:51:28
I created a thread to play an mp3 file in Java by converting it to an array of bytes. I'm wondering if I can keep track of the current play position as the mp3 is being played. First, I set up my music stream like so: try { AudioInputStream in = AudioSystem.getAudioInputStream(file); musicInputStream = AudioSystem.getAudioInputStream(MUSIC_FORMAT, in); DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, MUSIC_FORMAT); musicDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo); musicDataLine.open(MUSIC_FORMAT); musicDataLine.start(); startMusicThread(); } catch

Audio: Change Volume of samples in byte array

纵饮孤独 提交于 2019-12-04 17:42:13
问题 I'm reading a wav-file to a byte array using this method (shown below). Now that I have it stored inside my byte array, I want to change the sounds volume. private byte[] getAudioFileData(final String filePath) { byte[] data = null; try { final ByteArrayOutputStream baout = new ByteArrayOutputStream(); final File file = new File(filePath); final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file); byte[] buffer = new byte[4096]; int c; while ((c = audioInputStream.read

How can I write the contents of a SourceDataLine to a file?

南楼画角 提交于 2019-12-04 15:22:45
问题 I am modifying an application that plays audio data to write the data to a file instead. As it is currently implemented, a byte array is filled dynamically, and the contents of this buffer are written to a SourceDataLine each time it is filled. I basically want to write that buffer out to a file in a specified format. I have read through this official tutorial and came across this code snipped for writing audio data to a file: File fileOut = new File(someNewPathName); AudioFileFormat.Type

Turning the computer volume up/down with Java?

青春壹個敷衍的年華 提交于 2019-12-04 12:02:58
I want to turn the master volume of the computer up and down (100%/0%), with just a command. I saw that I could use FloatControl , but I'm not sure how to use it. Have at look at using JavaSound to control the master volume . From the link: Mixer.Info [] mixers = AudioSystem.getMixerInfo(); System.out.println("There are " + mixers.length + " mixer info objects"); for (Mixer.Info mixerInfo : mixers) { System.out.println("Mixer name: " + mixerInfo.getName()); Mixer mixer = AudioSystem.getMixer(mixerInfo); Line.Info [] lineInfos = mixer.getTargetLineInfo(); // target, not source for (Line.Info

How to sample multi-channel sound input in Java

馋奶兔 提交于 2019-12-04 11:50:58
问题 I realised this might be relatively niche, but maybe that's why this is good to ask anyway. I'm looking at a hardware multiple input recording console (such as the Alesis IO 26) to take in an Adat lightpipe 8 channel input to do signal processing. As I have yet to acquire the device and need to work out whether this is feasible (budgetary concerns), I'd like to ask if anyone has any experience tapping all these 8 inputs for data in Java? I've seen tons of examples of recording sound using the

MIDI instrument listing?

ぃ、小莉子 提交于 2019-12-04 11:33:55
问题 I have recently implemented a MIDI Beatbox from the code in Head First Java and would really like to do more with Java's MIDI capabilities. I thought that I might start by adding more, non-percussive instruments to the existing code, but I cannot seem to find a straightforward listing of the available instruments and their int keys. Does such a listing exist anywhere for the Soundbank that ships with the JDK? 回答1: DYM like this? import javax.sound.midi.*; import javax.swing.*; class

Java Sound: devices found when run in IntelliJ, but not in SBT

吃可爱长大的小学妹 提交于 2019-12-04 04:27:39
问题 I'm trying to to use Java Sound API in a Scala SBT-managed project. Here is a toy app that plays a note. import javax.sound.midi._ object MyMain extends App { val infos = MidiSystem.getMidiDeviceInfo() println( "[DEBUG] midi devices found: " + infos.length ) val myMsg = new ShortMessage; // Start playing the note Middle C (60), // moderately loud (velocity = 93). myMsg.setMessage(ShortMessage.NOTE_ON, 0, 60, 93); val timeStamp = -1; val rcvr : Receiver = MidiSystem.getReceiver(); rcvr.send

Java detecting an audio file (mp3)

心不动则不痛 提交于 2019-12-03 20:46:17
I have this code that reads an mp3 file import java.io.File; import java.io.IOException; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; public class Sound { public static void main(String[] args) { File sampleFile = new File("test.mp3"); try { AudioSystem.getAudioFileFormat(sampleFile); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } The problem here is that it is returning file not supported exception,

How to get Note On/Off messages from a MIDI sequence?

好久不见. 提交于 2019-12-03 15:27:13
I am hoping to get notifications of note on/off events in a playing MIDI sequence to show the notes on a screen based (piano) keyboard. The code below adds a MetaEventListener and a ControllerEventListener when playing a MIDI file, but only shows a few messages at the start and end of the track. How can we listen for note on & note off MIDI events? import java.io.File; import javax.sound.midi.*; import javax.swing.JOptionPane; class PlayMidi { public static void main(String[] args) throws Exception { /* This MIDI file can be found at.. https://drive.google.com/open?id

How to capture sound from microphone with java sound API?

怎甘沉沦 提交于 2019-12-03 14:45:33
The tutorial http://download.oracle.com/javase/tutorial/sound/capturing.html does not cover how to select microphone. I am enumerating mixers with the following code System.out.println("Searching for microphones"); for(Mixer.Info mixerinfo : AudioSystem.getMixerInfo()) { mixer = AudioSystem.getMixer(mixerinfo); //System.out.println(mixerinfo.toString()); if( mixer.isLineSupported(Port.Info.MICROPHONE) ) { mixers.add(mixer); System.out.println(Integer.toString(mixers.size()) + ": " + mixerinfo.toString()); } } i.e. by presense of microphone input. But next, having a mixer, I can't get line to