// This is f*****g stupid as hell; if this method makes it into a release, somebody shoot me in // the head. public void delayTap1(int channel, int volume) { try { InputStream file_input_stream = p.createInput(modpath); delayplayerA = new Player(interpolation); delayplayerA.set_module(Player.load_module(file_input_stream)); file_input_stream.close(); delayplayerA.set_loop(true); delayplayerA.receivebuffer(buffersize); for (int i = 0; i < delayplayerA.get_num_channels(); i++) { if (i != channel) { delayplayerA.ibxm.chanmute[i] = true; } } delayplayerA.ibxm.channels[channel].chanvol_override = volume; delayplayerA.play(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void beginExecution() { AudioFormat audioFormat = new AudioFormat( AudioFormat.Encoding.PCM_SIGNED, 44100.0F, 16, 1, numChannels, 44100.0F, false); // System.out.println("AudioPlayer.playAudioInts audio format: " + audioFormat ); DataLine.Info dataLineInfo = new DataLine.Info(SourceDataLine.class, audioFormat); if (!AudioSystem.isLineSupported(dataLineInfo)) { System.out.println("AudioPlayer.playAudioInts does not " + " handle this type of audio."); return; } try { SourceDataLine sourceLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo); sourceLine.open(audioFormat); } catch (LineUnavailableException e) { e.printStackTrace(); } chunkIndex = 0; InitialExecution = true; }
private void checkArgumentsAndRun(String... arguments) { if (arguments.length == 0) { printError(); } else { try { run(arguments); } catch (UnsupportedAudioFileException e) { printError(); SharedCommandLineUtilities.printLine(); System.err.println("Error:"); System.err.println("\tThe audio file is not supported!"); } catch (IOException e) { printError(); SharedCommandLineUtilities.printLine(); System.err.println("Current error:"); System.err.println("\tIO error, maybe the audio file is not found or not supported!"); } catch (IllegalArgumentException e) { printError(); SharedCommandLineUtilities.printLine(); System.err.println("Current error:"); System.err.println("\tThe algorithm provided is unknown!"); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
public void play(InputStream source) { int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10); byte[] buffer = new byte[bufferSize]; SourceDataLine line; try { DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, bufferSize); } catch (LineUnavailableException e) { e.printStackTrace(); return; } line.start(); try { int numBytesRead = 0; while (numBytesRead != -1) { numBytesRead = source.read(buffer, 0, buffer.length); if (numBytesRead != -1) line.write(buffer, 0, numBytesRead); } } catch (IOException e) { e.printStackTrace(); } line.drain(); line.close(); }
private static void rand(int t, int range) { long t0 = System.currentTimeMillis(); Random r = new Random(); double hz; double n; int d; int i; while (System.currentTimeMillis() <= t0 + t) { n = r.nextInt(range * 12 + 1) / 2.0; d = 250 * (r.nextInt(8 - 1) + 1); if (r.nextDouble() <= 0.1) { i = 0; } else { i = 1; } hz = 440 * Math.pow(2, n / 6.0); try { Tone.sound(hz, d, i); } catch (LineUnavailableException e) { e.printStackTrace(); } } }
public void run() { InputStream ins = GameScreen.class.getResourceAsStream("res/bgmusic.wav"); AudioInputStream audioIn; // System.out.println(ins); try { clip = AudioSystem.getClip(); audioIn = AudioSystem.getAudioInputStream(ins); clip.open(audioIn); } catch (UnsupportedAudioFileException e) { // ignore e.printStackTrace(); return; } catch (IOException e) { // ignore e.printStackTrace(); return; } catch (LineUnavailableException e) { // ignore e.printStackTrace(); return; } // System.out.println("woohoo"); clip.loop(Clip.LOOP_CONTINUOUSLY); }
protected void startFile(File file) { currentFile = file; AudioFormat format; try { format = AudioSystem.getAudioFileFormat(file).getFormat(); float samplerate = format.getSampleRate(); int size = 1024; int overlap = 0; PitchResyntheziser prs = new PitchResyntheziser(samplerate); estimationGain = new GainProcessor(estimationGainSlider.getValue() / 100.0); estimationDispatcher = AudioDispatcher.fromFile(file, size, overlap); estimationDispatcher.addAudioProcessor(new PitchProcessor(algo, samplerate, size, prs)); estimationDispatcher.addAudioProcessor(estimationGain); estimationDispatcher.addAudioProcessor(new AudioPlayer(format)); sourceGain = new GainProcessor(sourceGainSlider.getValue() / 100.0); sourceDispatcher = AudioDispatcher.fromFile(file, size, overlap); sourceDispatcher.addAudioProcessor(sourceGain); sourceDispatcher.addAudioProcessor(new AudioPlayer(format)); new Thread(estimationDispatcher).start(); new Thread(sourceDispatcher).start(); } catch (UnsupportedAudioFileException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void run() { File soundFile = new File(filename); if (!soundFile.exists()) { System.err.println("Wave file not found: " + filename); Dialog.erreur(null, "Le fichier " + filename + " n'a pas été trouver."); return; } AudioInputStream audioInputStream = null; try { audioInputStream = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); return; } catch (IOException e1) { e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); SourceDataLine auline = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); try { auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); } catch (LineUnavailableException e) { e.printStackTrace(); return; } catch (Exception e) { e.printStackTrace(); return; } if (auline.isControlSupported(FloatControl.Type.PAN)) { FloatControl pan = (FloatControl) auline.getControl(FloatControl.Type.PAN); if (curPosition == Position.RIGHT) pan.setValue(1.0f); else if (curPosition == Position.LEFT) pan.setValue(-1.0f); } auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { e.printStackTrace(); return; } finally { auline.drain(); auline.close(); } }
public ThreadSound() { try { clip0 = AudioSystem.getClip(); clip1 = AudioSystem.getClip(); } catch (LineUnavailableException e) { e.printStackTrace(); canPlayAudio = false; } }
/** @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent) */ @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == play) { try { ReJava.playSample(waveData, sps); } catch (LineUnavailableException e1) { e1.printStackTrace(); } } }
public void run() { File soundFile = new File(this.filename); if (!soundFile.exists()) { System.err.println("nicht gefunden: " + filename); return; } AudioInputStream audioInputStream = null; try { audioInputStream = AudioSystem.getAudioInputStream(soundFile); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); return; } catch (IOException e1) { e1.printStackTrace(); return; } AudioFormat format = audioInputStream.getFormat(); SourceDataLine auline = null; DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); try { auline = (SourceDataLine) AudioSystem.getLine(info); auline.open(format); } catch (LineUnavailableException e) { e.printStackTrace(); return; } catch (Exception e) { e.printStackTrace(); return; } FloatControl rate = (FloatControl) auline.getControl(FloatControl.Type.SAMPLE_RATE); rate.setValue(rate.getValue() * 5f); auline.start(); int nBytesRead = 0; byte[] abData = new byte[EXTERNAL_BUFFER_SIZE]; try { while (nBytesRead != -1) { nBytesRead = audioInputStream.read(abData, 0, abData.length); if (nBytesRead >= 0) auline.write(abData, 0, nBytesRead); } } catch (IOException e) { e.printStackTrace(); return; } finally { auline.drain(); auline.close(); } }
// Constructor takes the name to save decoded track as in the form of a string ex:"track1.wav" public FlacTrackPlayer(String trackName) { player = null; track = new File(trackName); Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[0]); try { mixer.open(); } catch (LineUnavailableException e) { // TODO Auto-generated catch block System.out.println("huh?"); e.printStackTrace(); } }
@Override public void actionPerformed(final ActionEvent e) { String name = e.getActionCommand(); PitchEstimationAlgorithm newAlgo = PitchEstimationAlgorithm.valueOf(name); algo = newAlgo; try { setNewMixer(currentMixer); } catch (LineUnavailableException e1) { e1.printStackTrace(); } catch (UnsupportedAudioFileException e1) { e1.printStackTrace(); } }
public Oscilator(int sampleRate) { this.sampleRate = sampleRate; // オーディオ形式を指定 AudioFormat af = new AudioFormat(sampleRate, 8, 1, true, true); try { DataLine.Info info = new DataLine.Info(SourceDataLine.class, af); line = (SourceDataLine) AudioSystem.getLine(info); line.open(); line.start(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
/** @param filename the name of the file that is going to be played */ public void playSound(String filename) { String strFilename = filename; try { soundFile = new File(strFilename); } catch (Exception e) { e.printStackTrace(); System.exit(1); } try { audioStream = AudioSystem.getAudioInputStream(soundFile); } catch (Exception e) { e.printStackTrace(); System.exit(1); } audioFormat = audioStream.getFormat(); DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat); try { sourceLine = (SourceDataLine) AudioSystem.getLine(info); sourceLine.open(audioFormat); } catch (LineUnavailableException e) { e.printStackTrace(); System.exit(1); } catch (Exception e) { e.printStackTrace(); System.exit(1); } sourceLine.start(); int nBytesRead = 0; byte[] abData = new byte[BUFFER_SIZE]; while (nBytesRead != -1) { try { nBytesRead = audioStream.read(abData, 0, abData.length); } catch (IOException e) { e.printStackTrace(); } if (nBytesRead >= 0) { @SuppressWarnings("unused") int nBytesWritten = sourceLine.write(abData, 0, nBytesRead); } } sourceLine.drain(); sourceLine.close(); }
private static void scale(int f0, int range) { double hz; for (double n = 0; n <= 6 * range; n += 0.5) { if ((int) (n / 6) != n / 6 && (int) ((n - 2.5) / 6) != (n - 2.5) / 6) { n += 0.5; } hz = f0 * Math.pow(2, n / 6.0); try { Tone.sound(hz, 100, 1); } catch (LineUnavailableException e) { e.printStackTrace(); } } }
public MakoVM(int[] m) { this.m = m; try { AudioFormat format = new AudioFormat(8000f, 8, 1, false, false); DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); soundLine = (SourceDataLine) AudioSystem.getLine(info); soundLine.open(format, 670); soundLine.start(); } catch (IllegalArgumentException e) { System.out.println("Unable to initialize sound."); } catch (LineUnavailableException e) { e.printStackTrace(); } }
/** * Sets the value of output to newOutput. The output variable specifies whether or not to play the * audio of this source on the server. * * @param newOutput The new value for output. */ public void setOutput(boolean newOutput) { output = newOutput; if (output) { try { serverOutput.open(); } catch (LineUnavailableException e) { e.printStackTrace(); } serverOutput.start(); } else { serverOutput.stop(); serverOutput.close(); } }
/** Load all sounds */ private static void load() { loaded = true; try { startSound = Resources.loadSound("/sounds/start.wav"); backgroundSound = Resources.loadSound("/sounds/background.wav"); placeholderSound = Resources.loadSound("/sounds/placeholder.wav"); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
public WavEffect(String fileName) { URL url = getClass().getResource("/audios/" + fileName); try { clip = AudioSystem.getClip(); AudioInputStream input = AudioSystem.getAudioInputStream(url); clip.open(input); } catch (LineUnavailableException e) { e.printStackTrace(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private void sound(String nameSound) { Clip clip; try { clip = AudioSystem.getClip(); clip.open(AudioSystem.getAudioInputStream(new File("resource/fileSound/" + nameSound))); clip.start(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
public static void ScoreUp() { try { AudioInputStream audioIn; Clip clip; clip = AudioSystem.getClip(); audioIn = AudioSystem.getAudioInputStream(Main.class.getResource("/Sounds/Score.wav")); clip.open(audioIn); clip.start(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
private void init() { AudioFormat format = new AudioFormat((float) 44100, 16, 2, true, false); try { DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); mainLine = (SourceDataLine) AudioSystem.getLine(info); mainLine.open(format); mainLine.start(); bufferLine = (SourceDataLine) AudioSystem.getLine(info); bufferLine.open(format); bufferLine.start(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
public static void Play() { try { // Open an audio input stream. File soundFile = new File("foo.wav"); AudioInputStream audioIn = AudioSystem.getAudioInputStream(soundFile); // Get a sound clip resource. Clip clip = AudioSystem.getClip(); // Open audio clip and load samples from the audio input stream. clip.open(audioIn); clip.start(); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
public void run() { try { b = new byte[6300]; line.open(new AudioFormat(44100, 16, 1, true, true), 6300); line.start(); while (true) { line.read(b, 0, b.length); server.writeByteBuffers(b, sourceIndex); if (output) serverOutput.write(b, 0, b.length); } } catch (LineUnavailableException e) { e.printStackTrace(); System.out.println(sourceIndex); } finally { line.stop(); line.close(); } }
// ctor public DataInThread(DatagramSocket socket) { try { dSocket = socket; // sampl Rate & bits, #Channels, signed?, bigEndian? AudioFormat format = new AudioFormat(16000.0f, 16, 1, true, true); microphone = AudioSystem.getTargetDataLine(format); micData = new byte[MAXBUFSIZE]; microphone.open(format); inputThread = new Thread(this); } catch (LineUnavailableException e) { // TODO is there anything else we should do if the microphone // can't be connected? // http://stackoverflow.com/questions/14348169/understanding-java-sound-api-finding-mic-on-mixer e.printStackTrace(); } }
@SuppressWarnings("static-access") private void PlayMusic() { try { AudioInputStream audioIn; Clip clip; clip = AudioSystem.getClip(); audioIn = AudioSystem.getAudioInputStream(this.getClass().getResource("/Sounds/Main.wav")); clip.open(audioIn); clip.start(); clip.loop(clip.LOOP_CONTINUOUSLY); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
// Constructor to construct each element of the enum with its own sound file. SoundEffect(String soundFileName) { try { // Use URL (instead of File) to read from disk and JAR. URL url = this.getClass().getClassLoader().getResource(soundFileName); // Set up an audio input stream piped from the sound file. AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(url); // Get a clip resource. clip = AudioSystem.getClip(); // Open audio clip and load samples from the audio input stream. clip.open(audioInputStream); } catch (UnsupportedAudioFileException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (LineUnavailableException e) { e.printStackTrace(); } }
// 播放au,aiff,wav音乐流, 这个函数基本完全为帖子上的代码 private synchronized void play() { ByteArrayInputStream aMusicInputStream; AudioFormat format; AudioInputStream musicInputStream; byte[] audioSamples; SourceDataLine line; try { File MusicFile = new File(m_filename); musicInputStream = AudioSystem.getAudioInputStream(MusicFile); // 取得文件的音频输入流 format = musicInputStream.getFormat(); // 取得音频输入流的格式 audioSamples = getAudioSamples(musicInputStream, format); // 取得音频样本 aMusicInputStream = new ByteArrayInputStream(audioSamples); int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10); byte[] buffer = new byte[bufferSize]; try { DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); line = (SourceDataLine) AudioSystem.getLine(info); line.open(format, bufferSize); } catch (LineUnavailableException e) { e.printStackTrace(); return; } if (!line.isRunning()) { line.start(); } int numBytesRead = 0; while (numBytesRead != -1 && !m_stopped) { numBytesRead = aMusicInputStream.read(buffer, 0, buffer.length); if (numBytesRead != -1) { line.write(buffer, 0, numBytesRead); } } line.drain(); line.close(); } catch (Exception e) { e.printStackTrace(); } }
public SourceDataLine getFreeLine(AudioFormat format, int volume) { try { synchronized (this) { DataLine.Info info = new DataLine.Info(SourceDataLine.class, format); if (currentLine >= lines.length) { currentLine = 0; } if (lines[currentLine] == null) { lines[currentLine] = (SourceDataLine) AudioSystem.getLine(info); } if (!lines[currentLine].isActive()) { return lines[currentLine++]; } } } catch (LineUnavailableException e) { e.printStackTrace(); LOGGER.error(e.getMessage()); } return null; }