public SonarSoundEngine(int maxChannels) throws LineUnavailableException {
    silentSample = new SonarSample(new float[] {0}, 44100);
    Mixer mixer = AudioSystem.getMixer(null);

    sdl = (SourceDataLine) mixer.getLine(new Line.Info(SourceDataLine.class));
    sdl.open(new AudioFormat(rate, 16, 2, true, false), bufferSize * 2 * 2 * 2 * 2 * 2);
    soundBuffer.order(ByteOrder.LITTLE_ENDIAN);
    sdl.start();

    try {
      /*            FloatControl volumeControl = (FloatControl) sdl.getControl(FloatControl.Type.MASTER_GAIN);
      volumeControl.setValue(volumeControl.getMaximum());*/
    } catch (IllegalArgumentException e) {
      // System.out.println("Failed to set the sound volume");
    }

    listenerMixer = new ListenerMixer(maxChannels);

    leftBuf = new float[bufferSize];
    rightBuf = new float[bufferSize];

    Thread thread = new Thread(this);
    thread.setDaemon(true);
    thread.setPriority(10);
    thread.start();
  }
  public void storePreferences() {
    ISettingsManager props = properties;

    props.setOptionsSoundEnableSound(getEnableSoundCheckBox().isSelected());
    props.setOptionsSoundEnableGunshot(getEnableGunshotCheckBox().isSelected());
    props.setOptionsSoundEnableBulletHit(getEnableBulletHitCheckBox().isSelected());
    props.setOptionsSoundEnableRobotDeath(getEnableRobotDeathCheckBox().isSelected());
    props.setOptionsSoundEnableRobotCollision(getEnableRobotCollisionCheckBox().isSelected());
    props.setOptionsSoundEnableWallCollision(getEnableWallCollisionCheckBox().isSelected());
    props.setOptionsSoundEnableMixerVolume(getEnableMixerVolumeCheckBox().isSelected());
    props.setOptionsSoundEnableMixerPan(getEnableMixerPanCheckBox().isSelected());

    String mixerClassName = null;
    Mixer.Info mixerInfo = (Mixer.Info) getMixerComboBox().getSelectedItem();

    if (mixerInfo != null) {
      Mixer mixer = AudioSystem.getMixer((Mixer.Info) getMixerComboBox().getSelectedItem());

      if (mixer != null) {
        mixerClassName = mixer.getClass().getSimpleName();
      }
    }
    if (mixerClassName != null) {
      props.setOptionsSoundMixer(mixerClassName);
    }

    properties.saveProperties();
  }
Example #3
0
  /** Does any clean up before closing. */
  protected void cleanUp() {
    // signal to unpause
    setPaused(false);

    // close the mixer (stops any running sounds)
    Mixer mixer = AudioSystem.getMixer(null);
    if (mixer.isOpen()) {
      mixer.close();
    }
  }
 // Constructor takes the name to save decoded track as in the form of a string ex:"track1.wav"
 public FlacTrackPlayer(String trackName) {
   player = null;
   track = new File(trackName);
   Mixer mixer = AudioSystem.getMixer(AudioSystem.getMixerInfo()[0]);
   try {
     mixer.open();
   } catch (LineUnavailableException e) {
     // TODO Auto-generated catch block
     System.out.println("huh?");
     e.printStackTrace();
   }
 }
Example #5
0
  public SourceDataLine getOutputLine(AudioFormat format) throws LineUnavailableException {
    SourceDataLine out;

    DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
    out = (SourceDataLine) mixer.getLine(info);
    out.open(format, out.getBufferSize());
    return out;
  }
Example #6
0
  public TargetDataLine getInputLine(AudioFormat format) throws LineUnavailableException {
    TargetDataLine in;

    DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
    in = (TargetDataLine) mixer.getLine(info);
    in.open(format, in.getBufferSize());
    return in;
  }
Example #7
0
 private Line.Info[] getPortInfo(Mixer mixer) {
   Line.Info[] infos;
   List<Line.Info> portInfoList = new ArrayList<>();
   infos = mixer.getSourceLineInfo();
   for (Line.Info info : infos) {
     if (info instanceof Port.Info || info instanceof DataLine.Info) {
       portInfoList.add(info);
     }
   }
   infos = mixer.getTargetLineInfo();
   for (Line.Info info1 : infos) {
     if (info1 instanceof Port.Info || info1 instanceof DataLine.Info) {
       portInfoList.add(info1);
     }
   }
   return portInfoList.toArray(EMPTY_PORT_INFO_ARRAY);
 }
  public static boolean isLineSupported(Line.Info info) {

    for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        MixerProvider pr = (MixerProvider) providers.next();
        Mixer.Info[] mixinfos = pr.getMixerInfo();
        for (Mixer.Info mixinfo : mixinfos) {
          Mixer mix = pr.getMixer(mixinfo);
          if (mix.isLineSupported(info)) {
            return true;
          }
        }
      } catch (ClassCastException e) {
      }
    }
    return false;
  }
 public static Line.Info[] getTargetLineInfo(Line.Info info) {
   List<Line.Info> result = new ArrayList<Line.Info>();
   for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
       providers.hasNext(); ) {
     try {
       MixerProvider pr = (MixerProvider) providers.next();
       Mixer.Info[] mixinfos = pr.getMixerInfo();
       for (Mixer.Info mixinfo : mixinfos) {
         Mixer mix = pr.getMixer(mixinfo);
         Line.Info[] linfos = mix.getTargetLineInfo(info);
         for (Line.Info linfo : linfos) {
           result.add(linfo);
         }
       }
     } catch (ClassCastException e) {
     }
   }
   Line.Info[] temp = new Line.Info[result.size()];
   return result.toArray(temp);
 }
