• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JMF and Java Sound at same time?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Is it possible to use a Java sound resource (such as the
javax.sound.midi.Synthesizer.java) at the same time as a JMF
resource (such as javax.media.Player.java)?
I am having problems with this (the two resources appear to contend for the same audio resource).
I wish to play out MIDI notes at the same time as playing out movie animations, so if there is a different way to do this, please let me know.
Thank you in advance...
-John
 
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Howdy -- I don't know the answer to your question; I've never tried to use the two together (I have managed to synchronize midi events with plain old graphics animations in Java, but that's different).
But have you looked at this FAQ? It seems pretty detailed; it told me about a major bug in the midi event callback system that I would never have found otherwise. It *does* discuss the relationship between javax.sound and JMF, although I have no idea if it answers your question:
http://www.jsresources.org/faq/jspfaq.html
cheers and good luck,
Kathy
p.s. if anybody want to talk more about sound, that would be GREAT. I'm just getting started, although I'm focusing exclusively onthe MIDI side right now.
 
John Wood
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the reply Kathy. I've added a few more thoughts to this thread below...

>Howdy -- I don't know the answer to your
>question; I've never tried to use the two
>together (I have managed to synchronize midi
>events with plain old graphics animations in
>Java, but that's different).
Sun's JMF FAQ mentions that "JMF uses the Java Sound API for sound rendering". Based on this, I was really hoping that JMF and Java Sound resources could play together. An interesting observation is that at least two Players can be operating at the same time, both playing audio and video simultaneously, so there is definitely some multiplexing ability under the hood. Sounds like one for the Sun engineers!
>But have you looked at this FAQ? It seems pretty
>detailed; it told me about a major bug in the
>midi event callback system that I would never
>have found otherwise. It *does* discuss the
>relationship between javax.sound and JMF,
>although I have no idea if it answers your
>question:
>
>http://www.jsresources.org/faq/jspfaq.html
I had looked at this FAQ before, and hadn't thought to search the MIDI part of it! I'm not sure if the event bug is an impact on my specific app as I'm only outputting MIDI notes via the Synthesizer class, but there are several references to JDK-version-dependent issues that I hadn't known before. I definitely need to try my app code on the latest JDK version...

>p.s. if anybody want to talk more about sound,
>that would be GREAT. I'm just getting started,
>although I'm focusing exclusively onthe MIDI
>side right now.
Sounds good to me! Thanks again for the information Kathy.
John
 
Kathy Sierra
Cowgirl and Author
Posts: 1589
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by John Wood:
I'm not sure if the event bug is an impact on my specific app as I'm only outputting MIDI notes via the Synthesizer class, but there are several references to JDK-version-dependent issues that I hadn't known before. I definitely need to try my app code on the latest JDK version...


The bug I mentioned had to do with implementing your own Receiver to get the MIDI events (so it sounds like that's probably not your issue). I wanted to synchronize the MIDI sound from the Sequencer with my own Graphics2D animation. But implementing a Receiver apparently does not work in 1.3 and 1.4 (according to that FAQ, and it proved to be my problem). You just never do get the event!
My fix was that instead of trying to listen for the actual MIDI events, I had to insert (into the Track) my own 'do nothing' control event at the same 'tick' as the MIDI events I was creating for that Track, and then implemented a ControllerEventListener, and it works perfectly on Windows 98 (java 1.4) and MacOSX (1.3), and Linux (1.4)
I too was (and am) worried about the platform-dependent issues, because according to what I was reading, it seemed like there might not even be a SoundBank available... but I sent my MIDI program to a group of my friends and so far I have not found anyone who was not able to play it without a hitch, and NONE of them had done any other work with JavaSound APIs (or software synthesizers, so they had not, for example, downloaded a SoundBank from java.sun.com prior to playing this).
I'm still trying to find out why MidiSystem throws an exception for being "unavailable" -- like, under what circumstances would that ever happen? I'm kind of going on the (flawed and naive) assumption that if you have Javax.sound.midi, and you're running on 1.3 or 1.4, you'll get a Sequencer and everybody will be happy
So, again, sorry I'm useless with JMF; this is my first foray into media. And even though documentation is scarce and unclear, it sure is fun
cheers,
Kathy
 
John Wood
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
>My fix was that instead of trying to listen for
>the actual MIDI events, I had to insert (into
>the Track) my own 'do nothing' control event at
>the same 'tick' as the MIDI events I was
>creating for that Track, and then implemented a
>ControllerEventListener, and it works perfectly
>on Windows 98 (java 1.4) and MacOSX (1.3), and
>Linux (1.4)
I'll keep this fix in mind for sure!

>I too was (and am) worried about the platform-
>dependent issues, because according to what I
>was reading, it seemed like there might not even
>be a SoundBank available...
There are different size/quality soundbanks as well. For example, I have two soundbank files in my sound install 'lib' directory: soundbank.gm and soundbank-deluxe.gm. The deluxe one is 5 meg!
I figure that the low quality one is more widely available (so your app may not sound as good on someone else's machine). Seems I read that from JDK v1.3 on, the sound API is included, though not sure about that, in which case the low quality soundbank is probably automatically available after JDK install.

>I'm still trying to find out why MidiSystem
>throws an exception for being "unavailable" --
>like, under what circumstances would that ever
>happen? I'm kind of going on the (flawed and
>naive) assumption that if you have
>Javax.sound.midi, and you're running on 1.3 or
>1.4, you'll get a Sequencer and everybody will
>be happy
Actually, this is the very problem I see!
I see this exception thrown if I try to instantiate JMF Player objects before calling MidiSystem.getSynthesizer() to get my MIDI Synthesizer. I figure that the JMF system is claiming the sound resource all to itself, so the MIDI/Sound-API system cannot allocate it. Again, this seems strange to me if JMF is using the Sound API under the hood.

>So, again, sorry I'm useless with JMF; this is
>my first foray into media. And even though
>documentation is scarce and unclear, it sure is
>fun
Like any cool technology, there is always a little pain to endure before things work right!
Good luck,
John
 
reply
    Bookmark Topic Watch Topic
  • New Topic