Working With/Processing Audio in Java - java

Anyone know of any good tutorials or reference guides for working with Audio in Java? I'm not looking for anything too specific at this point; just would like to get my feet wet working with audio. Thanks in advance!

First of all: Multimedia/audio support in Java is not great.
But—if you're set on Java, I suggest taking a look at the Java Sound Trail. It explains most of the basic APIs. Then check out Java Sound Resources to get a better idea of how things work. Even though it's not brand-new anymore, it is very useful and explains a lot about the low level details.
Beyond the raw sound API, Sun came up with JMF, the Java Media Framework. It has been unsupported for years, so I would stay clear of it. You might want to use it for inspiration, but I can't recommend using it for more.
You will also discover that the built-in Java support for audio formats like mp3 or ogg is rather limited. To be able to play such files, you will need third party libraries, like jogg, jflac, mp3spi, or SampledSP. While the first three are pure Java solutions, the last one is basically a thin Java wrapper for a number of native libraries. Especially for FFmpeg there are a many different libraries like that, as FFmpeg supports most available audio formats.
The only way to play an mp3 file from Java without any additional libraries, is to cheat and use the JavaFX class MediaPlayer. You can find more info about how to do that on Stackoverflow.
Good luck!

Related

Mixing audio with java

I have been looking for good examples of sound mixing using Java in vain. I am developing an Android app and would like to implement such feature. I am mainly looking for a way of mixing (or merging) multiple wav or mp3 sounds into a single sound file and save it as a specific format (mp3 or wav). I have found a couple of sources, unfortunately they don't offer enough comprehensive documentations. I just don't want to copy and past codes without understanding the core concepts. I have tried to implement the Jmusic library, but I keep getting errors and my app always crashes when reading the files. Any help would be greatly appreciated. Thanks

What Java APIs should I look into for interacting with my microphone?

I would like to build a recording software, for my own purposes, I would like it to be deployable on multiple systems (Windows and Unix) I am also building an application first time. So any help you would be able to provide on that topic as well it would be appreciated.
Please and thank you.
GC
I haven't seen any API for dealing with Microphones explicitly, but the Java Sound API should be able to see it as an input. Specifically, the javax.sound.sampled classes.
Oracle has a (not-so-quick) Java Sound Programmer Guide which includes Chapters on Accessing Audio System Resources and Capturing Audio.
You might look at BASS if you only need to support OS/X and/or Windows. I haven't used it or JavaSound recently enough to speak to which is better at the moment, but BASS was good enough to merit a looksee.

A simple free MIDI implementation in Java besides javax.sound.midi: Are there any?

The problem is: Android doesn't implement javax.sound.midi.
I need a simple free library that allows me to create simple 1-track midi files.
I searched the net for it, but can't really find anything, since everything uses javax.sound.midi .
The license needs to be one where I don't need to opensource my linked app.
Any ideas?
I also looked into the fileformat itself. However, I am totally not familiar with working with bytes, hexidecimal stuff etc.
So, other option is: are there any simple midi implementations that I can use as reference?
Well, for all you midi needing android devs: check out this Dutch university assignment
that contains a very very basic midi file writer. Together with this reference doc you can easily expand it into playing chords, selecting instrument etc.
It worked for me!
I do have opened a feature request for direct streaming access to the synthesizer. If you are interested in streaming midi, please rate, star, comment there.
http://kevinboone.net/javamidi.html
I've recently uploaded a MIDI library written in Java to Google Code:
http://code.google.com/p/android-midi-lib/
For those who come across this more recently Android does, as of API version 23, implement android.sound.midi which is not an implementation of javax.sound.midi but does have a very similar API.

Java for a video based application: Good choice?

