]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/AudioClip.java
Version 13, August 2011
[GpsPrune.git] / tim / prune / data / AudioClip.java
similarity index 52%
rename from tim/prune/data/AudioFile.java
rename to tim/prune/data/AudioClip.java
index 43089ab85570526ad833bff0dcb68283165c167b..b6dbd87948d6d60870d30d33b18dcf88a2703a86 100644 (file)
@@ -1,15 +1,16 @@
 package tim.prune.data;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import javax.sound.sampled.AudioFileFormat;
 import javax.sound.sampled.AudioSystem;
 
 /**
- * Class to represent an audio file for correlation
+ * Class to represent an audio clip for correlation
  */
-public class AudioFile extends MediaFile
+public class AudioClip extends MediaObject
 {
-       /** length of current audio file in seconds */
+       /** length of current audio clip in seconds */
        private int _lengthInSeconds = LENGTH_UNKNOWN;
 
        private static final int LENGTH_UNKNOWN = -1;
@@ -19,21 +20,36 @@ public class AudioFile extends MediaFile
         * Constructor
         * @param inFile file object
         */
-       public AudioFile(File inFile)
+       public AudioClip(File inFile)
        {
                // Timestamp is always just taken from the file modification stamp
                super(inFile, new Timestamp(inFile.lastModified()));
        }
 
        /**
-        * @return length of this audio file in seconds
+        * Constructor
+        * @param inData byte array of data
+        * @param inName name of source file
+        * @param inUrl url from which it came (or null)
+        */
+       public AudioClip(byte[] inData, String inName, String inUrl)
+       {
+               super(inData, inName, inUrl);
+       }
+
+       /**
+        * @return length of this audio clip in seconds
         */
        public int getLengthInSeconds()
        {
                if (_lengthInSeconds == LENGTH_UNKNOWN)
                {
                        try {
-                               AudioFileFormat format = AudioSystem.getAudioFileFormat(getFile());
+                               AudioFileFormat format = null;
+                               if (getFile() != null)
+                                       format = AudioSystem.getAudioFileFormat(getFile());
+                               else
+                                       format = AudioSystem.getAudioFileFormat(new ByteArrayInputStream(_data));
                                _lengthInSeconds = (int) (format.getFrameLength() / format.getFormat().getFrameRate());
                        }
                        catch (Exception e) {