Package javax.sound.sampled

Examples of javax.sound.sampled.SourceDataLine


      System.out.println("  Sources (" + sLineInfos.length + "):");
      for(int k=0; k<sLineInfos.length; k++)
      {
        try
        {
          SourceDataLine sLine = (SourceDataLine)mixer.getLine(sLineInfos[k]);
          System.out.println("   Line: " + sLine.getLineInfo() + "\t(Name: " + sLine + ")");
        }
        catch (LineUnavailableException e)
        {
          e.printStackTrace();
        }
View Full Code Here


    try {
      ByteArrayOutputStream baOut = new ByteArrayOutputStream();
      TargetDataLine tl = (TargetDataLine) AudioSystem.getLine(info);
      tl.open(af);
      tl.start();
      SourceDataLine sl = (SourceDataLine) AudioSystem.getLine(sinfo); // Neu:
                                        // Line
                                        // f�r
                                        // Tonausgabe
      sl.open(af); // �ffnen
      sl.start(); // starten
      int numBytesRead;
      int durchlauf = 0;
      byte[] ba = new byte[256]; // definieren und gleich einmal
                    // initialisieren.
      while (durchlauf < 1000) {
        durchlauf++;
        numBytesRead = tl.read(ba, 0, ba.length);
        baOut.write(ba, 0, numBytesRead);
        sl.write(ba, 0, numBytesRead); // in Tonausgabe schreiben
      }
      baOut.close(); // close() ist wichtig, k�nnten noch Daten gepuffert
              // sein
      tl.stop(); // eingabe stoppen
      sl.stop(); // ausgabe stoppen
      tl.close(); // eingabe schliessen
      sl.close(); // ausgabe schliessen
      ba = baOut.toByteArray(); // ba liegt brach ruhig wieder verwenden
      ByteArrayInputStream baIn = new ByteArrayInputStream(ba);
      AudioInputStream stream = new AudioInputStream(baIn, af, ba.length
          / af.getFrameSize());
       AudioSystem.write(stream, AudioFileFormat.Type.WAVE,outputFile);
View Full Code Here

      try
      {
        audioInputStream = AudioSystem.getAudioInputStream(soundFile);
        AudioFormat audioFormat = audioInputStream.getFormat();
        SourceDataLine line = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, audioFormat);
        line = (SourceDataLine) AudioSystem.getLine(info);
        line.open(audioFormat);
        line.start();

        int nBytesRead = 0;
        byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
        while (nBytesRead != -1)
        {
          try
          {
            nBytesRead = audioInputStream.read(abData, 0, abData.length);
          }
          catch (IOException e)
          {
            e.printStackTrace();
          }
          if (nBytesRead >= 0)
          {
            int nBytesWritten = line.write(abData, 0, nBytesRead);
            if (nBytesWritten > 0)
            {
              nBytesWritten = 0;
            }
          }
        }

        line.drain();
        line.close();
      }
      catch (Exception e)
      {
        e.printStackTrace();
      }
View Full Code Here

    }

    public void run() {
        byte[] buffer = SoftAudioPusher.this.buffer;
        AudioInputStream ais = SoftAudioPusher.this.ais;
        SourceDataLine sourceDataLine = SoftAudioPusher.this.sourceDataLine;

        try {
            while (active) {
                // Read from audio source
                int count = ais.read(buffer);
                if(count < 0) break;
                // Write byte buffer to source output
                sourceDataLine.write(buffer, 0, count);
            }
        } catch (IOException e) {
            active = false;
            //e.printStackTrace();
        }
View Full Code Here

/*  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;
/*     */     }
View Full Code Here

/* 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;
/*     */
View Full Code Here

            e1.printStackTrace();
            return;
        }
        AudioFormat format = audioInputStream.getFormat();
        SourceDataLine auline = null;
        DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
        try {
            auline = (SourceDataLine) AudioSystem.getLine(info);
            auline.open(format);
        } catch (LineUnavailableException e) {
            e.printStackTrace();
            return;
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        if (auline.isControlSupported(FloatControl.Type.PAN)) {
            FloatControl pan = (FloatControl) auline
                    .getControl(FloatControl.Type.PAN);
            if (curPosition == Position.RIGHT)
                pan.setValue(1.0f);
            else if (curPosition == Position.LEFT)
                pan.setValue(-1.0f);
        }
        auline.start();
        int nBytesRead = 0;
        byte[] abData = new byte[EXTERNAL_BUFFER_SIZE];
        try {
            while (nBytesRead != -1) {
                nBytesRead = audioInputStream.read(abData, 0, abData.length);
                if (nBytesRead >= 0)
                    auline.write(abData, 0, nBytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
            return;
        } finally {
            auline.drain();
            auline.close();
        }
    }
View Full Code Here

                        ais = AudioSystem.getAudioInputStream( audioFile );
                    }

                    AudioFormat af = ais.getFormat();
                    DataLine.Info inf = new DataLine.Info( SourceDataLine.class, af );
                    SourceDataLine sdl = ( SourceDataLine ) AudioSystem.getLine( inf );
                    sdl.open( af );
                    sdl.start();
                    byte[] buf = new byte[ 65536 ];
                    for ( int n = 0; (n = ais.read( buf, 0, buf.length )) > 0; )
                    {
                        sdl.write( buf, 0, n );
                    }
                    sdl.drain();
                    sdl.close();
                }
                catch ( Exception e )
                {
                    Common.hadleErrorMessage( e, "無法播放" + audioFileString );
                }
View Full Code Here

    private ClipImpl clip;

    public ViewerAudioClip(URL url) {
        AudioFormat af = null;
        AudioInputStream ais = null;
        SourceDataLine line = null;
        try {
            ais = AudioSystem.getAudioInputStream(url);
        } catch (Exception e) {
            e.printStackTrace();
            return;
View Full Code Here

     * @throws InterruptedException
     */
    public void PlayListTest() throws LineUnavailableException, InterruptedException {

        DataLine.Info info = new DataLine.Info(SourceDataLine.class, TargetFormat);
        SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
        StreamPlayer player = StreamPlayer.create(line, "Music");
        JukeBox jukebox = JukeBox.create(player);
        jukebox.setAutoRewind(true);

        List<Resource> list = new LinkedList<>();
View Full Code Here

TOP

Related Classes of javax.sound.sampled.SourceDataLine

Copyright © 2018 www.massapicom. 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.