This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using JavaFX to play audio from a PCM stream (not from a file)

 
Phil Freihofner
Ranch Hand
Posts: 121
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This topic was brought up several years ago, but JavaFX has evolved since then. Here is a link to the earlier post: Open a Media from InputStream

What I am wondering is similar. I have a read() method which provides a "frame" of audio data (two floats, one for left, one for right, holding PCM data ranging from -1 to 1). It can easily be altered to provide a larger array of PCM data if that proves helpful. I'm wondering if there is a way to make use of the JavaFX audio for playing back this stream, perhaps by routing it through Media/MediaPlayer. By my reading of the api for Media, a URI is needed, but my data is not in File form.

I currently have audio playback from this stream working quite well using the javax.audio.sampled library, and have also written a wrapper that allows my streamed output to be played on Android. I'm just curious if there is a way to use JavaFX audio as well.

Second question: I'm unclear on how to find out if the JavaFX audio implementation makes use of any of the existing implementations for javax.audio.sampled, or if they are wholly new. How does one go about researching such a question?

 
Karthik Shiraly
Bartender
Posts: 1210
25
Android C++ Java Linux PHP Python
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Phil Freihofner wrote:Second question: I'm unclear on how to find out if the JavaFX audio implementation makes use of any of the existing implementations for javax.audio.sampled, or if they are wholly new. How does one go about researching such a question?

By digging into the source code. Oracle doesn't open source its JRE completely, but Oracle JRE is for the most part same as the completely open source OpenJDK project, which is itself the open source fork of Sun's JRE.
So digging into OpenJDK and OpenJFX source code should answer your question.

I've not dug deep into the source code, but as far as I know, javax.sound* was java wrapper around native DirectSound/WinMM on Windows and ALSA on Linux. JavaFX media is a rewritten java wrapper that does not use javax.sound.*, but uses native DirectX on Windows and gstreamer on Linux.

http://hg.openjdk.java.net/icedtea/jdk8/jdk/file/aa2c9ce06632/src/ is the OpenJDK codebase.
The sound subproject tells where their implementations are in the codebase (mainly [share|linux|windows]/com/sun/media/sound)

http://hg.openjdk.java.net/openjfx/8u60/rt/file/996511a322b7 is the OpenJFX codebase.
Their build page gives some clues on the native dependencies.
 
John Damien Smith
Ranch Hand
Posts: 299
15
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
According to the Java 8 media documentation, as far as my reading of it goes, although PCM playback is supported, that is only when encoded in a WAV or AIFF file (or http resource). This may change for future releases, e.g., Java 9+.

The streaming technology supported is MP3 HTTP Live Streaming (or AAC for mixed audio/visual streams). You could potentially run an external http live streaming server which takes your PCM stream and converts it to a http live stream for consumption by your JavaFX application (I assume such servers exist, though I have not researched it). I don't know if that would really be practical or a good idea for your use case or not.

[berry120 did an analysis of modifying the JavaFX media playback for supporting additional formats](http://stackoverflow.com/a/22563941/1155209). This is not the format you are looking for. But you could review his analysis to get a broad overview of what is happening in the JavaFX media implementation and how it might be modified to suit other purposes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic