Package com.sun.j3d.audioengines.headspace

Source Code of com.sun.j3d.audioengines.headspace.AudioContainerInputStream

/*      */ package com.sun.j3d.audioengines.headspace;
/*      */
/*      */ import java.io.ByteArrayInputStream;
/*      */ import java.io.ByteArrayOutputStream;
/*      */ import java.io.DataInputStream;
/*      */ import java.io.DataOutputStream;
/*      */ import java.io.IOException;
/*      */ import java.io.InputStream;
/*      */ import java.io.PrintStream;
/*      */ import java.util.ArrayList;
/*      */
/*      */ class AudioContainerInputStream extends MediaInputStream
/*      */ {
/*   53 */   protected boolean DEBUG = false;
/*      */   static final int MIDI_MAGIC = 1297377380;
/*      */   static final int AIFF_MAGIC = 1179603533;
/*      */   static final int RMF_MAGIC = 1230128474;
/*      */   static final int RIFF_MAGIC = 1380533830;
/*      */   static final int WAV_MAGIC = 1463899717;
/*      */   static final int AU_SUN_MAGIC = 779316836;
/*      */   static final int AU_DEC_MAGIC = 779314176;
/*      */   static final int AU_SUN_INV_MAGIC = 1684960046;
/*      */   static final int AU_DEC_INV_MAGIC = 6583086;
/*   71 */   static final int[] ULAW_TABH = { 130, 134, 138, 142, 146, 150, 154, 158, 162, 166, 170, 174, 178, 182, 186, 190, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 248, 249, 249, 249, 249, 250, 250, 250, 250, 251, 251, 251, 251, 252, 252, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 126, 121, 117, 113, 109, 105, 101, 97, 93, 89, 85, 81, 77, 73, 69, 65, 62, 60, 58, 56, 54, 52, 50, 48, 46, 44, 42, 40, 38, 36, 34, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 14, 13, 13, 12, 12, 11, 11, 10, 10, 9, 9, 8, 8, 7, 7, 7, 6, 6, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
/*      */
/*  107 */   static final int[] ULAW_TABL = { 0, 4, 8, 12, 17, 21, 25, 29, 33, 38, 42, 46, 50, 55, 59, 63, 66, 68, 71, 73, 75, 77, 79, 81, 83, 85, 88, 90, 92, 94, 96, 98, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 243, 244, 180, 53, 181, 54, 182, 55, 184, 56, 185, 57, 186, 58, 187, 59, 188, 60, 157, 221, 29, 94, 158, 222, 30, 95, 159, 223, 31, 96, 160, 224, 32, 97, 145, 177, 209, 241, 17, 50, 82, 114, 146, 178, 210, 242, 18, 51, 83, 115, 139, 155, 171, 187, 203, 219, 235, 251, 11, 28, 44, 60, 76, 92, 108, 124, 136, 144, 152, 160, 168, 176, 184, 192, 200, 208, 216, 224, 232, 240, 248, 0, 0, 252, 248, 244, 239, 235, 231, 227, 223, 218, 214, 210, 206, 201, 197, 193, 190, 188, 185, 183, 181, 179, 177, 175, 173, 171, 168, 166, 164, 162, 160, 158, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 13, 12, 76, 203, 75, 202, 74, 201, 72, 200, 71, 199, 70, 198, 69, 197, 68, 196, 99, 35, 227, 162, 98, 34, 226, 161, 97, 33, 225, 160, 96, 32, 224, 159, 111, 79, 47, 15, 239, 206, 174, 142, 110, 78, 46, 14, 238, 205, 173, 141, 117, 101, 85, 69, 53, 37, 21, 5, 245, 228, 212, 196, 180, 164, 148, 132, 120, 112, 104, 96, 88, 80, 72, 64, 56, 48, 40, 32, 24, 16, 8, 0 };
/*      */   AudioFormat f;
/*      */   AudioFormat fout;
/*  153 */   boolean streamFinished = false;
/*      */
/*  157 */   boolean processBytes = false;
/*  158 */   boolean swapBytes = false;
/*  159 */   boolean convertFromUlaw = false;
/*  160 */   boolean convertUnsigned = false;
/*  161 */   boolean mixerBigEndian = false;
/*      */   InputStream stream;
/*      */   InputStream streamSrc;
/*  173 */   ArrayList sharedInputContainers = null;
/*  174 */   byte[] cachedBuffer = null;
/*      */   static final int MAX_HEADER_SIZE = 12;
/*  181 */   protected int totalBytes = 0;
/*      */
/*  184 */   protected int totalFrames = 0;
/*      */
/*  187 */   protected int currentFrame = 0;
/*      */
/*  190 */   protected int headerSize = 0;
/*      */
/*  194 */   float filterCutoffFreq = 44100.0F;
/*  195 */   boolean filterFlag = false;
/*      */
/*      */   protected AudioContainerInputStream(byte[] bytes, InputStream in)
/*      */     throws IOException, BadAudioHeaderException
/*      */   {
/*  211 */     super(in);
/*  212 */     this.stream = in;
/*  213 */     this.streamSrc = in;
/*      */
/*  215 */     AudioFormat format = readFormat(bytes);
/*  216 */     setFormat(format);
/*  217 */     setupConversions();
/*      */   }
/*      */
/*      */   AudioContainerInputStream(AudioFormat format, InputStream in)
/*      */     throws BadAudioHeaderException
/*      */   {
/*  233 */     super(in);
/*  234 */     this.stream = in;
/*  235 */     this.streamSrc = in;
/*  236 */     if ((format == null) || (format.getEncoding() == null)) {
/*  237 */       throw new BadAudioHeaderException("invalid format object");
/*      */     }
/*  239 */     setFormat(format);
/*  240 */     setupConversions();
/*      */   }
/*      */
/*      */   protected AudioContainerInputStream(AudioContainerInputStream is)
/*      */   {
/*  245 */     super(is.streamSrc);
/*  246 */     this.f = is.f;
/*  247 */     this.fout = is.fout;
/*  248 */     this.streamFinished = is.streamFinished;
/*  249 */     this.processBytes = is.processBytes;
/*  250 */     this.swapBytes = is.swapBytes;
/*  251 */     this.convertFromUlaw = is.convertFromUlaw;
/*  252 */     this.mixerBigEndian = is.mixerBigEndian;
/*  253 */     this.stream = is.stream;
/*  254 */     this.streamSrc = is.streamSrc;
/*  255 */     this.totalBytes = is.totalBytes;
/*  256 */     this.totalFrames = is.totalFrames;
/*  257 */     this.currentFrame = is.currentFrame;
/*  258 */     this.headerSize = is.headerSize;
/*  259 */     this.filterCutoffFreq = is.filterCutoffFreq;
/*  260 */     this.filterFlag = is.filterFlag;
/*  261 */     if (is.sharedInputContainers == null) {
/*  262 */       is.sharedInputContainers = new ArrayList();
/*  263 */       is.sharedInputContainers.add(is);
/*      */     }
/*  265 */     is.sharedInputContainers.add(this);
/*  266 */     this.sharedInputContainers = is.sharedInputContainers;
/*      */   }
/*      */
/*      */   protected void setFormat(Format theFormat)
/*      */   {
/*  271 */     if ((theFormat instanceof AudioFormat))
/*      */     {
/*  274 */       this.f = ((AudioFormat)theFormat);
/*  275 */       this.totalFrames = (getTotalBytes() / (this.f.getChannels() * this.f.getSampleSize()));
/*      */     }
/*  278 */     else if (theFormat != null) {
/*  279 */       System.out.println("not a valid audio format!");
/*      */     }
/*      */   }
/*      */
/*      */   protected void setupConversions()
/*      */     throws BadAudioHeaderException
/*      */   {
/*  287 */     if (this.f == null) return;
/*      */
/*  291 */     if ((!"JAUDIO_LINEAR".equals(this.f.getEncoding())) && (!"JAUDIO_G711_ULAW".equals(this.f.getEncoding()))) {
/*  292 */       throw new BadAudioHeaderException("Unsupported audio encoding: " + this.f.getEncoding());
/*      */     }
/*      */
/*      */     try
/*      */     {
/*  299 */       HaeMixer mixer = HaeDevice.getSystemMixer();
/*  300 */       if (mixer != null)
/*  301 */         this.mixerBigEndian = mixer.isBigEndian();
/*      */     } catch (HaeException e) {
/*  303 */       throw new BadAudioHeaderException("Mixer not initialized");
/*      */     }
/*      */
/*  306 */     if (this.f.isBigEndian() == this.mixerBigEndian)
/*  307 */       this.swapBytes = false;
/*      */     else {
/*  309 */       this.swapBytes = (this.f.getSampleSize() != 1);
/*      */     }
/*      */
/*  315 */     if ((this.f.isSigned()) && (this.f.getEncoding() != null) && (this.f.getSampleSize() == 1) && (this.f.getEncoding().equals("JAUDIO_LINEAR")))
/*      */     {
/*  318 */       this.convertUnsigned = true;
/*      */     }
/*      */
/*  323 */     if (this.f.getEncoding().equals("JAUDIO_G711_ULAW"))
/*      */     {
/*  327 */       if (this.f.getChannels() != 1) {
/*  328 */         throw new BadAudioHeaderException("Stereo ulaw");
/*      */       }
/*  330 */       this.convertFromUlaw = true;
/*      */     }
/*      */
/*  333 */     if ((this.swapBytes) || (this.convertUnsigned) || (this.convertFromUlaw)) {
/*  334 */       this.processBytes = true;
/*      */
/*  337 */       this.fout = new AudioFormat(this.f.getSampleRate(), this.convertFromUlaw ? "JAUDIO_LINEAR" : this.f.getEncoding(), this.convertFromUlaw ? 2 : this.f.getSampleSize(), this.f.getSamplePerUnit(), this.f.getChannels(), this.mixerBigEndian, this.convertUnsigned ? false : this.f.isSigned());
/*      */     }
/*      */     else
/*      */     {
/*  341 */       this.fout = this.f;
/*      */     }
/*  343 */     if (this.DEBUG) {
/*  344 */       System.out.println("format conversions: processBytes: " + this.processBytes + " swapBytes: " + this.swapBytes + "  convertUnsigned: " + this.convertUnsigned + " convertFromUlaw: " + this.convertFromUlaw);
/*  345 */       System.out.println("input format: " + this.f.toString());
/*  346 */       System.out.println("output format: " + this.fout.toString());
/*      */     }
/*      */   }
/*      */
/*      */   int getConvertedData(byte[] data, int frames)
/*      */     throws IOException
/*      */   {
/*  360 */     if (this.f == null) {
/*  361 */       return 0;
/*      */     }
/*      */
/*  365 */     if ((data == null) || (frames <= 0)) {
/*  366 */       return 0;
/*      */     }
/*      */
/*  371 */     int inputSampleFrameSize = this.f.getSampleSize() * this.f.getChannels();
/*  372 */     int outputSampleFrameSize = this.fout.getSampleSize() * this.fout.getChannels();
/*      */
/*  374 */     if (frames * outputSampleFrameSize > data.length) {
/*  375 */       frames = data.length / outputSampleFrameSize;
/*      */     }
/*      */
/*  378 */     int audioSize = frames * outputSampleFrameSize;
/*  379 */     int bytesLeft = audioSize;
/*  380 */     int offset = 0;
/*      */
/*  386 */     if (this.convertFromUlaw == true) {
/*  387 */       offset = audioSize / 2;
/*  388 */       bytesLeft /= 2;
/*      */     }
/*      */
/*  391 */     int bytesRead = 0;
/*  392 */     int totalBytesRead = 0;
/*      */     do
/*      */     {
/*  397 */       bytesRead = this.stream.read(data, offset, bytesLeft);
/*  398 */       if (bytesRead <= 0)
/*      */       {
/*      */         break;
/*      */       }
/*  402 */       totalBytesRead += bytesRead;
/*  403 */       offset += bytesRead;
/*  404 */       bytesLeft -= bytesRead;
/*  405 */     }while ((bytesLeft != 0) && (this.stream.available() != 0));
/*      */
/*  409 */     if (bytesRead == -1) {
/*  410 */       this.streamFinished = true;
/*      */     }
/*      */
/*  413 */     if (totalBytesRead == 0) {
/*  414 */       return 0;
/*      */     }
/*      */
/*  417 */     if (this.processBytes)
/*      */     {
/*  419 */       int byteCount = 0;
/*      */
/*  422 */       if (this.swapBytes)
/*      */       {
/*  424 */         while (byteCount < audioSize)
/*      */         {
/*  426 */           byte firstByte = data[byteCount];
/*  427 */           byte secondByte = data[(byteCount + 1)];
/*      */
/*  432 */           if (this.convertUnsigned) {
/*  433 */             firstByte = (byte)(firstByte ^ 0x80);
/*  434 */             secondByte = (byte)(secondByte ^ 0x80);
/*      */           }
/*      */
/*  448 */           data[byteCount] = secondByte;
/*  449 */           data[(byteCount + 1)] = firstByte;
/*      */
/*  452 */           byteCount += 2;
/*      */         }
/*      */
/*      */       }
/*      */
/*  459 */       if (this.convertFromUlaw)
/*      */       {
/*  463 */         boolean bigEOut = this.mixerBigEndian;
/*  464 */         int[] lTab = ULAW_TABL;
/*  465 */         int[] hTab = ULAW_TABH;
/*  466 */         offset = audioSize / 2;
/*      */
/*  468 */         while (offset < audioSize)
/*      */         {
/*  470 */           data[byteCount] = (bigEOut ? (byte)hTab[(data[offset] & 0xFF)] : (byte)lTab[(data[offset] & 0xFF)]);
/*      */
/*  473 */           data[(byteCount + 1)] = (bigEOut ? (byte)lTab[(data[offset] & 0xFF)] : (byte)hTab[(data[offset] & 0xFF)]);
/*      */
/*  478 */           byteCount += 2;
/*  479 */           offset++;
/*      */         }
/*      */
/*      */       }
/*  485 */       else if (this.convertUnsigned)
/*      */       {
/*  487 */         while (byteCount < audioSize)
/*      */         {
/*  489 */           byte tempByte = data[byteCount];
/*      */
/*  493 */           data[byteCount] = ((byte)(tempByte ^ 0x80));
/*      */
/*  502 */           byteCount++;
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */
/*  511 */     int framesRead = totalBytesRead / inputSampleFrameSize;
/*  512 */     updateCurrentFrame(framesRead);
/*      */
/*  514 */     if (this.filterFlag) {
/*  515 */       slopeData(data);
/*      */     }
/*  517 */     return framesRead;
/*      */   }
/*      */
/*      */   void slopeData(byte[] data)
/*      */   {
/*  522 */     int numChannels = this.fout.getChannels();
/*  523 */     int sampleRate = this.fout.getSampleRate();
/*  524 */     float fSampleRate = sampleRate / 2.0F;
/*  525 */     if (numChannels > 1)
/*      */     {
/*  527 */       if (this.DEBUG) {
/*  528 */         System.out.println("slopeData() number channels > 1");
/*      */       }
/*  530 */       return;
/*      */     }
/*  532 */     if (this.filterCutoffFreq >= fSampleRate)
/*      */     {
/*  534 */       if (this.DEBUG) {
/*  535 */         System.out.println("slopeData() freqCutoff " + this.filterCutoffFreq + " higher than effective sample rate " + fSampleRate);
/*      */       }
/*      */
/*  538 */       return;
/*      */     }
/*  540 */     if (this.filterCutoffFreq <= 20.0D) {
/*  541 */       if (this.DEBUG) {
/*  542 */         System.out.println("slopeData() freqCutoff is below hearing");
/*      */       }
/*  544 */       return;
/*      */     }
/*      */
/*  547 */     float lowFreq = fSampleRate;
/*  548 */     int offset = 1;
/*  549 */     int sampleSize = this.fout.getSampleSize();
/*  550 */     int delta = 0;
/*      */
/*  553 */     while (lowFreq > 20.0F) {
/*  554 */       lowFreq = fSampleRate / (offset + 1);
/*  555 */       if (this.filterCutoffFreq >= lowFreq)
/*      */       {
/*  558 */         int length = data.length;
/*  559 */         if (this.DEBUG) {
/*  560 */           System.out.println("slopeData(), offset chosen = " + offset);
/*  561 */           System.out.println("              sampleSize = " + sampleSize + ", numChannels = " + numChannels);
/*      */
/*  563 */           if (length > 2) {
/*  564 */             System.out.println("              data[] = " + data[0] + ", " + data[1] + ",...," + data[(length - 2)] + ", " + data[(length - 1)]);
/*      */           }
/*      */         }
/*  567 */         int offsetCounter = 0;
/*  568 */         if (this.DEBUG) {
/*  569 */           System.out.println("slopeData(): Loop - offset, count = " + offset + ", " + (length - 2 * (offset + 1)) + "  ***************************");
/*      */         }
/*      */
/*  572 */         int dataInt = 0;
/*  573 */         for (int byteCount = 0; byteCount < length - 2 * (offset + 1);
/*  574 */           byteCount += 2)
/*      */         {
/*  576 */           if ((offsetCounter > 0) && (offsetCounter <= offset)) {
/*  577 */             if (this.DEBUG) {
/*  578 */               System.out.println("slopeData(): old value " + byteCount + " = " + Integer.toHexString(data[byteCount]) + ", " + Integer.toHexString(data[(byteCount + 1)]));
/*      */             }
/*      */
/*  606 */             dataInt += delta;
/*  607 */             if (this.DEBUG) {
/*  608 */               System.out.println("slopeData(): delta added to int " + Integer.toHexString(delta) + ", " + Integer.toHexString(dataInt));
/*      */             }
/*      */
/*  612 */             data[byteCount] = ((byte)(dataInt >>> 8));
/*  613 */             data[(byteCount + 1)] = ((byte)(dataInt & 0xFF));
/*      */           }
/*      */           else {
/*  616 */             if (this.DEBUG) {
/*  617 */               System.out.println("slopeData(): unchanged value " + byteCount + " = " + Integer.toHexString(data[byteCount]) + ", " + Integer.toHexString(data[(byteCount + 1)]));
/*      */             }
/*      */
/*  630 */             int dataLeft = data[byteCount];
/*  631 */             dataLeft = dataLeft << 8 | data[(byteCount + 1)] & 0xFF;
/*      */
/*  633 */             if (this.DEBUG) {
/*  634 */               System.out.println("slopeData(): data left " + Integer.toHexString(dataLeft));
/*      */             }
/*      */
/*  645 */             int dataRight = data[(byteCount + 2 * (offset + 1))];
/*  646 */             dataRight = dataRight << 8 | data[(byteCount + 2 * (offset + 1) + 1)] & 0xFF;
/*      */
/*  648 */             if (this.DEBUG) {
/*  649 */               System.out.println("slopeData(): data right " + Integer.toHexString(dataRight));
/*      */             }
/*      */
/*  653 */             delta = (int)(0.5F + (dataRight - dataLeft) / (offset + 1));
/*      */
/*  655 */             dataInt = dataLeft;
/*  656 */             if (this.DEBUG) {
/*  657 */               System.out.println("slopeData(): delta " + Integer.toHexString(delta));
/*      */             }
/*      */
/*  660 */             offsetCounter = 0;
/*      */           }
/*  662 */           offsetCounter++;
/*  663 */           if (this.DEBUG) {
/*  664 */             System.out.println("slopeData(): new value " + byteCount + " = " + Integer.toHexString(data[byteCount]) + ", " + Integer.toHexString(data[(byteCount + 1)]));
/*      */           }
/*      */
/*      */         }
/*      */
/*  669 */         break;
/*      */       }
/*  671 */       offset++;
/*      */     }
/*      */   }
/*      */
/*      */   void setFiltering(boolean onFlag, float cutoffFreq)
/*      */   {
/*  677 */     if (this.DEBUG) {
/*  678 */       System.out.println("setFiltering(" + onFlag + ", " + cutoffFreq + ")");
/*      */     }
/*  680 */     this.filterFlag = onFlag;
/*  681 */     if (onFlag)
/*  682 */       this.filterCutoffFreq = cutoffFreq;
/*      */   }
/*      */
/*      */   public Format[] getFormat()
/*      */   {
/*  689 */     Format[] format = { this.f };
/*  690 */     return format;
/*      */   }
/*      */
/*      */   int getTotalBytes()
/*      */   {
/*  696 */     return this.totalBytes;
/*      */   }
/*      */
/*      */   int getTotalFrames()
/*      */   {
/*  701 */     return this.totalFrames;
/*      */   }
/*      */
/*      */   int getCurrentFrame()
/*      */   {
/*  706 */     return this.currentFrame;
/*      */   }
/*      */
/*      */   int getRemainingFrames()
/*      */   {
/*  711 */     return this.totalFrames - this.currentFrame;
/*      */   }
/*      */
/*      */   void setCurrentFrame(int currentFrame)
/*      */   {
/*  720 */     this.currentFrame = currentFrame;
/*      */
/*  722 */     if (currentFrame < getTotalFrames())
/*  723 */       this.streamFinished = false;
/*      */   }
/*      */
/*      */   protected void updateCurrentFrame(int delta)
/*      */   {
/*  729 */     this.currentFrame += delta;
/*  730 */     int frames = getTotalFrames();
/*      */
/*  732 */     if ((frames > 0) && (this.currentFrame >= frames))
/*  733 */       this.streamFinished = true;
/*      */   }
/*      */
/*      */   byte[] getBytes()
/*      */   {
/*  748 */     if (!(this.stream instanceof ByteArrayInputStream)) return null;
/*      */
/*  750 */     ByteArrayInputStream bais = (ByteArrayInputStream)this.stream;
/*  751 */     byte[] buffer = null;
/*      */
/*  753 */     synchronized (this.stream)
/*      */     {
/*  755 */       int initAvail = bais.available();
/*  756 */       bais.reset();
/*  757 */       int totalAvail = bais.available();
/*  758 */       buffer = new byte[totalAvail];
/*  759 */       bais.read(buffer, 0, buffer.length);
/*  760 */       bais.reset();
/*  761 */       bais.skip(totalAvail - initAvail);
/*      */     }
/*      */
/*  764 */     return buffer;
/*      */   }
/*      */
/*      */   boolean setData()
/*      */     throws IOException
/*      */   {
/*  790 */     if (this.sharedInputContainers != null)
/*      */     {
/*  792 */       for (int i = this.sharedInputContainers.size() - 1; i >= 0; i--) {
/*  793 */         AudioContainerInputStream is = (AudioContainerInputStream)this.sharedInputContainers.get(i);
/*  794 */         if (is.cachedBuffer != null)
/*      */         {
/*  796 */           this.cachedBuffer = is.cachedBuffer;
/*  797 */           this.stream = new ByteArrayInputStream(this.cachedBuffer);
/*  798 */           return true;
/*      */         }
/*      */
/*      */       }
/*      */
/*      */     }
/*      */
/*  805 */     return this.totalBytes > 0 ? readTotalBytes() : readAllBytes();
/*      */   }
/*      */
/*      */   boolean readAllBytes()
/*      */     throws IOException
/*      */   {
/*  813 */     ByteArrayOutputStream ba = new ByteArrayOutputStream();
/*  814 */     DataOutputStream dos = new DataOutputStream(ba);
/*  815 */     int readCount = 2048;
/*  816 */     byte[] tmp = new byte[readCount];
/*  817 */     int num = 0;
/*  818 */     int readByte = 0;
/*      */
/*  820 */     if ((this.stream instanceof ByteArrayInputStream))
/*  821 */       return true;
/*      */     try
/*      */     {
/*      */       while (true)
/*      */       {
/*  826 */         readByte = this.in.read(tmp, 0, readCount);
/*  827 */         if (readByte == -1) {
/*  828 */           if (num != 0) break;
/*  829 */           this.totalBytes = 0;
/*  830 */           return false;
/*      */         }
/*      */
/*  835 */         dos.write(tmp, 0, readByte);
/*  836 */         num += readByte;
/*  837 */         Thread.currentThread(); Thread.yield();
/*      */       }
/*      */
/*  840 */       this.in.close();
/*  841 */       this.cachedBuffer = ba.toByteArray();
/*      */     }
/*      */     catch (IOException e) {
/*  844 */       e.printStackTrace();
/*  845 */       this.totalBytes = 0;
/*  846 */       this.cachedBuffer = null;
/*  847 */       throw new IOException(e.getMessage());
/*      */     }
/*      */
/*  850 */     this.totalBytes = num;
/*  851 */     this.stream = new ByteArrayInputStream(this.cachedBuffer);
/*  852 */     return true;
/*      */   }
/*      */
/*      */   boolean readTotalBytes()
/*      */     throws IOException
/*      */   {
/*  863 */     this.cachedBuffer = new byte[this.totalBytes];
/*      */     try {
/*  865 */       int gotbytes = readFully(this.cachedBuffer, 0, this.cachedBuffer.length);
/*  866 */       close();
/*      */     } catch (IOException e) {
/*  868 */       this.cachedBuffer = null;
/*  869 */       throw e;
/*      */     }
/*      */
/*  872 */     this.stream = new ByteArrayInputStream(this.cachedBuffer);
/*  873 */     return true;
/*      */   }
/*      */
/*      */   public long getDataPos()
/*      */   {
/*  888 */     return 0L;
/*      */   }
/*      */
/*      */   boolean streamIsFinished() {
/*  892 */     return this.streamFinished;
/*      */   }
/*      */
/*      */   protected AudioFormat readFormat(byte[] bytes)
/*      */     throws BadAudioHeaderException, IOException
/*      */   {
/*  912 */     throw new BadAudioHeaderException("cannot read format in ACIS base class");
/*      */   }
/*      */
/*      */   static AudioContainerInputStream getStream(InputStream in)
/*      */     throws IOException, BadAudioHeaderException
/*      */   {
/*  934 */     if ((in instanceof AudioContainerInputStream)) {
/*  935 */       return (AudioContainerInputStream)in;
/*      */     }
/*      */
/*  938 */     if ((in instanceof AudioStream)) {
/*  939 */       return ((AudioStream)in).acis;
/*      */     }
/*  941 */     if ((in instanceof AudioDataStream)) {
/*  942 */       return ((AudioDataStream)in).acis;
/*      */     }
/*  944 */     if ((in instanceof NativeAudioStream)) {
/*  945 */       return ((NativeAudioStream)in).acis;
/*      */     }
/*      */
/*  958 */     in.mark(12);
/*  959 */     byte[] bytes = new byte[4];
/*      */
/*  964 */     int bytesRead = in.read(bytes);
/*      */
/*  967 */     int firstInt = (bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + (bytes[3] << 0);
/*      */     AudioContainerInputStream acis;
/*  975 */     switch (firstInt)
/*      */     {
/*      */     case 1297377380:
/*  978 */       acis = new AudioMidiInputStream(bytes, in);
/*  979 */       break;
/*      */     case 1179603533:
/*  982 */       acis = new AudioAiffInputStream(bytes, in);
/*  983 */       break;
/*      */     case 1230128474:
/*  986 */       acis = new AudioRmfInputStream(bytes, in);
/*  987 */       break;
/*      */     case 6583086:
/*      */     case 779314176:
/*      */     case 779316836:
/*      */     case 1684960046:
/*  993 */       acis = new AudioAuInputStream(bytes, in);
/*  994 */       break;
/*      */     case 1380533830:
/*  997 */       byte[] moreBytes = new byte[12];
/*  998 */       System.arraycopy(bytes, 0, moreBytes, 0, bytes.length);
/*  999 */       bytesRead += in.read(moreBytes, bytesRead, 8);
/* 1000 */       int nextInt = (moreBytes[8] << 24) + (moreBytes[9] << 16) + (moreBytes[10] << 8) + (moreBytes[11] << 0);
/*      */
/* 1002 */       if (nextInt == 1463899717) {
/* 1003 */         acis = new AudioWavInputStream(moreBytes, in);
/*      */       }
/*      */       else {
/* 1006 */         bytes = moreBytes;
/*      */       }
/*      */       break;
/*      */     default:
/*      */       try
/*      */       {
/* 1012 */         in.reset();
/* 1013 */         throw new BadAudioHeaderException("Unknown header");
/*      */       }
/*      */       catch (IOException e) {
/* 1016 */         throw new BadAudioHeaderException("Unknownheader", bytes);
/*      */       }
/*      */     }
/*      */     AudioContainerInputStream acis;
/* 1021 */     return acis;
/*      */   }
/*      */
/*      */   byte[] ulawToLinear(byte[] ulaw)
/*      */   {
/* 1029 */     byte[] linear = new byte[ulaw.length * 2];
/* 1030 */     int i = 0; for (int j = 0; i < ulaw.length; j += 2) {
/* 1031 */       linear[j] = ((byte)ULAW_TABH[(ulaw[i] & 0xFF)]);
/* 1032 */       linear[(j + 1)] = ((byte)ULAW_TABL[(ulaw[i] & 0xFF)]);
/*      */
/* 1030 */       i++;
/*      */     }
/*      */
/* 1034 */     return linear;
/*      */   }
/*      */
/*      */   AudioFormat getInputFormat()
/*      */   {
/* 1042 */     return this.f;
/*      */   }
/*      */
/*      */   AudioFormat getOutputFormat()
/*      */   {
/* 1048 */     return this.fout;
/*      */   }
/*      */
/*      */   protected int rllong(DataInputStream dis)
/*      */     throws IOException
/*      */   {
/* 1069 */     int i = 0;
/*      */
/* 1071 */     i = dis.readInt();
/*      */
/* 1073 */     int b1 = (i & 0xFF) << 24;
/* 1074 */     int b2 = (i & 0xFF00) << 8;
/* 1075 */     int b3 = (i & 0xFF0000) >> 8;
/* 1076 */     int b4 = (i & 0xFF000000) >>> 24;
/*      */
/* 1078 */     i = b1 | b2 | b3 | b4;
/*      */
/* 1080 */     return i;
/*      */   }
/*      */
/*      */   protected short rlshort(DataInputStream dis)
/*      */     throws IOException
/*      */   {
/* 1093 */     short s = 0;
/*      */
/* 1096 */     s = dis.readShort();
/*      */
/* 1098 */     short high = (short)((s & 0xFF) << 8);
/* 1099 */     short low = (short)((s & 0xFF00) >>> 8);
/*      */
/* 1101 */     s = (short)(high | low);
/*      */
/* 1103 */     return s;
/*      */   }
/*      */
/*      */   void setVerbose(boolean v)
/*      */   {
/* 1110 */     this.DEBUG = v;
/*      */   }
/*      */
/*      */   AudioContainerInputStream cloneInputStream() {
/* 1114 */     return new AudioContainerInputStream(this);
/*      */   }
/*      */
/*      */   boolean resetAudioInputStream() {
/* 1118 */     if (this.cachedBuffer != null) {
/* 1119 */       this.stream = new ByteArrayInputStream(this.cachedBuffer);
/* 1120 */       return true;
/*      */     }
/*      */
/* 1123 */     if (this.sharedInputContainers != null)
/*      */     {
/* 1125 */       for (int i = this.sharedInputContainers.size() - 1; i >= 0; i--) {
/* 1126 */         AudioContainerInputStream is = (AudioContainerInputStream)this.sharedInputContainers.get(i);
/* 1127 */         if (is.cachedBuffer != null)
/*      */         {
/* 1129 */           this.cachedBuffer = is.cachedBuffer;
/* 1130 */           this.stream = new ByteArrayInputStream(this.cachedBuffer);
/* 1131 */           return true;
/*      */         }
/*      */       }
/*      */     }
/* 1135 */     return false;
/*      */   }
/*      */ }

/* Location:           Z:\System\Library\Java\Extensions\j3daudio.jar
* Qualified Name:     com.sun.j3d.audioengines.headspace.AudioContainerInputStream
* JD-Core Version:    0.6.2
*/
TOP

Related Classes of com.sun.j3d.audioengines.headspace.AudioContainerInputStream

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.