• 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

Exploring source code for Clip

 
Ranch Hand
Posts: 140
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Phil Freihofner
Ranch Hand
Posts: 140
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 140
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic