javasound

java midi latency

蹲街弑〆低调 提交于 2019-12-01 02:48:15
问题 I´m trying to make a java application that is able to play notes on the computer after detecting a midi device. Once I get the desired midi device I´m seting the receiver to which the device´s transmitter will deliver MIDI messages. device.getTransmitter().setReceiver( new MyReceiver()) ; class MyReceiver looks like: public class MyReceiver implements Receiver { MidiChannel[] channels ; public MyReceiver (){ try { Synthesizer synthesizer = MidiSystem.getSynthesizer(); synthesizer.open();

Java Sound refresh Lines list after attaching a microphone

拥有回忆 提交于 2019-12-01 02:45:03
问题 I have a simple capture/playback Swing app that has to detect if there is no appropriate microphone attached to the computer and warn the user. After a lot of fiddling around I have found the only solution that allowed me to detect the newly attached or removed microphone: com.sun.media.sound.JDK13Services.setCachingPeriod(0); private static boolean isMicrophoneAvailable() { try { if (!AudioSystem.isLineSupported(Port.Info.MICROPHONE)) { log.debug("NO MICROPHONE FOUND"); return false; } else

How do I know if I'm on the event dispatch thread?

一世执手 提交于 2019-11-30 23:11:22
问题 1.Consider my code is on some line of a JPanel that I have, am I automatically on EDT? 2.Same question for all other classes which are not belong to GUI, JPanels or other view classes, simple logical class. 3.If I have JPanel which I'm playing music while being in it, should the music run on event dispatch thread or on other thread which is not EDT (for not blocking the GUI, although I didn't feel any problem with running it from EDT)? Note: I want a general rule how to know it without using

Obtain wave pattern of a audio file in Java

北城余情 提交于 2019-11-30 20:53:38
I'm wondering how I may obtain musical information such as amplitude from a audio file? Suppose we have a raw audio file, what I want to extract data from the file which allows me to generate a curve such as http://www1.icsi.berkeley.edu/Speech/mr/nearfar.html . Once I have obtained this curve, I will perform FFT, etc. I have been trying to search for solutions in Java Sound, but what I only know so far is that I can pour the data into byte[] using AudioInputStream . But how do I translate that byte[] into a double[] which contains actual information about the sound? In this case, the values

Noise in background when generating sine wave in Java

有些话、适合烂在心里 提交于 2019-11-30 15:27:45
I'm getting a slight distortion (sounds like buzzing) in the background when I run the following code. Because of its subtle nature it makes believe there is some sort of aliasing going on with the byte casting. AudioFormat = PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, big-endian Note : code assumes (for now) that the data is in big endian. public static void playFreq(AudioFormat audioFormat, double frequency, SourceDataLine sourceDataLine) { System.out.println(audioFormat); double sampleRate = audioFormat.getSampleRate(); int sampleSizeInBytes = audioFormat.getSampleSizeInBits() / 8

MIDI beginner - need to play one note

我怕爱的太早我们不能终老 提交于 2019-11-30 12:52:51
I don't know very much about Java's MIDI function. In fact, it utterly bewilders me. what I'd like to do however is just build a simple application that will play one note. How to play a single MIDI note using Java Sound? The support for this out on the web is almost nonexistent, and I am totally at a loss. user2955146 I know this is a really old question, but, as a novice programmer, I had a very difficult time figuring out how to do this, so I thought I would share the following hello-world-style program that gets Java to play a single midi note in order to help anyone else getting started.

Playing multiple byte arrays simultaneously in Java

谁说我不能喝 提交于 2019-11-30 10:31:30
How can you play multiple (audio) byte arrays simultaneously? This "byte array" is recorded by TargetDataLine, transferred using a server. What I've tried so far Using SourceDataLine: There is no way to play mulitple streams using SourceDataLine, because the write method blocks until the buffer is written. This problem cannot be fixed using Threads, because only one SourceDataLine can write concurrently. Using the AudioPlayer Class: ByteInputStream stream2 = new ByteInputStream(data, 0, data.length); AudioInputStream stream = new AudioInputStream(stream2, VoiceChat.format, data.length);

How can i remove background noise with java, while recording audio in a crowd zone?

拥有回忆 提交于 2019-11-30 07:24:13
When i capture with JavaSound or Third party sound capture tools and record it to a file. Afterwards read the file back to modify it, is there any way to remove the "background noise" with my java application. Such as road traffic/air noises while main person was talking? Thanks Removing background noise is very difficult. If it is uniform noise, such as the "white" noise on an airplane, there are algorithms to remove those frequency components. But if the noise is non-uniform and similar in nature as your good recording, e.g. people talking in the background, street noise, etc. it will be

Obtain wave pattern of a audio file in Java

 ̄綄美尐妖づ 提交于 2019-11-30 04:52:38
问题 I'm wondering how I may obtain musical information such as amplitude from a audio file? Suppose we have a raw audio file, what I want to extract data from the file which allows me to generate a curve such as http://www1.icsi.berkeley.edu/Speech/mr/nearfar.html. Once I have obtained this curve, I will perform FFT, etc. I have been trying to search for solutions in Java Sound, but what I only know so far is that I can pour the data into byte[] using AudioInputStream . But how do I translate

sound not playing in jar

别来无恙 提交于 2019-11-29 18:04:51
I have packed all the class files and resources as a jar but on execution the sound files wont play. My package structure is: +project |_classes |_ _*.class |_resources |_ _ *.jpg,*.wav Code: AudioInputStream inputStream = AudioSystem.getAudioInputStream(kidsClassRoom.class.getResourceAsStream("../resources/"+file)); getting a null when this line is executed!! An alternate theory to those already presented. Often successful getResource() calls depend on the class loader instance that is called to locate them. For this reason, I would recommend to use an instance of a user defined object, from