I need to display a graph of a sound file - i.e. a wave form as displayed by audio editors such as Audacity.
How should I go about this? Is there anything in the Java Sound API that can help me?
In Java Sound API poke around AudioSystem.getAudioInputStream
which will return AudioInputStream which shows you how to open audio files form within Java. It is good enough to read .wav files, but not quite so for mp3s.
It lets you read bytes one by one directly. Also getAudioFormat will return object that has sample rate, bit/sample, etc. After reading your waveform you can draw it in your favorite way on the screen (Swing, AWT, png file on the web, etc.).
In the end I found code to do exactly what I wanted in Chapter 10 of the book Swing Hacks.
Related
I want to create a media player in Java. The mp3 support already works with the JLayer library but which library can play m4a files?
I read about vlcj here on stackoverflow, but this seems to depend on Swing/AWT which I wouldn't use because I want to port the application to Android later on.
Have you looked at JAAD? It's a Javasound SPI that decodes AAC audio, I've used it with success previously.
Note that m4a is a container format, and while it usually contains (in my experience) AAC audio, in theory it could contain other formats instead.
You can find some information about getting it working without Javasound (and a test case) here.
This answer is indirect. I don't really know anything about m4a files. But what I have found is an open source library that can stream them as a flash server named red5. It's written in Java so theoretically you should be able to browse their code to figure out how to do it.
Hopefully someone here can give a more direct answer, this is the best I can do.
If you have Java 7 or later, you have access to the Javafx library. You can also use your media player (like iTunes or Windows Media Player) to convert to the simpler mp3 version and run that. I wouldn't recommend .wav files as they have significantly more data usage than mp3s, (which condense the file size by compressing the .wav data and omitting inaudible and otherwise garbage-y data).
import javafx.scene.media.*;
String name = "song.mp3";
Media song = new Media(name);
MediaPlayer player = new MediaPlayer(song);
player.play();
I'm working on a little science project, and I really want to record audio from an audio input and a program running on my computer, how to do this in Java? It would be awesome if the bit rate for example is customizable somehow. Files like .mp3 or similar would be awesome, it shouldn't be a problem if it's any different file type, because it could be converted.
I've heard about a Java Sound API but I don't really get how to really record audio with this API.
Thanks in advance,
Tim Visée
I'm looking for a small library to play, merge and change pitch for .wav files.
I've tried JASS, beads, something from anyexample.com, basic javax.sound examples, Sonia Sound Library etc.
Can anyone help me? I just need change pitch, merge and play wav files in Java.
Have you tried the Java Media Framework? Even though it has its limitations, it may be an option. In addition, the wikipedia article (linked above) has a listing of alternatives - maybe one of them does the trick for you.
I'm searching a java framework for manipulate audio and video files, I need functions like:
Split video and audio files
Get a frame from a video
Key Frame extraction
I tried Xuggle and I want to know if there are other frameworks.
any advice?
I found Xuggler: http://www.xuggle.com/xuggler/
Which audio and video format you are dealing with? For MPEG-2, Project X may be a solution.
For the computer game I'm making, I obviously want to play sound. So far, I've been using AudioClip to play WAV files. While this approach works fine, the WAV files tend to be gigantic. A few seconds of sound end up being hundreds of kB. I'm faced with having a game download that's 95% audio!
The obvious option here would be to use MP3 or Ogg Vorbis. But I've had limited success with this - I can play MP3 using JLayer (but it plays in the same thread). As for Ogg, I've had no luck at all. Worse, JLayer's legal status is a bit on the dubious side.
So my question is to both Java developers and generally people who actually know something about sound: What do I do? Can I somehow "trim the fat" off my WAVs? Is there some way of playing Ogg in Java? Is there some other sound format I should use instead?
You could use JOrbis library to play back OGG music. For working sample usage you can look at these files here.
I also experimented with some lossless audio compression, for example I had a 16 bit mono sound. I separated the upper and lower bytes of each sample and put them after each other. Then I applied a differential replacement where each byte is replaced by its difference from the last byte. And finally used GZIP to compress the data. I was able to reduce the data size to 50-60% of the original size. Unfortunately this was not enough so I turned to the OGG format.
One thing I noticed with 8 bit music is that if I change the audio volume, the playback becomes very noisy. I solved this problem by upsampling the audio data to 16 bit right before the SourceDataLine.write().
These may be outdated, but they are officially recognized by the Xiph.org team (who maintain Ogg and Vorbis, among others).
http://www.vorbis.com/software/#java
The problem you describe is addressed by the Service Provider Interface (SPI) for sound in Java. The result is that simply adding JAR files to your classpath will add functionality to the default Java Sound API. Thus enabling the handling of more sound formats without changing code.
Last time I tried this the Javazoom people offered a working MP3 SPI JAR. Which was based on the JLayer you mentioned.
For Vorbis OGG there now also seems to be an SPI library. Check out the docs on the Vorbis SPI on Javazoom.
If you decide to stay with wav format...
It is probably not very important to have high quality sound files. You can use your favorite wav editor to lower the bit rate, switch to mono, or both. That will save tons of space and you won't notice the difference in quality while playing the game.
Hope this helps.