Java 8 SourceDataLine - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 SourceDataLine class.

This code example shows how to use the following methods:getFormat, open
        SourceDataLine loudspeakers = null;
        try { 
            DataLine.Info info = new DataLine.Info(SourceDataLine.class,
                    audioFormat);
            loudspeakers = (SourceDataLine) AudioSystem.getLine(info);
            loudspeakers.open(audioFormat);
            System.out.println("Loudspeaker format: "+loudspeakers.getFormat());
        } catch (LineUnavailableException e) {
            e.printStackTrace();
        } 
         
        // Choose an audio effect 
        InlineDataProcessor effect = new Robotiser.PhaseRemover(4096);
        //InlineDataProcessor effect = new LPCWhisperiser(20); 
 
        // Create the output thread and make it run in the background: 
        int bufferSize = SignalProcUtils.getDFTSize(fs);
        OnlineAudioEffects online = new OnlineAudioEffects(effect, microphone, loudspeakers, bufferSize);
        online.start();
         
5
CodeRank
This code example shows how to use the following methods:getBufferSize, getControl, isControlSupported, open
        DataLine.Info info = new DataLine.Info(SourceDataLine.class,
                audioFormat, AudioSystem.NOT_SPECIFIED);
        SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
 
        if (bufferSize <= 0)
            bufferSize = line.getBufferSize();
        line.open(audioFormat, bufferSize);
 
        /*-- Is Gain Control supported ? --*/ 
        if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            gainControl = (FloatControl) line
                    .getControl(FloatControl.Type.MASTER_GAIN);
        } 
        return line;
    } 
 
    /** 
     * Creates a map of properties about the current inputstream. Unlike many inputStreams, 
     * audioInputStreams have a variety of extra properties associated with them such as 
     * <pre> 
6
CodeRank
This code example shows how to use the following methods:stop, close
            throw new RuntimeException(ex);
        } 
    } 
 
    public void close() { 
        line.stop();
        line.close();
    } 
 
    public long playedMs() { 
        return line.getMicrosecondPosition();
    } 
 
    public long playedFrames() { 
        return line.getLongFramePosition();
    } 
 
    public int available() { 
        return line.available();
    } 
5
CodeRank
This code example shows how to use the following methods:flush, close
		} 
	} 
 
	public void close() 
	{ 
		sourceLine.flush();
		sourceLine.close();
	} 
} 
5
CodeRank
This code example shows how to use the following methods:flush, stop, close
            return; 
 
        tick.cancel();
        tick.purge();
 
        output.stop();
        output.flush();
        output.close();
        output = null;
    } 
 
    public void set_speed(double speed) {
        /* This engine is equipped with an automatic gear box that 
         * switches gears when the RPM becomes too high or too low.  */ 
        double new_speed = Math.abs(speed);
        double accel = new_speed - this.speed;
        this.speed = new_speed;
 
        if (accel > 0.05)
            accel = 0.05;
5
CodeRank
This code example shows how to use the following methods:start, open
      this.aesCipher = Cipher.getInstance("AES/CBC/NOPADDING");
      receiveSocket = new DatagramSocket(port);
 
      DataLine.Info info = new DataLine.Info(SourceDataLine.class, new AudioFormat(session.getFormat().getSampleRate(), session.getFormat().getSampleSize(), 2, true, true));
      line = (SourceDataLine) AudioSystem.getLine(info);
      line.open();
      line.start();
    } catch (Exception e) {
      throw new RuntimeException(e);
    } 
    secretKey = new SecretKeySpec(session.getAesKey(), "AES");
    secretKey = new SecretKeySpec(session.getAesKey(), "AES");
    keySpec = new IvParameterSpec(session.getAesIv());
 
    int frameSize = session.getFormat().getFrameSize();
    alac = AlacDecodeUtils.create_alac(session.getFormat().getSampleSize(), 2);
    alac.setSetinfo_max_samples_per_frame(frameSize);
    alac.setSetinfo_rice_historymult(session.getFormat().getRiceHistoryMult());
    alac.setSetinfo_rice_initialhistory(session.getFormat().getRiceInitialHistory());
    alac.setSetinfo_rice_kmodifier(session.getFormat().getRiceKModifier());
5
CodeRank
This code example shows how to use the following methods:getBufferSize, getFormat
  } 
 
  /** Converts a frame count to a duration in milliseconds. */ 
  private long convertFramesToMilliseconds (int frames)
  { 
    return (frames / (long)dataLine.getFormat().getSampleRate()) * 1000;
  } 
 
  /** Converts a duration in milliseconds to a frame count. */ 
  private int convertMillisecondsToFrames (long milliseconds)
  { 
    return (int)(milliseconds / dataLine.getFormat().getSampleRate());
  } 
 
  @Override public void update (LineEvent le)
  { 
    //PlayN.log().debug("update: " + le); 
  } 
 
  @Override public void loop (int count)

5
CodeRank
This code example shows how to use the following methods:start, open
			Line line = AudioSystem.getLine(getSourceLineInfo());
            if (line instanceof SourceDataLine)
            { 
         		source = (SourceDataLine)line;
                //source.open(fmt, millisecondsToBytes(fmt, 2000)); 
				source.open(fmt);
                /* 
                if (source.isControlSupported(FloatControl.Type.MASTER_GAIN)) 
                { 
					FloatControl c = (FloatControl)source.getControl(FloatControl.Type.MASTER_GAIN); 
                    c.setValue(c.getMaximum()); 
                }*/ 
                source.start();
 
            } 
        } catch (RuntimeException ex)
          { 
			  t = ex;
          } 
          catch (LinkageError ex)
5
CodeRank
This code example shows how to use the following methods:stop
     
     
 
    public void cancel() { 
        if (line != null)
            line.stop();
        exitRequested = true;
    } 
 
    public SourceDataLine getLine() {
        return line;
    } 
 
    public void run() { 
        status = Status.PLAYING;
        AudioFormat audioFormat = ais.getFormat();
        if (audioFormat.getChannels() == 1) {
            if (outputMode != MONO) { // mono -> convert to stereo
                ais = new StereoAudioInputStream(ais, outputMode);
                audioFormat = ais.getFormat();
5
CodeRank
This code example shows how to use the following methods:stop
		return clip;
	} 
 
	public void stopSound() { 
		if (clip != null) {
			clip.stop();
		} 
		isRunning = false;
	} 
 
	public boolean isVolumeSupported() { 
		return true; 
	} 
} 
4
CodeRank
See Code Examples for Java 8 SourceDataLine Methods: