javasound

How to remove LOOP_CONTINUOUSLY in Javasound? [code inside]

☆樱花仙子☆ 提交于 2019-12-11 23:09:51
问题 I have saw this code somewhere in this area. I want to play the .wav file once but not continuously. How can I do that? I try removing the LOOP_CONTINUOUSLY line but it does not work. URL url = new URL("http://pscode.org/media/leftright.wav"); Clip clip = AudioSystem.getClip(); // getAudioInputStream() also accepts a File or InputStream AudioInputStream ais = AudioSystem. getAudioInputStream( url ); clip.open(ais); clip.loop(Clip.LOOP_CONTINUOUSLY); SwingUtilities.invokeLater(new Runnable() {

To modify the pitch of an audio file at specific positions in the files using the codes in java below

点点圈 提交于 2019-12-11 20:30:10
问题 I want to modify the pitch of the audio clip dynamically based on the user input at different time instants, say if user enters change the pitch of the audio after 10 seconds then how can I achieve the same? I found this link that describes how to modify the pitch but i want to repeat this process at different time instants of the audio clip and for some short duration only. Can anybody guide me on this ? Some Edits Edit 1 I found this code as I mentioned this previously as well //source file

OutOfBoundsException in Processing (Sound library)

大城市里の小女人 提交于 2019-12-11 15:36:18
问题 I recently started playing with Processing. I want to create a simple FFT visualizer that will import music file using Sound library. Here's my code and the console output. Console Output import processing.sound.*; SoundFile file; void setup() { size(); background(51); file = new SoundFile(this, "song.mp3"); file.play(); } void draw () { } Can someone explain why is this happening and how it can be fixed? By the way, sound file (song.mp3) is located in the same folder as the .pde file. 回答1:

JavaSound: Extract one channel of stereo audio

时光毁灭记忆、已成空白 提交于 2019-12-11 12:06:57
问题 I have a stereo wave file that I need to read and play back only the selected channel. What is the best way to accomplish this? 回答1: When you bring the wav file in via an AudioInputStream, use the AudioFileFormat info to convert the bytes to PCM. The data for the right and left alternates. So, if the line is 16-bit, you will have 4 bytes per frame. The first two will be assembled into the left channel and the second two will be assembled into the right channel. (Or vice versa--I have trouble

Adding Music/Sound to Java Programs

喜欢而已 提交于 2019-12-11 08:38:08
问题 I'm making some mini java games and I was wondering how I can add sound/music to my programs. I watched a video on youtube and followed the code provided, however I get the following error: java.io.IOException: could not create audio stream from input stream I noticed that others have asked the same question with the same code but the answers were not helpful. Here is the code: import sun.audio.*; import javax.swing.*; import java.awt.event.*; import java.io.*; public class Project1 { public

Java Audio - How to play song during game (Application, not Applet)

允我心安 提交于 2019-12-11 06:38:42
问题 LAST EDIT - TWO SIMPLE ANSWERS NEEDED. 1) I was able to get the code working with a URL (it's the code from one of the responses below). But my song is in a wav file. When I try to do File url = new File("---");, it doesn't work. Instead, in the stack trace (thanks for that tip!), it says "Failed to allocate clip data: Requested buffer too large" The song I'm trying to play is techno, about 3 minutes long. How do I work around the clip data size issue? 回答1: Look at the classes of the Java

How to write a generated audio into a .wav format in java

僤鯓⒐⒋嵵緔 提交于 2019-12-11 05:48:37
问题 I am very new in Java Sound and therefore my concepts of it are not that strong. I want to understand that how to write the audio generated by the following code into a file of .wav format. I had read a few posts and some questions on stackoverflow as well, but I am not able to make out the solution out of them. So please help me understand it. Thanks. import javax.sound.sampled.*; import java.nio.ByteBuffer; import java.util.Scanner; public class Audio { //Alternating Tones public static

Play and Seek Audio File in java

可紊 提交于 2019-12-11 04:01:23
问题 I used this class to play my Wav file. Its very good but How to start my wav file on some position (KB or second)? auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); System.out.println("s"); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { return; } finally { auline.drain(); auline.close(); } This is part of the code. 回答1: A Clip

disable other sounds in java

泄露秘密 提交于 2019-12-11 03:57:28
问题 I wrote a program in Java using the pi4j lib to make sound whenever a (physical) button is clicked. This program works, but it now plays all the sounds interchangeably. I want that when you click on 2,3,4 or more buttons you only hear one sound. This is the code I hope you can help. public class ButtonSoundsProject{ public static void main(String args[]) throws InterruptedException { System.out.println("Toy has been started!"); // create gpio controller final GpioController gpio = GpioFactory

Audio playback in java not working correctly

拥有回忆 提交于 2019-12-11 02:36:16
问题 I attempted to mimic the code found here https://stackoverflow.com/tags/javasound/info but I cannot make it play either through loop() or start(). I've looked for answers but it seems like mine is just a fluke or a stupid mistake that everyone else is good enough to recognize. import javax.sound.sampled.*; import java.net.URL; public class AudioTest { public static void main(String[] args) throws Exception { URL url = new URL("http://www.public.asu.edu/~wnjones1/leftright.wav"); Clip clip =