Hello.  I have the following code snippet to start reading an mp3 file

(let [file (File. filename)
      stream (AudioSystem/getAudioInputStream file)
      base-format (.getFormat stream)
      decoded-format (AudioFormat. AudioFormat$Encoding/
PCM_SIGNED ...)
      line-info (DataLine$Info. SourceDataLine decoded-format)
      decoded-stream (AudioSystem/getAudioInputStream decoded-format
stream)
      line (AudioSystem/getLine line-info)
      buffer (byte-array (* 1024 4))]
  (pprint line)
  (.open line decoded-format)
  (.start line)
  ...)

This works fine on Mac OSX.  The pprint gives

#<MixerSourceLine com.sun.media.sound.MixerSourceLine@56101751>

When I run it in windows I get

Can't call public method of non-public class: public void
com.sun.media.sound.AbstractDataLine.open(javax.sound.sampled.AudioFormat)
throws javax.sound.sampled.LineUnavailableException
  [Thrown class java.lang.IllegalArgumentException]

This time the pprint gives

 #<DirectSDL com.sun.media.sound.DirectAudioDevice$DirectSDL@173bb67>

The problem is that getLine on windows returns DirectSDL which is a
private inner class of DirectAudioDevice.  I tried casting it to
SourceDataLine which is the type I need (which is a literal
translation of equivalent java code I'm following) by doing

      line (cast SourceDataLine (AudioSystem/getLine line-info))

But that didn't work.  I had to declare the type like so

      #^SourceDataLine line (AudioSystem/getLine line-info)

My question is what is the difference between casting and type
declaration?  Why does one work and not the other in this case?  In
general, when is one used over the other?

I found a related post from Rich 
http://www.mail-archive.com/clojure@googlegroups.com/msg13283.html
where he says the let (without type declaration I assume) should allow
the compiler to infer the type.

Thanks

Kartik

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to