javax.sound.sampled.Mixer类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.5k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中javax.sound.sampled.Mixer类的一些代码示例,展示了Mixer类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mixer类的具体详情如下:
包路径:javax.sound.sampled.Mixer
类名称:Mixer

Mixer介绍

暂无

代码示例

代码示例来源:origin: marytts/marytts

return null;
  Mixer mixer = AudioSystem.getMixer(mixerInfo);
  targetDataLine = (TargetDataLine) mixer.getLine(info);
} else {
  if (DEBUG) {
    out("AudioCommon.getTargetDataLine(): using default mixer");
  targetDataLine = (TargetDataLine) AudioSystem.getLine(info);

代码示例来源:origin: marytts/marytts

/**
 * List Mixers. Only Mixers that support either TargetDataLines or SourceDataLines are listed, depending on the value of
 * bPlayback.
 * 
 * @param bPlayback
 *            bPlayback
 */
public static void listMixersAndExit(boolean bPlayback) {
  out("Available Mixers:");
  Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
  for (int i = 0; i < aInfos.length; i++) {
    Mixer mixer = AudioSystem.getMixer(aInfos[i]);
    Line.Info lineInfo = new Line.Info(bPlayback ? SourceDataLine.class : TargetDataLine.class);
    if (mixer.isLineSupported(lineInfo)) {
      out(aInfos[i].getName());
    }
  }
  if (aInfos.length == 0) {
    out("[No mixers available]");
  }
  System.exit(0);
}

代码示例来源:origin: stackoverflow.com

soundNode.add(soundSampledNode);
md = new MediaData("Suffixes", "Sound File Suffixes", AudioSystem.getAudioFileTypes());
soundSampledNode.add(new DefaultMutableTreeNode(md));
Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
String[][] mixerData = new String[mixerInfo.length][4];
for (int ii=0; ii<mixerData.length; ii++) {
  mixerData[ii][0] = mixerInfo[ii].getName();
  mixerData[ii][1] = mixerInfo[ii].getVendor();
  mixerData[ii][2] = mixerInfo[ii].getVersion();
  mixerData[ii][3] = mixerInfo[ii].getDescription();
  Mixer mixer = AudioSystem.getMixer(mixerInfo[ii]);
  data = mergeArrays(
    "Source",
    mixer.getSourceLineInfo(),
    "Target",
    mixer.getTargetLineInfo() );
  columnNames = new String[]{ "Input/Output", "Line Info" };
  md = new MediaData(mixerInfo[ii].getName(), columnNames, data);
  Line.Info[] source = mixer.getSourceLineInfo();
  Line.Info[] target = mixer.getTargetLineInfo();
  Line[] all = new Line[source.length + target.length];
  try {

代码示例来源:origin: stackoverflow.com

Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
for (Mixer.Info info: mixerInfos){
Mixer m = AudioSystem.getMixer(info);
Line.Info[] lineInfos = m.getSourceLineInfo();
for (Line.Info lineInfo:lineInfos){
 System.out.println (info.getName()+"---"+lineInfo);
 Line line = m.getLine(lineInfo);
 System.out.println("\t-----"+line);
}
lineInfos = m.getTargetLineInfo();
for (Line.Info lineInfo:lineInfos){
 System.out.println (m+"---"+lineInfo);
 Line line = m.getLine(lineInfo);
 System.out.println("\t-----"+line);
}
}

代码示例来源:origin: marytts/marytts

/**
 * Try to get a line for output to the speaker. The line is not yet opened with a specific format.
 * 
 * @return a line object, or null if the line could not be created.
 */
public SourceDataLine getSpeakerOutputLine() {
  Object audioDescriptor = cbSpeakerOutput.getSelectedItem();
  assert audioDescriptor instanceof Mixer.Info;
  Mixer.Info mixerInfo = (Mixer.Info) audioDescriptor;
  Mixer mixer = AudioSystem.getMixer(mixerInfo);
  Line.Info[] lineInfos = mixer.getSourceLineInfo();
  assert lineInfos.length > 0 : "Strange, there are no more source lines for mixer: " + mixer;
  Line.Info lineInfo = lineInfos[0];
  SourceDataLine line = null;
  try {
    line = (SourceDataLine) mixer.getLine(lineInfo);
  } catch (LineUnavailableException e) {
    e.printStackTrace();
  }
  return line;
}

代码示例来源:origin: marytts/marytts

private void populateAudioCombo() {
  Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
    Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
    boolean hasTargetLine = false;
    Line.Info[] lines = mixer.getTargetLineInfo();
    for (int j = 0; j < lines.length; j++) {
      if (lines[j] instanceof DataLine.Info) {
    Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
    boolean hasSourceLine = false;
    Line.Info[] lines = mixer.getSourceLineInfo();
    for (int j = 0; j < lines.length; j++) {
      if (lines[j] instanceof DataLine.Info) {

代码示例来源:origin: stackoverflow.com

Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();    //get available mixers
System.out.println("Available mixers:");
for (int cnt = 0; cnt < mixerInfo.length; cnt++) {
  System.out.println(mixerInfo[cnt].getName());
Mixer mixer = AudioSystem.getMixer(mixerInfo[3]);   //getting the mixer for capture device
targetDataLine = (TargetDataLine) mixer.getLine(dataLineInfo);
targetDataLine.open(audioFormat);
targetDataLine.start();
sourceDataLine = (SourceDataLine) AudioSystem.getLine(dataLineInfo1);
sourceDataLine.open(audioFormat);
sourceDataLine.start();

代码示例来源:origin: chatty/chatty

AudioInputStream ais = AudioSystem.getAudioInputStream(file.toFile());
  clip = (Clip)mixer.getLine(info);
} else {
  clip = (Clip)AudioSystem.getLine(info);

代码示例来源:origin: cmusphinx/sphinx4

audioLine = (TargetDataLine) AudioSystem.getLine(info);
} else {
  audioLine = (TargetDataLine) selectedMixer.getLine(info);

代码示例来源:origin: openimaj/openimaj

/**
 *     Returns a Java sound line for the given device name. Use 
 *     {@link AudioDevice#deviceName} as input to this method. Use
 *     {@link AudioUtils#getDevices()} to get an {@link AudioDevice} object.
 * 
 *    @param deviceName The device name.
 *  @param af The format 
 *    @return A Java sound line.
 *     @throws LineUnavailableException 
 */
static public SourceDataLine getJavaOutputLine( final String deviceName, 
    final AudioFormat af ) 
  throws LineUnavailableException
{
  final Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
  for( final Mixer.Info info: mixerInfo )
  {
    if( info.getName().equals( deviceName ) )
    {
      final Mixer m = AudioSystem.getMixer(info);
      if( m.getSourceLineInfo().length > 0 )
        return (SourceDataLine)AudioSystem.getLine( 
            m.getSourceLineInfo()[0] );
    }
  }
  
  return null;
}

代码示例来源:origin: ddf/Minim

if ( AudioSystem.isLineSupported(info) ) 
     line = (SourceDataLine)AudioSystem.getLine(info);
     line = (SourceDataLine)outputMixer.getLine(info);

代码示例来源:origin: marytts/marytts

if (audioDescriptor instanceof Mixer.Info) {
  Mixer.Info mixerInfo = (Mixer.Info) audioDescriptor;
  Mixer mixer = AudioSystem.getMixer(mixerInfo);
  Line.Info[] lineInfos = mixer.getTargetLineInfo();
  assert lineInfos.length > 0 : "Strange, there is no more line info for mixer: " + mixer;
  Line.Info lineInfo = lineInfos[0];
  targetDataLine = (TargetDataLine) mixer.getLine(lineInfo);
} else {
  assert ((String) audioDescriptor).equals("AudioSystem");
  Line.Info lineInfo = new DataLine.Info(TargetDataLine.class, getAudioFormat());
  targetDataLine = (TargetDataLine) AudioSystem.getLine(lineInfo);

代码示例来源:origin: stackoverflow.com

javax.sound.sampled.Mixer.Info[] mixers = AudioSystem.getMixerInfo();
System.out.println("There are " + mixers.length + " mixer info objects");  
for(int i=0;i<mixers.length;i++){
  Mixer.Info mixerInfo = mixers[i];
  System.out.println("Mixer Name:"+mixerInfo.getName());
  Mixer mixer = AudioSystem.getMixer(mixerInfo);
  Line.Info[] lineinfos = mixer.getTargetLineInfo();
  for(Line.Info lineinfo : lineinfos){
    System.out.println("line:" + lineinfo);
    try {
      Line line = mixer.getLine(lineinfo);
      line.open();
      if(line.isControlSupported(FloatControl.Type.VOLUME)){

代码示例来源:origin: marytts/marytts

private static void listTargetDataLines() {
  out("Available Mixers:");
  Mixer.Info[] aInfos = AudioSystem.getMixerInfo();
  for (int i = 0; i < aInfos.length; i++) {
    Mixer mixer = AudioSystem.getMixer(aInfos[i]);
    // mixer.open();
    Line.Info[] lines = mixer.getTargetLineInfo();
    out(aInfos[i].getName());
    for (int j = 0; j < lines.length; j++) {
      out("  " + lines[j].toString());
      if (lines[j] instanceof DataLine.Info) {
        AudioFormat[] formats = ((DataLine.Info) lines[j]).getFormats();
        for (int k = 0; k < formats.length; k++) {
          out("    " + formats[k].toString());
        }
      }
    }
  }
}

代码示例来源:origin: net.sf.phat/phat-audio

private SourceDataLine getSourceDataLine(DataLine.Info dataLineInfo) {
  SourceDataLine sdl = null;
  for (Mixer.Info mi : AudioSystem.getMixerInfo()) {
    Mixer m = AudioSystem.getMixer(mi);
    if (m.isLineSupported(dataLineInfo)) {
      try {
        Line line = m.getLine(dataLineInfo);
        if (line instanceof SourceDataLine) {
          Logger.getLogger(
              PCSpeaker.class.getName()).log(Level.INFO, "Mixer={0}", m.getMixerInfo().getName());
          sdl = (SourceDataLine) line;
          break;
        }
      } catch (LineUnavailableException ex) {
        Logger.getLogger(PCSpeaker.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
  return sdl;
}

代码示例来源:origin: stackoverflow.com

JPanel gui = new JPanel(new GridLayout(0,1));
Mixer.Info[] mixers = AudioSystem.getMixerInfo();
System.out.println(
    "There are " + mixers.length + " mixer info objects");
for (Mixer.Info mixerInfo : mixers) {
  System.out.println("mixer name: " + mixerInfo.getName());
  Mixer mixer = AudioSystem.getMixer(mixerInfo);
  Line.Info[] lineInfos = mixer.getSourceLineInfo();
  for (Line.Info lineInfo : lineInfos) {
    System.out.println("  Line.Info: " + lineInfo);
    try {
      Line line = mixer.getLine(lineInfo);
      FloatControl volCtrl = (FloatControl)line.getControl(
          FloatControl.Type.MASTER_GAIN);

代码示例来源:origin: magefree/mage

public LinePool(AudioFormat audioFormat, int size, int alwaysActive) {
  this.alwaysActive = alwaysActive;
  mixer = AudioSystem.getMixer(null);
  DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, audioFormat);
  for (int i = 0; i < size; i++) {
    try {
      SourceDataLine line = (SourceDataLine) mixer.getLine(lineInfo);
      freeLines.add(line);
    } catch (LineUnavailableException e) {
      log.warn("Failed to get line from mixer", e);
    }
  }
  new Timer("Line cleanup", true).scheduleAtFixedRate(new TimerTask() {
    @Override
    public void run() {
      synchronized (LinePool.this) {
        for (SourceDataLine sourceDataLine : freeLines) {
          if (sourceDataLine.isOpen()) {
            sourceDataLine.close();
            log.debug("Closed line {}", sourceDataLine);
          }
        }
      }
    }
  }, LINE_CLEANUP_INTERVAL, LINE_CLEANUP_INTERVAL);
}

代码示例来源:origin: robo-code/robocode

private JComboBox getMixerComboBox() {
  if (mixerComboBox == null) {
    Mixer.Info[] mixerInfo = AudioSystem.getMixerInfo();
    Line.Info clipLineInfo = new Line.Info(Clip.class);
    Vector<Mixer.Info> mixers = new Vector<Mixer.Info>();
    for (Mixer.Info mi : mixerInfo) {
      if (AudioSystem.getMixer(mi).getSourceLineInfo(clipLineInfo).length > 0) {
        mixers.add(mi);
      }
    }
    mixerComboBox = new JComboBox(mixers);
    mixerComboBox.setRenderer(new MixerInfoCellRenderer());
    mixerComboBox.addActionListener(eventHandler);
  }
  return mixerComboBox;
}

代码示例来源:origin: robo-code/robocode

private ClipClones(Mixer mixer, SoundData soundData, int size) throws LineUnavailableException {
  idx = 0;
  clips = new Clip[size];
  DataLine.Info info = new DataLine.Info(Clip.class, soundData.format);
  if (!AudioSystem.isLineSupported(info)) {
    throw new LineUnavailableException("Required data line is not supported by the audio system");
  }
  for (int i = 0; i < size; i++) {
    clips[i] = (Clip) mixer.getLine(info);
    clips[i].open(soundData.format, soundData.byteData, 0, soundData.length);
  }
}

代码示例来源:origin: stackoverflow.com

Mixer.Info[] mixerInfos = AudioSystem.getMixerInfo();
  Mixer mixer = AudioSystem.getMixer(mixerInfos[i]);
  int maxLines = mixer.getMaxLines(Port.Info.MICROPHONE);
  Port lineIn = null;
  FloatControl volCtrl = null;
  if (maxLines > 0) {
    try {
      lineIn = (Port) mixer.getLine(Port.Info.MICROPHONE);
      lineIn.open();
      CompoundControl cc = (CompoundControl) lineIn.getControls()[0];

相关文章