Example #10
0
 private boolean arePortsSupported(Mixer mixer) {
   Line.Info[] infos;
   infos = mixer.getSourceLineInfo();
   for (Line.Info info : infos) {
     if (info instanceof Port.Info) {
       return true;
     } else if (info instanceof DataLine.Info) {
       return true;
     }
   }
   infos = mixer.getTargetLineInfo();
   for (Line.Info info : infos) {
     if (info instanceof Port.Info) {
       return true;
     } else if (info instanceof DataLine.Info) {
       return true;
     }
   }
   return false;
 }
  private void mixerComboBoxActionPerformed() {
    Mixer mixer = AudioSystem.getMixer((Mixer.Info) mixerComboBox.getSelectedItem());

    Line.Info lineInfo = mixer.getSourceLineInfo(new Line.Info(Clip.class))[0];

    boolean volumeSupported;
    boolean panSupported;

    try {
      Line line = mixer.getLine(lineInfo);

      volumeSupported = line.isControlSupported(FloatControl.Type.MASTER_GAIN);
      panSupported = line.isControlSupported(FloatControl.Type.PAN);
    } catch (LineUnavailableException e) {
      volumeSupported = false;
      panSupported = false;
    }

    enableMixerVolumeCheckBox.setEnabled(volumeSupported);
    enableMixerPanCheckBox.setEnabled(panSupported);
  }
Example #12
0
    public void playAudio() {
      int minSize =
          AudioTrack.getMinBufferSize(
              sampleRate, AudioFormat.CHANNEL_CONFIGURATION_STEREO, AudioFormat.ENCODING_PCM_16BIT);
      int bufsize = minSize < minBufferSize ? minBufferSize : minSize;

      AudioTrack audio =
          new AudioTrack(
              AudioManager.STREAM_MUSIC,
              sampleRate,
              AudioFormat.CHANNEL_CONFIGURATION_STEREO,
              AudioFormat.ENCODING_PCM_16BIT,
              bufsize,
              AudioTrack.MODE_STREAM);
      audio.setStereoVolume(1.0f, 1.0f);

      Mixer audioSource;
      audioSource = new Mixer(notes);

      short[] buffer = new short[bufsize / 2]; // this is num SAMPLES: divide by 2 for 16-bit

      // pre-fill buffer before starting playback
      for (int offs = 0; offs < buffer.length; offs += 2) {
        audioSource.nextSample(buffer, offs);
      }

      audio.write(buffer, 0, buffer.length);
      audio.play();

      // fill buffer repeatedly
      while (!stopPlaying) {
        for (int offs = 0; offs < buffer.length; offs += 2) {
          audioSource.nextSample(buffer, offs);
        }

        audio.write(buffer, 0, buffer.length);
      }

      audio.stop();
    }
Example #13
0
  private void createMixerChildren(JavaMixer.MixerNode mixerNode) {
    Mixer mixer = mixerNode.getMixer();
    Line.Info[] infosToCheck = getPortInfo(mixer);
    for (Line.Info anInfosToCheck : infosToCheck) {
      if (mixer.isLineSupported(anInfosToCheck)) {
        Port port = null;
        DataLine dLine = null;

        int maxLines = mixer.getMaxLines(anInfosToCheck);
        // Workaround to prevent a JVM crash on Mac OS X (Intel) 1.5.0_07 JVM
        if (maxLines > 0) {
          try {
            if (anInfosToCheck instanceof Port.Info) {
              port = (Port) mixer.getLine(anInfosToCheck);
              port.open();
            } else if (anInfosToCheck instanceof DataLine.Info) {
              dLine = (DataLine) mixer.getLine(anInfosToCheck);
              if (!dLine.isOpen()) {
                dLine.open();
              }
            }
          } catch (LineUnavailableException e) {
            e.printStackTrace();
          } catch (Exception e) {
            // Do Nothing
          }
        }
        if (port != null) {
          JavaMixer.PortNode portNode = new JavaMixer.PortNode(port);
          createPortChildren(portNode);
          mixerNode.add(portNode);
        } else if (dLine != null) {
          JavaMixer.PortNode portNode = new JavaMixer.PortNode(dLine);
          createPortChildren(portNode);
          mixerNode.add(portNode);
        }
      }
    }
  }
  private static Line getLine(String propName, Line.Info info) throws LineUnavailableException {

    List<?> mixerProviders = ProviderService.getProviders(mixerProviderPath);

    if (propName != null) {
      String propVal = System.getProperty(propName);
      if (propVal != null) {
        Mixer m = getMixer(propVal, info, mixerProviders);
        if (m != null) {
          Line l = m.getLine(info);
          if (l != null) {
            return l;
          }
        }
      }

      Properties soundProperties = ProviderService.getSoundProperties();
      propVal = soundProperties.getProperty(propName);
      if (propVal != null) {
        Mixer m = getMixer(propVal, info, mixerProviders);
        if (m != null) {
          Line l = m.getLine(info);
          if (l != null) {
            return l;
          }
        }
      }
    }

    for (Iterator providers = ProviderService.getProviders(mixerProviderPath).iterator();
        providers.hasNext(); ) {
      try {
        MixerProvider pr = (MixerProvider) (providers.next());
        Mixer.Info[] mixinfos = pr.getMixerInfo();
        for (Mixer.Info mixinfo : mixinfos) {
          try {
            Mixer mix = pr.getMixer(mixinfo);
            return mix.getLine(info);
          } catch (IllegalArgumentException e) {
            // continue
          }
        }
      } catch (ClassCastException e) {
      }
    }
    // sound.11=Could not get line
    throw new IllegalArgumentException(Messages.getString("sound.11")); // $NON-NLS-1$
  }
