File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Exploring source code for Clip Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Exploring source code for Clip" Watch "Exploring source code for Clip" New topic
Author

Exploring source code for Clip

Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
I've written a class for myself that provides some of the functions of a javax.sound.sampled.Clip, and adds some additional capabilities (multiple/overlapping playback, varispeed playback). I am thinking of revising it, so that it becomes a class that both fully implements the Clip interface as well as providing my additional methods. In doing so, I thought it would be interesting to look at the code that implements Clip.

But this leads to a really basic question. The code for Clip is of course just the Interface code, the list of methods to implement, not their actual implementation. So, I am wondering, for example, just how IS the data for a Clip held internally? Where are the variable & pointers and the methods that DO the provided functions?

I downloaded the source code for Java and am poking around, and found j2se/src/share/classes/javax/sound/sampled/ which contains the source code for Clip. Also viewed AudioSystem which is used to provide a DataLine that has been cast to a Clip. But that is all, and DataLine is also an Interface.

With a class like HashMap, which implements Map, in this source file we get to see how the methods are coded. Where would someone find something like this for Clip? There has to be some concrete class that makes all the methods concrete, doesn't there? I suspect I'm having some sort of basic conceptual confusion.

EDIT: just found AudioInputStream. Perhaps the most correct course of action would be to start with making my new super-duper clip class extend AudioInputStream and implement Clip? But the Clip is supposed to have loaded the data from the input stream into memory. Still grappling...
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42592
    
  65
I don't have the JDK source handy at the moment, but I seem to recall audio stuff being implemented somewhere in the com.sun.* package hierarchy. Searching for "implements Clip" or something like that should find it.


Ping & DNS - my free Android networking tools app
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
Excellent idea, searching for "implements Clip"!

Unfortunately, searching with my Windows "search" function is not working as expected. I'll have to find another way to search.

sun.audio.AudioData -- this seems to be the class where Clip data is stored.

and et cetera.
Phil Freihofner
Ranch Hand

Joined: Sep 01, 2010
Posts: 115
    
    1
Just a couple more notes for anyone who might be following:

One can get source code in the JDK download. I use Eclipse, and was able to attach the "src.zip" to rt.jar and now the Eclipse search function can search within the source code for rt (defined as a "working set" for the Eclipse search), which is where the audio seems to reside.

Second note: some of the sun and com.sun files which hold audio are not included in the JDK download, for some reason. However, there is a snapshot of Java 1.6...I can't recall the exact update...on Java.net. From this download of source code, I was able to find a few more relevant audio packages and add them to the src.zip provided by the JDK.

So far, found at least two classes which implement Clip:

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exploring source code for Clip