Is there an .m4a service provider interface for java sound? - java

I've written a simple media player that uses java sound and a bunch of different SPIs to give support for various audio formats. I haven't been able to find an SPI for .m4a yet though. I've looked at JAAD but it seems to only have an SPI for AAC, not M4A.
Is there one out there?

So after doing more research, it look like JAAD should in theory work for .m4a and .mp4 containers if the audio inside is AAC. For me, It's going as far as getting the dataline, but then it's not actually reading bytes from the decoded stream. I posted this as a question here: Java sound not playing m4a files through JAAD

Related

How to implement a video exporter in Spring?

I am implementing an online video editing platform, as a part of which, the users edit their videos online, and then export the edited video either in native format (suppose .xyz) or other standard video file formats like .mp4, .mov, .avi etc.
My question is: how should I go about implementing the video exporting part? I looked it up around the internet, and found some interesting topics that might be of use, like video web codecs and lossless compression of video files.
I am implementing the backend of the application in Spring, and I am a complete beginner in these areas.
Any help on how I should get started and implement this video file exporter would be greatly appreciated.

How to decode ogg vorbis file java?

I'm getting started with lwjgl and openal, so I want to be able to decode an ogg vorbis file and play it with openal. My question is: how can I decode an ogg file from java, get the frequency, pcm data, etc. and send it over to openal so I can play it? I found jorbis to do this, but it seemed just too difficult to use, and the tutorials online are kinda messy. I was thinking of something like alutLoadWavFromFile but for ogg(and java).
Thanks!
EDIT: Ok, I'll clarify my question. I want to decode an ogg file. And then send the data to openal. But the only part I don't know how to do is the decoding part.
VorbisJava does exactly this. There is a reasonable example in the tools directory.
https://github.com/Gagravarr/VorbisJava/blob/master/tools/src/main/java/org/gagravarr/vorbis/tools/VorbisCommentTool.java
VorbisFile vf = new VorbisFile(new File(inFile));
Also, Java Sound API has an extensible service provider model. You can add OggVorbis as a provider.
See How can I decode OGG vorbis data from a ByteBuffer?

Play m4a files in Java

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();

How can I play and manipulate .wav files using Java?

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.

Playing small sounds in Java game

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.

Categories

Resources