javasound

Audio: Change Volume of samples in byte array

≡放荡痞女 提交于 2019-12-03 11:29:10
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(buffer, 0, buffer.length)) != -1) { baout.write(buffer, 0, c); } audioInputStream.close(); baout.close(

MIDI instrument listing?

↘锁芯ラ 提交于 2019-12-03 08:13:31
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? DYM like this? import javax.sound.midi.*; import javax.swing.*; class Instruments { public static void main(String[] args) throws MidiUnavailableException { Synthesizer synthesizer =

Java clip not working

牧云@^-^@ 提交于 2019-12-02 23:39:30
问题 Can someone please help me understand why this code below doesn't work? I start the clip by calling method start() . This method creates a new thread for the clip to run. However, no it doesn't seem to play anything. The code is compiled without any error... public class Audio { private Clip clip; private Thread thread; public Audio (String audioFile) { AudioInputStream audioStream = null; URL audioURL = this.getClass().getClassLoader().getResource(audioFile); // Obtain audio input stream

Returning a list of audio filetypes

别等时光非礼了梦想. 提交于 2019-12-02 22:36:00
问题 In answering this question: I want to make a java program in which there is a combobox which displays the titles of all the files available in a folder Another method of implementing the answer was brought to my attention; the usage of AudioSystem.getAudioFileTypes() to return all the supported audio files in the specified folder. I am a fairly inexperienced coder and am unable to integrate this method in my given answer File someFolder = new File("pathname"); Object[] wavFiles = someFolder

Java clip not working

 ̄綄美尐妖づ 提交于 2019-12-02 13:37:36
Can someone please help me understand why this code below doesn't work? I start the clip by calling method start() . This method creates a new thread for the clip to run. However, no it doesn't seem to play anything. The code is compiled without any error... public class Audio { private Clip clip; private Thread thread; public Audio (String audioFile) { AudioInputStream audioStream = null; URL audioURL = this.getClass().getClassLoader().getResource(audioFile); // Obtain audio input stream from the audio file and load the information // into main memory using the URL path retrieved from above.

Java Applet: Basic Drum Set

痴心易碎 提交于 2019-12-02 13:33:08
问题 I am trying to program an applet that has four buttons, all of which play a short audio file. The goal is to try and have the user successfully click the buttons any number of times, therefore creating a beat. Here is my attempt: import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; public class drumKit extends JApplet { private JButton snareButton; private JButton hiHatButton; private JButton bassButton; private JButton cymbalsButton; private AudioClip snare

SourceDataLine.drain() hangs on OSX

允我心安 提交于 2019-12-02 12:24:18
问题 My game plays back sound via the usual method: sdl.open(); sdl.start(); sdl.write(data, 0, data.length); sdl.drain(); sdl.stop(); sdl.close(); And the user may cancel the playback (asynchronously): sdl.stop(); This cancellation works nicely under Windows, but for one user running OSX 10.5.8 with Java 6 the program hangs. Threaddump shows the playback thread is inside drain(): com.sun.media.sound.MixerSourceLine.nDrain . If the user doesn't interrupt the sound, it completes nicely and the

Audio does not play in Jar but does in eclipse

时光总嘲笑我的痴心妄想 提交于 2019-12-02 10:17:18
Sound does not play when I run the JAR, but it does when I run it in eclipse. Here is where I load the clips: public void init(){ System.out.println("grabbing Music"); String currentDir = new File("").getAbsolutePath(); name=new File(currentDir+"\\music\\").list(); clip=new Clip[name.length]; soundFile=new File[name.length]; for(int x=0;x<name.length;x++){ System.out.println(currentDir+"\\music\\"+name[x]); try { soundFile[x]= new File(currentDir+"\\music\\"+name[x]); AudioInputStream sound = AudioSystem.getAudioInputStream(soundFile[x]); DataLine.Info info= new DataLine.Info(Clip.class, sound

How do I play two sounds at once?

喜夏-厌秋 提交于 2019-12-02 07:53:12
When I try to play two sounds at once in an applet, it won't work. I'm using AudioClip s. Is it even possible to play two sounds at once in an applet? Andrew Thompson Since Java 1.3+, use the Clip class of the Java Sound API. It is similar to the applet based AudioClip class, but better. E.G. adapted from the one shown on the Java Sound info. page . import java.net.URL; import javax.swing.*; import javax.sound.sampled.*; public class LoopSounds { public static void main(String[] args) throws Exception { URL url = new URL( "http://pscode.org/media/leftright.wav"); Clip clip = AudioSystem

Identifying silence at the end of an mp3 using java

可紊 提交于 2019-12-02 07:06:36
问题 Trying to detect silence at the end of audio in mp3 format, well all formats would be useful but mp3 format is the most important 回答1: The only way I know of to reliably detect silence at the end of a sound clip is to convert it to a PCM format and do one of the following calculations checking for a certain minimum cut-off amplitude. Decibels (dB) Root Mean Square (RMS) I've never managed to implement dB, but RMS is relatively simple, and should work for this use. I used it for the small bars