Package com.sun.j3d.audioengines.javasound

Source Code of com.sun.j3d.audioengines.javasound.JSStream

/*     */ package com.sun.j3d.audioengines.javasound;
/*     */
/*     */ import javax.sound.sampled.AudioFormat;
/*     */ import javax.sound.sampled.AudioInputStream;
/*     */ import javax.sound.sampled.AudioSystem;
/*     */ import javax.sound.sampled.DataLine;
/*     */ import javax.sound.sampled.DataLine.Info;
/*     */ import javax.sound.sampled.SourceDataLine;
/*     */
/*     */ class JSStream extends JSChannel
/*     */ {
/*  32 */   SourceDataLine line = null;
/*     */
/*  35 */   SourceDataLine otherChannel = null;
/*     */
/*  39 */   SourceDataLine reverbChannel = null;
/*     */
/*     */   boolean initialize()
/*     */   {
/*  47 */     return true;
/*     */   }
/*     */
/*     */   DataLine initDataLine(AudioInputStream ais)
/*     */   {
/*  59 */     SourceDataLine line = null;
/*     */     try
/*     */     {
/*  68 */       this.audioFormat = ais.getFormat();
/*     */
/*  80 */       DataLine.Info info = new DataLine.Info(SourceDataLine.class, this.audioFormat);
/*     */
/*  82 */       line = (SourceDataLine)AudioSystem.getLine(info);
/*     */
/*  88 */       line.open(this.audioFormat);
/*     */
/*  95 */       line.start();
/*     */     }
/*     */     catch (Exception e)
/*     */     {
/* 104 */       return null;
/*     */     }
/* 106 */     return line;
/*     */   }
/*     */
/*     */   boolean reloadSample()
/*     */   {
/* 152 */     return false;
/*     */   }
/*     */
/*     */   boolean startSamples(int loopCount, float leftGain, float rightGain, int leftDelay, int rightDelay)
/*     */   {
/* 182 */     if ((this.otherChannel == null) || (this.reverbChannel == null)) {
/* 183 */       startSample(loopCount, leftGain, leftDelay);
/*     */     }
/*     */
/* 189 */     if (this.ais == null)
/*     */     {
/* 194 */       return false;
/*     */     }
/*     */
/* 198 */     SourceDataLine leftLine = this.line;
/* 199 */     SourceDataLine rightLine = this.otherChannel;
/*     */
/* 214 */     double ZERO_EPS = 0.0039D;
/* 215 */     double leftVolume = leftGain;
/* 216 */     double rightVolume = rightGain;
/*     */
/* 218 */     int nBytesRead = 0;
/* 219 */     int nBytesWrittenLeft = 0;
/* 220 */     int nBytesWrittenRight = 0;
/* 221 */     int EXTERNAL_BUFFER_SIZE = 128000;
/* 222 */     byte[] commonBuffer = new byte[EXTERNAL_BUFFER_SIZE];
/*     */
/* 227 */     this.startTime = System.currentTimeMillis();
/*     */
/* 231 */     while (nBytesRead != 1)
/*     */     {
/*     */       try
/*     */       {
/* 254 */         nBytesRead = this.ais.read(commonBuffer, 0, EXTERNAL_BUFFER_SIZE);
/* 255 */         if (nBytesRead > 0) {
/* 256 */           nBytesWrittenLeft = leftLine.write(commonBuffer, 0, nBytesRead);
/*     */         }
/*     */
/*     */       }
/*     */       catch (Exception e)
/*     */       {
/* 264 */         this.startTime = 0L;
/* 265 */         return false;
/*     */       }
/*     */     }
/* 268 */     leftLine.drain();
/*     */
/* 271 */     return true;
/*     */   }
/*     */
/*     */   boolean startSample(int loopCount, float gain, int delay)
/*     */   {
/* 292 */     boolean returnVal = startSamples(loopCount, gain, gain, 0, 0);
/* 293 */     return returnVal;
/*     */   }
/*     */
/*     */   int stopSample()
/*     */   {
/* 301 */     this.startTime = 0L;
/* 302 */     return 0;
/*     */   }
/*     */
/*     */   int stopSamples()
/*     */   {
/* 311 */     this.startTime = 0L;
/* 312 */     return 0;
/*     */   }
/*     */
/*     */   void setSampleGain(float gain)
/*     */   {
/* 320 */     if (this.line == null);
/*     */   }
/*     */
/*     */   void setSampleDelay(int delay)
/*     */   {
/*     */   }
/*     */
/*     */   void setSampleReverb(int type, boolean on)
/*     */   {
/*     */   }
/*     */
/*     */   void setSampleRate()
/*     */   {
/*     */   }
/*     */
/*     */   int getSampleRate()
/*     */   {
/* 357 */     if (this.ais == null)
/*     */     {
/* 360 */       return -1;
/*     */     }
/*     */
/* 365 */     AudioFormat audioFormat = this.ais.getFormat();
/* 366 */     float rate = audioFormat.getSampleRate();
/*     */
/* 369 */     return (int)rate;
/*     */   }
/*     */
/*     */   void scaleSampleRate(float scaleFactor)
/*     */   {
/* 380 */     if (this.ais == null)
/*     */     {
/* 383 */       return;
/*     */     }
/*     */
/* 386 */     AudioFormat audioFormat = this.ais.getFormat();
/* 387 */     float rate = audioFormat.getSampleRate();
/*     */
/* 389 */     double newRate = rate * scaleFactor;
/* 390 */     if (newRate > 48000.0D)
/* 391 */       newRate = 48000.0D;
/*     */   }
/*     */
/*     */   int pauseSamples()
/*     */   {
/* 412 */     return 0;
/*     */   }
/*     */
/*     */   int pauseSample()
/*     */   {
/* 420 */     return 0;
/*     */   }
/*     */
/*     */   int unpauseSamples()
/*     */   {
/* 428 */     return 0;
/*     */   }
/*     */
/*     */   int unpauseSample()
/*     */   {
/* 435 */     return 0;
/*     */   }
/*     */
/*     */   void setSampleFiltering(boolean filterFlag, float cutoffFreq)
/*     */   {
/*     */   }
/*     */ }

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

Related Classes of com.sun.j3d.audioengines.javasound.JSStream

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.