I am in the concept phase of an application that is going to have a lot of Audio/Video input and output. I want to do it in Java; but somehow am not fully convinced yet. What do you think? How bad could it be? And any advices?
Why I am thinking Java:
It's the language I'm most comfortable with.
Easier cross platform migration would be a bonus.
Cannot afford commercial platforms (like .NET) or not good enough in other free alternatives (like Python)
I'm also slightly inclined towards C++/Qt; but that would take more time for me as I'm not great in that and I am a bit worried about maintainability.
If you're interested, check out Xuggler. It exposes all the power of FFmpeg, but as a Java API that runs on Windows, Mac and Linux. The advantage is you get all the power of FFmpeg but from Java. The disadvantage is it requires the FFmpeg native DLLs/shared-libraries to be installed.
Easier cross platform migration would be a bonus.
Audio and video means you will be dealing with dedicated native libraries and JNI-wrappers for each supported platform; in this case, the cross-platform argument for Java does not really apply.
I believe that when you want to write an audio/video application, the programming language you will use is the second most important thing. The most important thing is the audio/video framework your application will use since this is what defines your capabilities.
I am aware of two popular generic video frameworks that can be used to accesd most multimedia types: Directshow and ffmpeg. Directshow is tied with windows, so only ffmpeg is left.
Ffmpeg has versions in both windows and unix and, although it is written in C, it can be used from a lot of languages.
There is even a number of java wrappers for ffmpeg (for instance, take a look at xuggle)!
C++ would be the first choice because of performance concerns often present in Audio/Video processing as well as the range of available libraries for video/audio.
You do make a good point about being familiar with Java. If you are pressed for time, this is even more important. However if you can spare some time for learning, C++ would be well worth it.
Regarding .NET: The .NET SDK with everything you need is freely downloadable. Get hold of a free IDE such as SharpDevelop and you are up and running. It's Visual Studio that costs money, you don't need Visual Studio to do .NET development.
Rusty.in,
How about trying to do JavaFX Media API. Recently, the version of the JavaFX is 1.2.0 with GUI Application as well. It supports the Swing. The grammar is based on the script style; however, you can deploy the existing Swing components into the JavaFX.
I hope it helps.
Tiger
Rusty, what did you wind up doing? I too have a video app I'd like to do, but really would prefer Java/JavaFX over C++. The thing about the using Flash and/or the current JavaFX video support is that Flash video playback is not frame-accurate. I really need to be able to stop/start/step on individual frames like you can with QuickTime.
Has anyone tried doing playback with Xuggler and Java/JavaFX?

Video Thumbnails in Java

I want to generate a thumbnail preview of videos in Java. I'm mostly JMF and video manipulation alienated.
Is there an easy way to do it?
What about codecs? Will I have to deal with it?
Any video type is suported? (including Quicktime)
Well, since you're not stuck with JMF, have you considered Xuggler? Xuggler is a Java API that uses FFmpeg under the covers to do all video decoding and encoding. It's free and LGPL licensed.
In fact, we have a tutorial that shows How to Make Thumbnails of an Existing File
There seems to be a few examples out there that are far better than what I was going to send you.
See http://krishnabhargav.blogspot.com/2008/02/processing-videos-in-java.html.
I'd agree with Stu, however. If you can find a way to get what you want using some command-line tools (and run them using Commons-Exec), you might have a better overall solution than depending on what is essentially the Sanskrit of Java extensions.
Are you sure that JMF is right for you? Unfortunately, it is not in particularly good shape. Unless you are already committed to JMF, you very well may want to investigate alternatives. Wikipedia has a decent overview at en.wikipedia.org/wiki/Java_Media_Framework
Many JMF developers have complained that it supports few codecs and formats in modern use. Its all-Java version, for example, cannot play MPEG-2, MPEG-4, Windows Media, RealMedia, most QuickTime movies, Flash content newer than Flash 2, and needs a plug-in to play the ubiquitous MP3 format. While the performance packs offer the ability to use the native platform's media library, they're only offered for Linux, Solaris and Windows. Furthermore, Windows-based JMF developers can unwittingly think JMF provides support for more formats than it does, and be surprised when their application is unable to play those formats on other platforms.
Another knock against JMF is Sun's seeming abandonment of it. The API has not been touched since 1999, and the last news item on JMF's home page was posted in November 2004.
While JMF is built for extensibility, there are few such third-party extensions.
Furthermore, editing functionality in JMF is effectively non-existent, which makes a wide range of potential applications impractical.
My own server-side app shells out to FFmpeg to do the encoding. I'm 98.42% sure FFmpeg does snapshots, too. (It is an all singing, all dancing beast of a program. The command line options alone could fill a book.)
Check it out: ffmpeg.mplayerhq.hu
There is a relatively newer option called JThumbnailer that you find here: https://github.com/makbn/JThumbnail
JThumbnail is a Java library for creating Thumbnails of common types
of file including .doc, .docx, .pdf , .mp4 and etc. full list

Categories