Example #15
0
 public String getName() {
   return /*""+id+" "+*/ mixer.getMixerInfo().getName();
 };
Example #16
0
 public void mix() {
   mixer.mix(puzzles);
   invalidate();
 }
Example #17
0
 public MixerNode(Mixer mixer) {
   super(mixer.getMixerInfo(), true);
   this.mixer = mixer;
 }
Example #18
0
 /**
  * Gets the maximum number of simultaneous sounds with the specified AudioFormat that the default
  * mixer can play.
  */
 public static int getMaxSimultaneousSounds(AudioFormat playbackFormat) {
   DataLine.Info lineInfo = new DataLine.Info(SourceDataLine.class, playbackFormat);
   Mixer mixer = AudioSystem.getMixer(null);
   return mixer.getMaxLines(lineInfo);
 }
Example #19
0
  public String toString() {
    Mixer.Info info = mixer.getMixerInfo();

    String s = "\nMixer [" + id + "]";
    s += "\n\t Name: " + info.getName();
    s += "\n\t Desc: " + info.getDescription();
    s += "\n\t Ven : " + info.getVendor();
    s += "\n\t Ver : " + info.getVersion();
    s += "\n\t Str : " + info.toString();

    Line.Info[] infos = mixer.getSourceLineInfo();
    s += "\n\nSourceLine count : " + infos.length;
    for (int i = 0; i < infos.length; i++) {
      if (infos[i] instanceof DataLine.Info) {
        s += "\n\t\tData Line Source [" + i + "]";
        s += "\n\t\t\t Str : " + infos[i].toString();
      } else if (infos[i] instanceof Port.Info) {
        s += "\n\t\tPort Source [" + i + "]";
        s += "\n\t\t\t Name: " + ((Port.Info) infos[i]).getName();
        s += "\n\t\t\t is Src: " + ((Port.Info) infos[i]).isSource();
        s += "\n\t\t\t Str : " + infos[i].toString();
      } else /*if(infos[i]!=null)*/ {
        s += "\n\t\tSource [" + i + "]";
        s += "\n\t\t\t Str : " + infos[i].toString();
      }
    }
    s += "\n\nOUTPUT\n";
    for (int i = 0; i < formats.length; i++) {
      try {
        SourceDataLine out = getOutputLine(formats[i]);
        out.close();
        s += "\n" + formats[i].toString();
      } catch (Exception e) {
        //        s+="\n"+e.getMessage();
      }
    }

    infos = mixer.getTargetLineInfo();
    s += "\n\nTargetLine count : " + infos.length;
    for (int i = 0; i < infos.length; i++) {
      if (infos[i] instanceof DataLine.Info) {
        s += "\n\t\tData Line Target [" + i + "]";
        s += "\n\t\t\t Str : " + infos[i].toString();
      } else if (infos[i] instanceof Port.Info) {
        s += "\n\t\tPort Target [" + i + "]";
        s += "\n\t\t\t Name: " + ((Port.Info) infos[i]).getName();
        s += "\n\t\t\t is Src: " + ((Port.Info) infos[i]).isSource();
        s += "\n\t\t\t Str : " + infos[i].toString();
      } else /*if(infos[i]!=null)*/ {
        s += "\n\t\tTarget [" + i + "]";
        s += "\n\t\t\t Str : " + infos[i].toString();
      }
    }

    s += "\n\nINPUT\n";
    for (int i = 0; i < formats.length; i++) {
      try {
        TargetDataLine out = getInputLine(formats[i]);
        out.close();
        s += "\n" + formats[i].toString();
      } catch (Exception e) {
        //        s+="\n"+e.getMessage();
      }
    }

    return s;
  }